fix(core): correct the parameter types of the nested token builder - #672
Open
Spomky wants to merge 1 commit into
Open
fix(core): correct the parameter types of the nested token builder#672Spomky wants to merge 1 commit into
Spomky wants to merge 1 commit into
Conversation
`NestedTokenBuilder::create()` declared sealed array shapes that rejected the documented usage: the JWE headers only accepted `alg` (plus a key literally named `string`), so passing `enc` was reported as an error, and `$signatures`/`$recipients` were shapes holding exactly one element, so a token with two signatures or two recipients was rejected as well. The JWE layer the builder delegates to declared no value type at all for its header parameters, and `JWS::addSignature()`/`Signature::__construct()` carried the same bogus shape. Fixes #662
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 #662.
Problem
NestedTokenBuilder::create()declared sealed array shapes that reject the documented usage. Analysing the documentation snippet with PHPStan (bleeding edge) or Psalm produced:Three distinct mistakes were involved:
array{alg?: string, string?: mixed}declares a shape with two optional keys,algand one literally namedstring. It was clearly meant to bearray<string, mixed>. Every other header parameter —enc,zip,cty,kid, … — was rejected.array{array{key: JWK, ...}}declares a shape holding exactly one element at key0, not a list. Building a token with two signatures or two recipients was reported as an error too:Changes
NestedTokenBuilder::create():$jweSharedProtectedHeaderand$jweSharedHeaderarearray<string, mixed>;$signaturesand$recipientsarearray<array{...}>.JWEBuilder::withSharedProtectedHeader(),withSharedHeader()andaddRecipient()now declarearray<string, mixed>for their header parameters (theirmissingType.iterableValueentries are dropped from the PHPStan baseline).JWS::addSignature()andSignature::__construct()carried the samearray{alg?: string, string?: mixed}shape and are corrected the same way. The baseline entries that quoted the old shape are updated accordingly.Documentation only — no runtime behaviour changes.
Verification
The documented snippet, extended with a second signature, was analysed at level max with bleeding edge against both the old and the new signatures: 3 errors before, none after.
castor phpstan: 43 errors, identical to the ones already present on4.1.xbefore this branch (the QA tooling breakage repaired on4.2.xby Make the quality gates pass again #669 is not backported here). No new error, no unmatched baseline entry.castor phpunit: 752 tests, 2223 assertions, green.castor ecscannot run on4.1.x(Undefined constant SetList::PHPUNIT), pre-existing and unrelated — this change touches docblocks only.