Repository navigation
refactor(crypto)!: auth's own tokens pass the shared claims check at a given time - #705
Draft
PiquelChips wants to merge 3 commits into
Draft
PiquelChips wants to merge 3 commits into
PiquelChips wants to merge 3 commits into
Conversation
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
PiquelChips
force-pushed
the
refactor/544-crypto-claims
branch
from
November 22, 2026 14:15
a9c357e to
6160dab
Compare
…a given time KeySet::verify and verify_id_token_hint take the time to check at and run Validation::check: no more Utc::now() inside crypto, and nbf is now checked. The hint decodes as IdTokenClaims rather than a raw Value, and CryptoError::Expired gives way to Claims and InvalidClaims.
Hints without iat or with an unreadable sid are now refused, and UserInfo names the claim an expired token fails. Access tokens verify as AccessTokenClaims in tests, and IdTokenClaims says why its decoding must stay backward-compatible.
PiquelChips
force-pushed
the
refactor/544-crypto-claims
branch
from
November 22, 2026 14:34
6160dab to
a95b435
Compare
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.
Part of #544. Stacked on #704, itself stacked on #672, because it changes how auth verifies an
id_token_hint.Crypto's
KeySet::verifyandverify_id_token_hinthad their own copy of the claim checks. They readUtc::now()themselves, so no caller or test could choose the time. They never checkednbf. And the hint came back as a rawserde_json::Value, which auth then picked apart by hand. Both methods now take the time to check at and run the sharedValidation::checkfrom the previous PR. The hint now decodes asIdTokenClaims.Policy
Auth checks its own tokens with
Expiry::Strict, which allows no leeway onexp, as before. A hint is checked withExpiry::Ignored: it may have expired, as before.nbfandiatget the 30 s leeway, asiatalready did. The audience isn't checked, as before:UserInfoaccepts any access token auth issued, and the hint's audience is compared to the client by its callers.Visible and API changes
sourceorigin-crypto(breaking):KeySet::verify<T: RegisteredClaims + DeserializeOwned>(token, type, issuer, now)gainsnowand theRegisteredClaimsbound, soT = serde_json::Valueno longer works.KeySet::verify_id_token_hint(token, issuer, now) -> IdTokenClaimsgainsnowand returns typed claims.CryptoError::Expiredis gone. Two variants replace it.CryptoError::Claims(ClaimsError)is transparent, so the message names the failing claim.CryptoError::InvalidClaims(serde_json::Error)is for signed claims that don't decode.InvalidTokennow covers only framing and headers, and reads "JWT framing or headers are invalid".UserInfoaccess tokens and hints now havenbfchecked. Auth always writesnbf: None, so this changes nothing in practice.UserInfo'serror_descriptionfor a rejected token now names the claim, for exampleaccess token is invalid: token expired at …instead of… JWT has expired.id_token_hint(src/oidc/hint.rs):invalid_requestandid_token_hint claims are invalid: <field>, at both authorization and logout. That covers a missingexp,iat,suboraud, and an invalidsid.iatused to count as unverified, and an unreadablesidused to be ignored.audis an array is still refused as "audience is not a client ID".Tests
expwith no leeway for tokens and none checked for hints,nbf(new) andiatat the leeway boundary, a wrong issuer, and claims that don't decode.Value:AccessTokenClaimsfor access tokens,IdTokenClaimsfor ID tokens. The logout-token test compares the decoded claims' JSON, as before.authorization_and_logout_read_a_hint_alikeadds the two hints whose outcome changed, one with noiatand one with"sid":"not-a-session". Both are now refused at authorization and logout, and the test checks each refusal'serror_description.userinfo_needs_the_openid_scope_and_an_unexpired_tokenchecks that an expired access token getsinvalid_token, withaccess token is invalid: token expired at <exp>.IdTokenClaims' doc now says its decoding must stay backward-compatible. Auth reads every hint it signed as these claims, even an expired hint or one signed by a retired key, so a stricter field would refuse every older hint. The doc also appears in the generatedpackages/auth/src/protocol.ts.Checks
cargo clippy --locked --all-targets -- -D warnings, with and without--all-features, forsourceorigin-cryptoandauth-service.just test -p sourceorigin-crypto --all-features(18 tests) and the crypto and common doc tests.just db test: 510 passed, plus the SQLx prepare check. This ran at this PR's head, so it includes the previous PR.RUSTDOCFLAGS='-D warnings' cargo doc --workspace --no-deps: clean.just sdk-typeswas rerun for theIdTokenClaimsdoc.cargo semver-checks -p sourceorigin-crypto --baseline-rev origin/main: major.CryptoError::Expiredis removed,ClaimsandInvalidClaimsare added, and bothKeySetmethods' parameter counts change, hence the!.just rust unused: no unused dependencies.Note
Written by Claude Opus 5.5 in Claude Code and reviewed by Claude Opus 5.5 (via T3 Code)