Repository navigation
feat(stack-auth): verify CTS access tokens against the issuer's JWKS - #1691
Draft
cipherstash-agent wants to merge 3 commits into
Draft
cipherstash-agent wants to merge 3 commits into
cipherstash-agent wants to merge 3 commits into
Conversation
Strategies trusted whatever token `authorize` returned. Whoever controls the auth URL (an injected CS_CTS_HOST, a compromised dependency, a poisoned token store) could hand the client a token with any scopes and a `services` claim pointing key requests at a rogue ZeroKMS. `verify_tokens()` on the access-key, OIDC federation, device-session and auto strategy builders now checks every token before `get_token` returns it: RS256 signature under a key from `<issuer>/.well-known/jwks.json`, `iss`, `exp` (60s leeway) and, when an audience was requested, `aud`. The trusted issuer is the CTS that service discovery names for the region, pinned separately from `base_url` and CS_CTS_HOST; `trusted_issuer(url)` pins another. The JWKS is cached for an hour and refetched early for an unknown `kid` at most once a minute. RSA verification uses aws-lc-rs natively and RustCrypto's `rsa` on wasm32, where aws-lc-rs does not build; the host tests run both backends against the same vectors. Verification is opt-in until the live check added to tests-golang.yml confirms CTS matches these assumptions. Refs CIP-5080 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012Jmn7r23UyoxCG5saYMrgG
…through an outage A failed fetch never moved the refetch clock, so a JWKS outage turned every get_token into a request to CTS. Attempts are now limited to one a minute whether they succeed or fail, and a key already cached still verifies when a refresh fails. An unreadable JWKS is a request error, not the token's. The refused-algorithm log no longer quotes the token's alg, the unverified header and claims are named as such, and the OIDC comments the ticket cites now say it is the provider's JWT that the client cannot verify. Refs CIP-5080 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012Jmn7r23UyoxCG5saYMrgG
Kills the surviving mutants in the token verifier: an hour-literal cache test, one JWK filter at a time, a 4096-bit key on both RS256 backends, and distinct refusal reasons. The wasm32 RS256 dispatch is excluded as unreachable in the host build, and the wasm32 detect_inner exclusion follows its new line. Refs CIP-5080 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012Jmn7r23UyoxCG5saYMrgG
Contributor
|
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 |
🦋 Changeset detectedLatest commit: 5390894 The changes in this PR will be included in the next version bump. This PR includes changesets to release 19 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
Mutation testing (cargo-mutants,
|
| caught | missed | unviable | timeout |
|---|---|---|---|
| 41 | 0 | 47 | 0 |
Every mutant in the changed lines was caught by a test.
This branch has not been deployed
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.
Requested by CipherStash · project thread
Summary
Today every stack-auth strategy trusts whatever token CTS's
authorizeendpoint returns. If someone controls the auth URL (an injectedCS_CTS_HOST, a compromised dependency, a poisoned token store), they can hand the client a token with any scopes and aservicesclaim that sends key requests to a rogue ZeroKMS.This PR adds a token verifier to
stack-auth. Callverify_tokens()on a strategy builder, and every token is checked beforeget_tokenreturns it:noneand HMAC are refused) by a key from<issuer>/.well-known/jwks.json;issmust be the trusted issuer;expmust not have passed (60 seconds of leeway, the same as ZeroKMS);audmust contain the audience the strategy requested, when it requested one.The trusted issuer is pinned separately from the auth URL. It is the CTS that service discovery names for the workspace's region (
https://<region>.aws.cts.cipherstashmanaged.net/).base_url()andCS_CTS_HOSTchange where tokens are requested, never which issuer is trusted. Usetrusted_issuer(url)to trust a different CTS, such as staging.Verification is opt-in in this PR. CTS signs with RS256, its issuer is the regional URL above, and its keys are at
/.well-known/jwks.json. The terraform provider's validator and CTS's route list say so, and a new step in thelivejob oftests-golang.ymlconfirms it by verifying a real CTS token (issued byhttps://us-east-2.aws.cts.cipherstashmanaged.net/). Turning verification on by default is a small follow-up.Changes
packages/stack-auth/src/token_verifier.rs(new):AuthError::InvalidToken. The reason is logged atwarn, and nothing from the token is logged.Request/Servererrors.aws-lc-sys), it uses RustCryptorsa. Only public-key operations are used, so RUSTSEC-2023-0071 does not apply. The host tests run both backends against the same vectors. vitaminc has no RSA verification.verify_tokens()/trusted_issuer()are added to theAccessKeyStrategy,OidcFederationStrategy,DeviceSessionStrategyandAutoStrategybuilders.iss.transport::getfor the JWKS request. The Go host transport already honours the request method.examples/verify_tokens.rs:tests-crates.yml;livejob oftests-golang.yml.README.md: new "Verifying tokens" section. Comments inoidc_refresher.rsandoidc_federation_strategy.rsnow make clear that the token the client can't verify is the provider's JWT.rsaand its dependencies..cargo/mutants.toml: added an exclusion for the wasm32-only dispatch, and moved the line anchor of the existing wasm32detect_innerexclusion.@cipherstash/authpatch. Its behaviour is unchanged, since the option is not exposed in JS yet.Verification
cargo test -p stack-auth --all-features: 367 passed.--no-default-features: passed. Doctests passed.cargo clippy -p stack-auth --all-targets --all-features -D warningsandRUSTDOCFLAGS=-D warnings cargo doc(both feature shapes): clean.cargo check --target wasm32-wasip1 -p stack-auth --no-default-features, with noaws-lc-sys, reqwest or js-sys in the tree.wasm32-unknown-unknowncheck forstack-auth-wasm. Both Go guests passcargo check --locked --target wasm32-wasip1.cargo mutants --in-diff): all mutants on the changed lines are caught or excluded. Each check was also confirmed by mutating it by hand.pnpm run test:scripts: 1431 passed.tests-golang.ymllivejob: it verified a token for workspace35PWGD4AWHAVOBG4issued byhttps://us-east-2.aws.cts.cipherstashmanaged.net/.Related
iss)Review notes
@cipherstash/authJS API and the Goauthpackage;audis unchecked today because the client does not know CTS's default.ServiceToken's accessors still decode claims without verifying them. They can be trusted only on tokens from a strategy with verification on.Generated by Claude Code
🤖 Generated with Claude Code
https://claude.ai/code/session_012Jmn7r23UyoxCG5saYMrgG