Skip to content

refactor(sdk)!: the SDK and Google sign-in share one registered-claims check - #704

Draft
PiquelChips wants to merge 3 commits into
refactor/544-decision-id-token-hintfrom
refactor/544-registered-claims
Draft

PiquelChips wants to merge 3 commits into
refactor/544-decision-id-token-hintfrom
refactor/544-registered-claims

Conversation

@PiquelChips

@PiquelChips PiquelChips commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

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::registered holds:

  • Validation, which checks iss, aud, exp, nbf, iat and nonce, in that order (the SDK's documented order). It takes the time to check at as now, so callers inject their clock.
  • Expiry, the leeway policy. nbf and iat always get LEEWAY, because the issuer's clock may be ahead. exp gets it only where Expiry::Lenient says (the SDKs). It gets none with Strict (auth and Google) and is skipped with Ignored (an id_token_hint).
  • RegisteredClaims, the trait the claim types implement. A macro implements it for AccessTokenClaims, IdTokenClaims and LogoutTokenClaims. Each type must name its nbf and nonce fields or none, so a type can't skip a check by omission. Google's claims implement it by hand.
  • ClaimsError, with reason() giving the shared SDK ErrorReason.

Why common and not crypto: 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, LEEWAY and ErrorReason, all of which already live in common::protocol.

Where checks differed, and what stays

  • exp leeway: the SDK keeps 30 s. Google keeps none. This is intended (the LEEWAY comment) because Google's token comes straight from its token endpoint.
  • iat leeway: 30 s everywhere. This was already the case.
  • nbf: Google sign-in now checks nbf, with the same leeway as iat. Google may send nbf, and it went unchecked before.
  • Accepted issuers: Google accepts either of its two iss spellings. Validation::issuers is a list for that reason.
  • Audience: ID, logout and Google tokens must name the expected audience alone, while access tokens may name several (RegisteredClaims::EXCLUSIVE_AUDIENCE). This is unchanged.
  • azp, max_age and 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 by TokenError::Claims(ClaimsError). TokenError::code() and every SDK code are unchanged, and the SDK vectors don't change. Display text is unchanged except WrongIssuer, which now reads expected one of [...]. sourceorigin_auth::protocol re-exports registered.
  • sourceorigin-common (additive): adds the protocol::registered module. LEEWAY's doc now says auth tolerates it on nbf and iat, which also changes a comment in the generated packages/auth/src/protocol.ts. The SDK design (docs/dev/architecture/sdk.md) says the same.
  • Auth, Google sign-in: GoogleError's UntrustedIssuer, WrongAudience, SharedAudience, NonceMismatch, Expired and IssuedInFuture become Rejected(ClaimsError). That changes the log text, and with several faults the nonce is now reported after the times. Every one is still recorded as SignInFailure::InvalidCredential. GoogleClaims::verify takes now.

Tests

  • New protocol::registered::tests covers the leeway policy at each boundary for every Expiry, 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_verified now runs at a pinned now. It asserts the shared check's typed errors, and adds nbf and the leeway boundaries on nbf and iat.

Checks

  • cargo clippy --locked --all-targets -- -D warnings, with and without --all-features, for sourceorigin-common, sourceorigin-auth and auth-service.
  • just test -p sourceorigin-common --all-features and just test -p sourceorigin-auth --all-features, plus their doc tests. Under machine load, nextest's 300 s cap timed out the trybuild compile_fail test, which then passed with cargo test --test compile_fail.
  • just db test -E 'test(federation)'.
  • just sdk-types: only the LEEWAY comment changed. just sdk-vectors: unchanged.
  • cargo semver-checks --baseline-rev origin/main:
    • sourceorigin-common: no semver update required.
    • sourceorigin-auth: major. The six TokenError variants are removed and TokenError::Claims is added, hence the !.
  • just db test (all 510 tests), RUSTDOCFLAGS='-D warnings' cargo doc --workspace --no-deps and just rust unused ran 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)

…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.
@github-project-automation github-project-automation Bot moved this to Needs Triage in sourceorigin.dev Nov 22, 2026
@PiquelChips PiquelChips added apps/auth-service Origin Auth at auth.sourceorigin.dev, its settings and developer console, and the operator CLI refactor No behviour changes sdk Rust and TypeScript SDKs labels Nov 22, 2026
@coderabbitai

coderabbitai Bot commented Nov 22, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

@PiquelChips PiquelChips changed the title refactor(common)!: the SDK and Google sign-in share one registered-claims check refactor(sdk)!: the SDK and Google sign-in share one registered-claims check Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

apps/auth-service Origin Auth at auth.sourceorigin.dev, its settings and developer console, and the operator CLI refactor No behviour changes sdk Rust and TypeScript SDKs

Projects

Status: Needs Triage

Development

Successfully merging this pull request may close these issues.

1 participant