Repository navigation
fix(sd-jwt): name the bound a Disclosure factory hits - #814
Merged
Merged
Conversation
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.
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.
Follow-up of #810 and #813.
The defect
Disclosure::forObjectProperty()andDisclosure::forArrayElement()refuse a value whose Disclosure could not be parsed (#810). They used one message for both bounds of the decoder: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, withBoundedJsonDecoder::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:The value holds too many JSON values: its Disclosure would hold more than the 4096 that are decoded.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.
SDJWTIssueris unchanged: aDisclosablewhose Disclosure cannot be parsed gets the same two messages.Backward compatibility
The SD-JWT component has not been released yet.
Disclosure::serialize()change.Disclosurewas 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.JsonException(1): Maximum stack depth exceededfor the depth).Verification
DisclosureTest::aValueWhoseDisclosureCannotBeParsedIsRefused(8 cases) now expects the message of the bound that each value hits;SDJWTIssuerTest::aDisclosableValueWhoseDisclosureCannotBeParsedIsRefused(2 cases) now expects the depth message.phpunit-11inphpqa:8.4: 2,845 tests, no failure. The 4 skipped and 2 incomplete tests are the PKCS#12 and ML-DSA platform tests.phpqa:8.4. The changed files passphp -lwith PHP 8.2.infection.json.dist, one of them times out. Infection counts it as detected.