Skip to content

SD-JWT: refuse at issuance the SD-JWTs the Holder and the Verifier reject - #809

Merged
Spomky merged 2 commits into
4.3.xfrom
fix/sd-jwt-issuer-bounds
Nov 9, 2026
Merged

Spomky merged 2 commits into
4.3.xfrom
fix/sd-jwt-issuer-bounds

Conversation

@Spomky

@Spomky Spomky commented Nov 8, 2026

Copy link
Copy Markdown
Member

Fixes #805.

The defect

Since #795, SDJWTVerifier::verify(), verifyWithKeyBinding() and SDJWT::select() reject a processed payload deeper than 64 levels, and SDJWT::fromString() decodes at most 4,096 JSON values per SD-JWT. SDJWTIssuer checked neither bound. It issued SD-JWTs that the Holder and the Verifier of this library then refused, so the error appeared at presentation or verification, possibly on another system, instead of at issuance.

The fix

Before signing, issue() and issueJson() build an SD-JWT with the encoded payload and the Disclosures of the one to issue. It also has the same serialization and the same unprotected headers. The protected headers and signatures are placeholders, which are base64url strings and hold no JSON value. The Issuer then:

  1. parses it with SDJWT::fromString(), as the Holder and the Verifier do. In the JWS JSON serialization, the values of the JSON document count too, including the unprotected headers and the commas of the disclosures array;
  2. processes it with select() and no claim path, the processing the Holder runs to select Disclosures.

Both bounds therefore come from the classes that enforce them, and nothing is copied. Depth is counted the way the Verifier counts it. An object counts with the levels of its JSON, and a Disclosable adds no level. The claims are refused with an InvalidArgumentException:

  • The processed payload of the SD-JWT is nested more than 64 levels deep. This is the message of the processor, which stays chained as the previous exception;
  • The Disclosures of the SD-JWT hold more JSON values than the 4096 the Holder and the Verifier decode. The InvalidSerializationException of the parser stays chained. This message names the bound, which The Disclosure is not valid JSON. / Unsupported input. did not.

Measured with an ES256 key, 1 to 3 decoys:

Claims 4.3.x This branch
typical (5 Disclosures, cnf) issued, 0.30 ms issued, 0.53 ms
chain of 63 objects + payload (64 levels) issued issued
chain of 64 objects + payload (65 levels) issued refused (depth)
chain of 1,000 Disclosures issued, 18 ms refused (budget), 25 ms
2,048 disclosable integers, compact issued issued
2,049 disclosable integers, compact issued refused (budget)

Tests

IssuerBoundsTest has 23 cases:

  • 64 levels are issued, verified and selected, and 65 levels are refused with the depth message. Three shapes are covered (nested arrays, chained Disclosures of object properties, chained Disclosures of array elements), each in both serializations (6 + 6 cases);
  • a chain of 1,000 Disclosures is refused in both serializations (2 cases);
  • 2,048 disclosable integers are issued and parsed back in the compact format, and 2,049 are refused with the budget message in both serializations (1 + 2 cases);
  • in the JWS JSON serialization, for 1,350 to 1,370 Disclosures, the Issuer issues exactly when SDJWT::fromString() can parse the result. This is checked with no unprotected header, with one, and with two general signatures (3 cases);
  • the JSON levels of a JsonSerializable are counted (1 case);
  • the refusal chains the exception of the parser or of the processor (1 case);
  • signatures passed by name to the variadic issueJson() keep working. They are collected under a string key, which the placeholder has to turn into a list (1 case).

On 4.3.x without the fix, all 14 refusal cases fail and the 7 acceptance cases pass. The two cases for the chained exception and the named signatures were added afterwards.

Infection on the diff, with a 60 s timeout: 25 of 30 mutants are killed. The 5 that escape are the 0 code of the two InvalidArgumentException (4, equivalent, and no test in the repository asserts an exception code) and the array_values() call. The named-signature case now covers that call: it fails without it.

Compatibility

The SD-JWT component has not been released yet: 4.3.0 will be its first release. No signature changes, nothing is deprecated, and no dependency is added to the split. Only private methods and a private constant are added to SDJWTIssuer.

  • I dumped the public and protected API of SDJWTIssuer, SDJWTIssuerInterface, SDJWT and DisclosureProcessor by reflection, on 4.3.x and on this branch. The two dumps are identical (24 entries).
  • In the probe above, only the claims beyond a bound change outcome. The whole suite passes (2,808 tests), and so do ECS, Rector, PHPStan and Deptrac on phpqa:8.4.

…er reject

SDJWTIssuer issued SD-JWTs whose processed payload is deeper than the
64 levels of DisclosureProcessor, or whose Disclosures hold more JSON
values than the budget of BoundedJsonDecoder: the Holder and the
Verifier then refused them.

Before signing, the Issuer now parses an SD-JWT that has the payload,
the Disclosures, the serialization and the unprotected headers of the
one to issue, then processes it as SDJWT::select() does. Both bounds
come from the classes that enforce them, and such claims are refused
with an InvalidArgumentException.

Fixes #805
Anonymous readonly classes need PHP 8.3: the property is readonly
instead, as in SDJWTIssuerTest.
@Spomky
Spomky merged commit 53a9820 into 4.3.x Nov 9, 2026
18 checks passed
@Spomky
Spomky deleted the fix/sd-jwt-issuer-bounds branch November 9, 2026 07:08
Spomky added a commit to Spomky-Labs/docs that referenced this pull request Nov 9, 2026
…ould reject for its size

Before signing, SDJWTIssuer::issue() and issueJson() now parse and
process the SD-JWT to issue, with placeholder signatures, as the Holder
and the Verifier do (web-token/jwt-framework#809). A Processed SD-JWT
Payload of more than 64 levels, or Disclosures over the budget of 4096
JSON values, is refused with an InvalidArgumentException that names the
bound.

The page gave that budget as about 1,300 claims in the compact format
and about 1,000 in the JWS JSON serialization. It now gives the figures
measured on 4.3.x (85d5df0a): 1,365 claims or 2,048 array elements in
the compact format, and 1,022 claims or 1,363 array elements in the
JWS JSON serialization with one signature.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SD-JWT: SDJWTIssuer issues SD-JWTs beyond the depth and size bounds of the Holder and Verifier

1 participant