fix(encryption): read the recipient header from the builder state - #698
Merged
Merged
Conversation
`JWEBuilder::withSharedProtectedHeader()` and `JWEBuilder::withSharedHeader()` called `getHeader()` on the already registered recipients, but `addRecipient()` stores plain arrays. Setting a shared header after a recipient therefore raised a fatal `Error` instead of running the duplicated-header-parameter check. Closes #678
Spomky
force-pushed
the
fix/jwe-builder-shared-header-after-recipient
branch
from
August 28, 2026 12:30
e643a02 to
892925a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #678.
JWEBuilder::withSharedProtectedHeader()andJWEBuilder::withSharedHeader()iterated over the alreadyregistered recipients and called
$recipient->getHeader(), butaddRecipient()stores plain arrays(
['key' => ..., 'header' => ..., 'key_encryption_algorithm' => ...]).Setting a shared header after a recipient therefore raised a fatal
Error: Call to a member function getHeader() on arrayinstead of performing theduplicated-header-parameter check. As a consequence that check only ever ran when the recipient was
added last.
Both loops now read
$recipient['header'].Tests
Three regression tests in
EncrypterTest, all failing before the fix:sharedHeaderCanBeSetAfterTheRecipientHasBeenAdded— builds, serializes tojwe_json_flattenedanddecrypts a JWE whose shared (unprotected) header is set after
addRecipient()duplicatedHeaderWhenTheSharedHeaderIsSetAfterTheRecipientduplicatedHeaderWhenTheSharedProtectedHeaderIsSetAfterTheRecipientThe PHPStan baseline is updated accordingly: the
method.nonObjectentry forgetHeader()is gone andthe
offsetAccess.nonOffsetAccessiblecount for'header'goes from 1 to 3.Replacing those array entries by readonly value objects remains part of the builder redesign planned for
4.3/5.0, as does the order sensitivity of
addRecipient()mentioned at the end of the issue.