fix(signature): apply the payload encoding to the clone, not the receiver - #695
Merged
Conversation
…iver `JWSBuilder::addSignature()` is documented as immutable but it wrote `isPayloadEncoded` on `$this` before cloning. The bundle registers the builder as a shared service, so the first call pinned the "b64" mode of that service for the rest of the process and any later, unrelated build failed with "Foreign payload encoding detected.". Clone first, then perform the state transition on the clone, as `JWEBuilder::addRecipient()` already does. Fixes #679
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 #679.
JWSBuilder::addSignature()is documented as immutable ("This method will return a new JWSBuilder object") but it wroteisPayloadEncodedon$thisbefore cloning:The bundle registers the builder as a shared service, so a single
addSignature()call on the injected instance permanently pinned theb64mode of that service: every later, unrelated build failed withForeign payload encoding detected..The clone is now created before the state transition and the transition applied to it, exactly as
JWEBuilder::addRecipient()already does withcheckAndSetContentEncryptionAlgorithm(). The check order is unchanged, so the exceptions raised on invalid input are the same as before.The regression test reuses one builder instance across two independent builds; it fails with
Foreign payload encoding detected.on4.2.xand passes with the fix.The wider redesign — making the builders genuinely immutable so the
create()reset becomes unnecessary — stays tracked for 4.3.0.Checks
phpunit -c .ci-tools/phpunit.xml.dist: 869 tests, 2541 assertions, OK (the 2 incomplete tests are pre-existing)