Repository navigation
Conversation
- Reject bytes after the COSE structure, and after the encoded map inside the protected header and payload byte strings. Appended data is not covered by the signature and was silently ignored. - Enforce the crit header parameter (RFC 9052 §3.1): it must be a non-empty array of labels in the protected header, and each label must be a parameter this library processes (alg, kid). Anything else fails with the new Error::UnsupportedCriticalHeader, as §3.1 requires for critical parameters the recipient does not understand. - Convert alg with i32::try_from instead of `as i32`, so an out-of-range value like 2^32 + 5 no longer aliases HMAC 256/256 (5). Apply the same fix to the catreplay value, where 2^32 aliased 0 (replay permitted). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Problem
Token::from_bytesaccepted several inputs that RFC 9052 and RFC 8949 say to reject:crit. The header parameter was ignored. RFC 9052 §3.1 requires a recipient to reject a message whose critical header parameters it doesn't understand.algwas converted withas i32, so an out-of-range value such as2^32 + 5aliased HMAC 256/256 (5). Thecatreplayvalue had the same truncation:2^32aliased0(replay permitted).Change
from_bytesrejects bytes after the COSE structure, and after the map inside the protected and payload byte strings, withError::InvalidFormat.crit: acritparameter must be a non-empty array in the protected header. Every label must be one this library processes (alg,kid); otherwise decoding fails with the newError::UnsupportedCriticalHeader.critin the unprotected header is rejected.algandcatreplayare converted withi32::try_from. An out-of-rangealgis treated as unknown, and an out-of-rangecatreplayis an invalid claim value.Tests
src/token.rsbuild exact COSE_Mac0 bytes to cover:critalgandcatreplaycargo fmt --check,cargo clippy --all-targets -- -D warningsandcargo testpass: 68 unit tests and 74 doctests.🤖 Generated with Claude Code