Repository navigation
fix(sd-jwt): create only the Disclosures that can be parsed - #810
Merged
Merged
Conversation
Disclosure::forObjectProperty() and Disclosure::forArrayElement() wrote the JSON of any value, while Disclosure::fromString() decodes it with a BoundedJsonDecoder: at most 4096 values, and at most 511 levels of arrays and objects, the array of the Disclosure included. A value of 511 nested arrays, an object whose JSON has 511 levels, 300 arrays around an object of 300 levels or a list of 4095 integers gave a Disclosure that this library then rejected as "not valid JSON", and SDJWTIssuer issued SD-JWTs that the Holder and the Verifier could not parse. Both factories now decode the JSON of the Disclosure with a new BoundedJsonDecoder before returning it, and refuse the value with an InvalidArgumentException when the Disclosure cannot be parsed. The levels are thus counted from the array of the Disclosure, for the arrays and the objects of the value alike, and the bounds are those of the parser. Fixes #808
Spomky
added a commit
to Spomky-Labs/docs
that referenced
this pull request
Nov 9, 2026
…s created Disclosure::forObjectProperty(), Disclosure::forArrayElement() and the Issuer now refuse a value whose Disclosure Disclosure::fromString() would reject: more than 510 levels of arrays and objects in the value, or more than 4096 JSON values in the Disclosure (web-token/jwt-framework#810). The page gives both bounds and the longest lists of integers each factory accepts, and the list of what the Issuer refuses points to them.
This was referenced Nov 9, 2026
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 #808.
The defect
Disclosure::forObjectProperty()andDisclosure::forArrayElement()wrote the JSON of any value, whileDisclosure::fromString()decodes it with aBoundedJsonDecoder: at most 4,096 values, and at most 511 levels of arrays and objects, the array of the Disclosure included (with their default depth of 512,json_encode()writes 512 levels butjson_decode()reads only 511). The factories created Disclosures that this library then rejected withThe Disclosure is not valid JSON.:json_encode()andjson_decode()on its own, so the levels above it were not counted either: 300 arrays around an object of 300 levels passed;forObjectProperty()), whichjson_decode()reads.Through
SDJWTIssuer, aDisclosableof 600 nested arrays was issued, thenSDJWT::fromString()rejected the SD-JWT.The fix
Disclosure::serialize(), which both factories use, now decodes the JSON it wrote with a newBoundedJsonDecoder, asDisclosure::fromString()does, before the Disclosure is returned. When the decoder refuses it, the factory throws anInvalidArgumentException:The previous exception tells which bound was hit:
Unsupported input.alone for the budget, followed byMaximum stack depth exceededfor the depth. The bounds stay in the class that enforces them, and the levels are counted from the top of the Disclosure, for arrays and objects alike.The cost is one more decoding per Disclosure. The decoder counts the values before decoding, so a Disclosure over the budget is never decoded.
SDJWTIssueris unchanged. It now refuses such aDisclosableat issuance with anInvalidArgumentException, the class of its other refusals, which is also what the same claim in clear gets (Invalid content.).Backward compatibility
The SD-JWT component has not been released yet: no tag contains
src/SelectiveDisclosure, and the splitweb-token/jwt-selective-disclosurehas no tag.Disclosure::serialize()and three docblocks change. By reflection, the public methods (parameters, types and defaults), the constants and the modifiers of the class are identical. No deprecation, no new dependency:BoundedJsonDecoderis inweb-token/jwt-library, which the split already requires.Disclosureloaded by an autoloader placed before Composer's. The cases are 146 values through the two factories, with ordinary and unusual claim names and salts (584 cases), and 13 sets of claims issued in both serializations (26 cases). The values cover scalars, strings full of JSON syntax, enums,DateTimeImmutable,ArrayObject,JsonSerializable, self references, nested arrays and objects and their combinations around 510, 511 and 512 levels, and lists, maps and objects around 4,093 to 4,096 values.Disclosure::fromString()orSDJWT::fromString()rejected, is now refused at creation with the message above.The value cannot be serialized as JSON.:json_decode()refuses it while it is converted, before this check.Verification
DisclosureTest::aValueWhoseDisclosureCannotBeParsedIsRefused(8 cases): the rows of the table of SD-JWT: Disclosure creates Disclosures that Disclosure::fromString() rejects #808, through both factories;DisclosureTest::aValueWithinTheBoundsOfTheParserIsDisclosed(9 cases): values at the bounds are created, then parsed back to the value that JSON gives them. They are 510 levels of arrays, of objects, or of 255 arrays around an object of 255 levels; 4,094 and 4,093 integers; and strings made of brackets, braces, commas, quotes and backslashes;SDJWTIssuerTest::aDisclosableValueWhoseDisclosureCannotBeParsedIsRefused(2 cases): the scenario of SD-JWT: Disclosure creates Disclosures that Disclosure::fromString() rejects #808, aDisclosableof 600 nested arrays, as a claim and as an array element.Failed asserting that exception of type "Jose\Component\Core\Exception\InvalidArgumentException" is thrown.). The 9 cases within the bounds pass before and after: they check that the fix refuses nothing that can be parsed. With this PR, all of them pass.phpunit-11inphpqa:8.4: 2,806 tests, no failure. The 4 skipped and 2 incomplete tests are the PKCS#12 and ML-DSA platform tests.tests/SelectiveDisclosurealso passes with PHP 8.5. PHP 8.2 is left to the CI matrix, because the local vendor requires 8.4.phpqa:8.4.throw, and two changes of the exception code), all killed with a 60-second timeout. Locally, the 3-second timeout ofinfection.json.distskips one of them.Interaction with #809
#809 (fix of #805) touches other files: the two branches merge without conflict, and
tests/SelectiveDisclosurepasses on the merge (626 tests). Together, the two checks split the work. This PR refuses a Disclosure that cannot be parsed on its own, before #809 runs. #809 refuses an SD-JWT whose Disclosures share a budget that is too small, or whose processed payload has more than 64 levels.Without this PR, #809 also refuses a Disclosure that is too deep, but reports it with its budget message,
The Disclosures of the SD-JWT hold more JSON values than the 4096 the Holder and the Verifier decode.. On the merge, the probe gives that message only for the SD-JWTs over the shared budget.Not covered
SDJWT::fromString()shares one budget between all the Disclosures of an SD-JWT, andDisclosureProcessorbounds the processed payload at 64 levels: those are the bounds of a whole SD-JWT, covered by SD-JWT: SDJWTIssuer issues SD-JWTs beyond the depth and size bounds of the Holder and Verifier #805. The probe found 3 such SD-JWTs, issued but not parsed both before and after this PR: one Disclosure of 4,093 integers in the JWS JSON serialization, whose JSON document adds values to the budget, and 2,049 Disclosures of integers, in both serializations.Disclosure::fromString()still rejects a Disclosure beyond the bounds, received from elsewhere, withThe Disclosure is not valid JSON., even whenjson_decode()can read it.