Repository navigation
refactor(sdk)!: the SDK and Google sign-in share one registered-claims check - #704
Draft
PiquelChips wants to merge 3 commits into
Draft
PiquelChips wants to merge 3 commits into
PiquelChips wants to merge 3 commits into
Conversation
…aims check Validation::check in sourceorigin_common::protocol::registered checks iss, aud, exp, nbf, iat and nonce at an injected time, with the leeway policy in Expiry. The Rust SDK's TokenError and auth's GoogleError wrap its ClaimsError instead of repeating the variants, and Google's ID tokens now have their nbf checked.
|
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. |
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 #672; the next PR stacks on this one.
The time, audience and nonce checks of a token's claims were written three times: in the Rust SDK, in Google sign-in, and in crypto's key set. Each had its own leeway rules and errors, and Google never checked
nbf. This PR adds the one check and moves the SDK and Google sign-in onto it. The next PR moves crypto's key set onto it too.The check
sourceorigin_common::protocol::registeredholds:Validation, which checksiss,aud,exp,nbf,iatandnonce, in that order (the SDK's documented order). It takes the time to check at asnow, so callers inject their clock.Expiry, the leeway policy.nbfandiatalways getLEEWAY, because the issuer's clock may be ahead.expgets it only whereExpiry::Lenientsays (the SDKs). It gets none withStrict(auth and Google) and is skipped withIgnored(anid_token_hint).RegisteredClaims, the trait the claim types implement. A macro implements it forAccessTokenClaims,IdTokenClaimsandLogoutTokenClaims. Each type must name itsnbfandnoncefields ornone, so a type can't skip a check by omission. Google's claims implement it by hand.ClaimsError, withreason()giving the shared SDKErrorReason.Why
commonand notcrypto: crypto depends on common, the SDK on both, and auth on all three, so either crate avoids a cycle. The check is protocol semantics with no cryptography. It reads common's claim types,LEEWAYandErrorReason, all of which already live incommon::protocol.Where checks differed, and what stays
expleeway: the SDK keeps 30 s. Google keeps none. This is intended (theLEEWAYcomment) because Google's token comes straight from its token endpoint.iatleeway: 30 s everywhere. This was already the case.nbf: Google sign-in now checksnbf, with the same leeway asiat. Google may sendnbf, and it went unchecked before.issspellings.Validation::issuersis a list for that reason.RegisteredClaims::EXCLUSIVE_AUDIENCE). This is unchanged.azp,max_ageand logout lifetime stay where they were. They aren't registered claims.Visible and API changes
sourceorigin-auth(breaking):TokenError::{WrongIssuer, WrongAudience, Expired, NotYetValid, IssuedInFuture, NonceMismatch}are replaced byTokenError::Claims(ClaimsError).TokenError::code()and every SDK code are unchanged, and the SDK vectors don't change. Display text is unchanged exceptWrongIssuer, which now readsexpected one of [...].sourceorigin_auth::protocolre-exportsregistered.sourceorigin-common(additive): adds theprotocol::registeredmodule.LEEWAY's doc now says auth tolerates it onnbfandiat, which also changes a comment in the generatedpackages/auth/src/protocol.ts. The SDK design (docs/dev/architecture/sdk.md) says the same.GoogleError'sUntrustedIssuer,WrongAudience,SharedAudience,NonceMismatch,ExpiredandIssuedInFuturebecomeRejected(ClaimsError). That changes the log text, and with several faults the nonce is now reported after the times. Every one is still recorded asSignInFailure::InvalidCredential.GoogleClaims::verifytakesnow.Tests
protocol::registered::testscovers the leeway policy at each boundary for everyExpiry, the check order (each fault in turn), issuer lists, exclusive and shared audiences, and nonces. Every check runs at a fixed instant long past, so a check that read the system clock would fail.google_signed_tokens_are_verifiednow runs at a pinnednow. It asserts the shared check's typed errors, and addsnbfand the leeway boundaries onnbfandiat.Checks
cargo clippy --locked --all-targets -- -D warnings, with and without--all-features, forsourceorigin-common,sourceorigin-authandauth-service.just test -p sourceorigin-common --all-featuresandjust test -p sourceorigin-auth --all-features, plus their doc tests. Under machine load, nextest's 300 s cap timed out the trybuildcompile_failtest, which then passed withcargo test --test compile_fail.just db test -E 'test(federation)'.just sdk-types: only theLEEWAYcomment changed.just sdk-vectors: unchanged.cargo semver-checks --baseline-rev origin/main:sourceorigin-common: no semver update required.sourceorigin-auth: major. The sixTokenErrorvariants are removed andTokenError::Claimsis added, hence the!.just db test(all 510 tests),RUSTDOCFLAGS='-D warnings' cargo doc --workspace --no-depsandjust rust unusedran at the head of the next PR, which contains this one.Note
Written by Claude Opus 5.5 in Claude Code and reviewed by Claude Opus 5.5 (via T3 Code)