Skip to content

refactor(crypto)!: auth's own tokens pass the shared claims check at a given time - #705

Draft
PiquelChips wants to merge 3 commits into
refactor/544-registered-claimsfrom
refactor/544-crypto-claims
Draft

PiquelChips wants to merge 3 commits into
refactor/544-registered-claimsfrom
refactor/544-crypto-claims

Conversation

@PiquelChips

@PiquelChips PiquelChips commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Part of #544. Stacked on #704, itself stacked on #672, because it changes how auth verifies an id_token_hint.

Crypto's KeySet::verify and verify_id_token_hint had their own copy of the claim checks. They read Utc::now() themselves, so no caller or test could choose the time. They never checked nbf. And the hint came back as a raw serde_json::Value, which auth then picked apart by hand. Both methods now take the time to check at and run the shared Validation::check from the previous PR. The hint now decodes as IdTokenClaims.

Policy

Auth checks its own tokens with Expiry::Strict, which allows no leeway on exp, as before. A hint is checked with Expiry::Ignored: it may have expired, as before. nbf and iat get the 30 s leeway, as iat already did. The audience isn't checked, as before: UserInfo accepts 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) gains now and the RegisteredClaims bound, so T = serde_json::Value no longer works.
    • KeySet::verify_id_token_hint(token, issuer, now) -> IdTokenClaims gains now and returns typed claims.
    • CryptoError::Expired is 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.
    • InvalidToken now covers only framing and headers, and reads "JWT framing or headers are invalid".
  • Auth's own tokens: UserInfo access tokens and hints now have nbf checked. Auth always writes nbf: None, so this changes nothing in practice. UserInfo's error_description for a rejected token now names the claim, for example access token is invalid: token expired at … instead of … JWT has expired.
  • id_token_hint (src/oidc/hint.rs):
    • Signed claims that don't decode as an ID token are refused with invalid_request and id_token_hint claims are invalid: <field>, at both authorization and logout. That covers a missing exp, iat, sub or aud, and an invalid sid.
    • This replaces the earlier per-claim messages. A missing iat used to count as unverified, and an unreadable sid used to be ignored.
    • A hint whose aud is an array is still refused as "audience is not a client ID".

Tests

  • The crypto signing test now runs at a pinned instant long past. A check that read the system clock would refuse every token. It covers exp with no leeway for tokens and none checked for hints, nbf (new) and iat at the leeway boundary, a wrong issuer, and claims that don't decode.
  • Crypto's other tests and auth's key-store and OIDC tests verify typed claims instead of Value: AccessTokenClaims for access tokens, IdTokenClaims for ID tokens. The logout-token test compares the decoded claims' JSON, as before.
  • authorization_and_logout_read_a_hint_alike adds the two hints whose outcome changed, one with no iat and one with "sid":"not-a-session". Both are now refused at authorization and logout, and the test checks each refusal's error_description.
  • userinfo_needs_the_openid_scope_and_an_unexpired_token checks that an expired access token gets invalid_token, with access 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 generated packages/auth/src/protocol.ts.

Checks

  • cargo clippy --locked --all-targets -- -D warnings, with and without --all-features, for sourceorigin-crypto and auth-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-types was rerun for the IdTokenClaims doc.
  • cargo semver-checks -p sourceorigin-crypto --baseline-rev origin/main: major. CryptoError::Expired is removed, Claims and InvalidClaims are added, and both KeySet methods' 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)

@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 added apps/auth-service Origin Auth at auth.sourceorigin.dev, its settings and developer console, and the operator CLI refactor No behviour changes labels Nov 22, 2026
@PiquelChips
PiquelChips force-pushed the refactor/544-crypto-claims branch from a9c357e to 6160dab Compare November 22, 2026 14:15
…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
PiquelChips force-pushed the refactor/544-crypto-claims branch from 6160dab to a95b435 Compare November 22, 2026 14:34
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

Projects

Status: Needs Triage

Development

Successfully merging this pull request may close these issues.

1 participant