Repository navigation
Conversation
RFC 8392 §3.1 fixes the types of the registered claims, but RegisteredClaims::from_map skipped any value of the wrong type and cast NumericDates with `as u64`. Two consequences on the verification path: - A negative exp became a far-future time, so the token never expired. - An iss, sub or aud of the wrong type (or an array-valued aud) was dropped, so the token passed expected_issuer / expected_audience unless require_iss / require_aud was also set. Token::from_bytes now decodes registered claims with the new strict RegisteredClaims::try_from_map / Claims::try_from_map and fails with Error::InvalidRegisteredClaim when a claim is present but malformed: iss and sub must be text, aud text or an array of text, exp/nbf/iat non-negative integers, cti bytes. An array-valued aud is kept, exposed through Token::audiences(), and expected_audience must match one of its entries. The lenient from_map remains but skips negative dates instead of casting them. 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
RFC 8392 §3.1 fixes the types of the registered claims.
RegisteredClaims::from_map, whichToken::from_bytesused, skipped any value of the wrong type and cast NumericDates withas u64. On the verification path that meant:expbecame a far-future time, so the token never expired.iss,suboraudof the wrong type was dropped, so the token passedexpected_issuer/expected_audienceunlessrequire_iss/require_audwas also set.audwas dropped too. Such a token passed any expected audience.Change
Token::from_bytesdecodes registered claims with the new strictRegisteredClaims::try_from_map/Claims::try_from_map. A claim that is present but malformed fails with the newError::InvalidRegisteredClaim.iss,sub: textaud: text, or an array of textexp,nbf,iat: non-negative integer NumericDatescti: byte stringaudis kept and readable through the newToken::audiences().expected_audiencemust match one of its entries.RegisteredClaims::from_mapstays lenient, but it now skips negative dates instead of casting them.Behavior change: a text
ctiused to be tolerated (test_cti_as_text_verifies_and_roundtrips) and is now rejected. RFC 8392 §3.1.7 definesctias a byte string, and silently dropping it can defeat replay caches keyed oncti.Non-integer NumericDates are rejected. RFC 8392 §2 permits floating-point NumericDates, and accepting them, rounding up, is a possible follow-up once #8 adds
CborValue::Float. Until then, rejecting them fails closed. With #8 merged, a floatexpis rejected rather than dropped, which is covered by a probe.Tests
src/claims.rscover:iss,sub,audandctiaudwith a non-text entryaudfrom_mapaudiences().cargo fmt --check,cargo clippy --all-targets -- -D warningsandcargo testpass: 66 unit tests and 74 doctests.🤖 Generated with Claude Code