Skip to content

fix(sd-jwt): name the bound a Disclosure factory hits - #814

Merged
Spomky merged 1 commit into
4.3.xfrom
fix/sd-jwt-disclosure-factory-messages
Nov 9, 2026
Merged

Spomky merged 1 commit into
4.3.xfrom
fix/sd-jwt-disclosure-factory-messages

Conversation

@Spomky

@Spomky Spomky commented Nov 9, 2026

Copy link
Copy Markdown
Member

Follow-up of #810 and #813.

The defect

Disclosure::forObjectProperty() and Disclosure::forArrayElement() refuse a value whose Disclosure could not be parsed (#810). They used one message for both bounds of the decoder:

The value is nested too deeply or holds too many JSON values: its Disclosure could not be parsed.

To know which bound the value hit, the caller had to read the chain of the exception.

The fix

Disclosure::serialize() now keeps its decoder and asks it, with BoundedJsonDecoder::hasExceededMaxValues() (#813), whether the budget of 4096 values was exceeded. If it was not, json_decode() rejected the JSON for its depth: json_encode() wrote it, so the JSON is valid. Each bound now has its own message:

Bound Message
More than 4096 JSON values in the Disclosure The value holds too many JSON values: its Disclosure would hold more than the 4096 that are decoded.
Nested too deeply The value is nested too deeply: its Disclosure could not be parsed.

The values are counted before the JSON is decoded. A value beyond both bounds, such as 10,000 nested arrays, is therefore reported for its values.

SDJWTIssuer is unchanged: a Disclosable whose Disclosure cannot be parsed gets the same two messages.

Backward compatibility

The SD-JWT component has not been released yet.

  • API. Unchanged: only the body and the docblock of the private Disclosure::serialize() change.
  • Behaviour. The probe of fix(sd-jwt): create only the Disclosures that can be parsed #810 ran its 617 cases on 4.3.x (da615c9) and on this branch. In the base run, the 4.3.x version of Disclosure was loaded before Composer's autoloader. The cases are 146 values through the two factories, with ordinary and unusual claim names and salts, and 13 sets of claims issued in both serializations.
    • 427 cases are identical, the API included.
    • 190 cases change their message, and nothing else. On 4.3.x, they were refused with the combined message. They are now refused with the message of one bound, with the same exception class and code: 104 for their depth and 86 for their values. For each of them, the chain of the 4.3.x exception shows the bound that was hit (JsonException(1): Maximum stack depth exceeded for the depth).
    • There is no other difference.

Verification

  • Updated tests:
    • DisclosureTest::aValueWhoseDisclosureCannotBeParsedIsRefused (8 cases) now expects the message of the bound that each value hits;
    • SDJWTIssuerTest::aDisclosableValueWhoseDisclosureCannotBeParsedIsRefused (2 cases) now expects the depth message.
  • On 4.3.x, these 10 cases fail on the combined message. With this PR, they pass.
  • Full suite with phpunit-11 in phpqa:8.4: 2,845 tests, no failure. The 4 skipped and 2 incomplete tests are the PKCS#12 and ML-DSA platform tests.
  • ECS, Rector, PHPStan (baseline unchanged) and Deptrac pass with phpqa:8.4. The changed files pass php -l with PHP 8.2.
  • Mutations on the diff: 5 mutants, all killed with a 60-second timeout. Locally, with the 3-second timeout of infection.json.dist, one of them times out. Infection counts it as detected.

Disclosure::forObjectProperty() and Disclosure::forArrayElement() gave
one message for both bounds of the decoder when the Disclosure of a
value could not be parsed: "The value is nested too deeply or holds too
many JSON values". BoundedJsonDecoder::hasExceededMaxValues() now tells
whether the budget of 4096 values was exceeded; otherwise, since
json_encode() wrote the JSON, json_decode() rejected it for its depth.
Each bound has its own message. The exception class and code are
unchanged.
@Spomky Spomky added this to the 4.3.0 milestone Nov 9, 2026
@Spomky Spomky added the bug label Nov 9, 2026
@Spomky
Spomky merged commit 3f69217 into 4.3.x Nov 9, 2026
18 checks passed
@Spomky
Spomky deleted the fix/sd-jwt-disclosure-factory-messages branch November 9, 2026 08:08
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.

1 participant