Harden JWKS access assertion validation with replay protection#139
Merged
Conversation
…erver:0.27.16, e2e-auth-tests:0.4.7 - harden JWKS access assertion validation The auth server's JWKS access assertion verifier (used by both /api/jwks/[audience] and the resource-server organization-role endpoint) previously only checked the signature and sub claim. It now passes audience (the auth server's app id), issuer (the requesting api_server_id), maxTokenAge of 60s, and requiredClaims ["exp","iat","jti","aud","iss"] to jose's jwtVerify, and treats every jti as single-use via a Redis SETNX record held for twice the acceptance window, so captured assertions cannot be replayed. createJwksAccessProofToken now mints jti and iat claims and aligns exp with the 60s server-side acceptance window; verifyJwksAccessProofToken applies the same hardened verification options. Resource servers must upgrade @schemavaults/jwt (directly or via @schemavaults/auth-server-sdk) before the hardened auth server is deployed, since assertions minted without jti/iat are now rejected. Covered by new unit tests in @schemavaults/jwt (claim emission, missing exp/iat/jti, expired, stale-but-unexpired, aud/iss mismatch) and E2E tests asserting 401 for replayed, exp-less, expired, and aud/iss-mismatched assertions against /api/jwks/[audience]. Co-Authored-By: Claude <noreply@anthropic.com> https://claude.ai/code/session_01WBBNRz39UahhGYVpSwRw2r
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.
Summary
Implements hardened validation for JWKS access assertions with replay protection and comprehensive claim verification. The auth server now enforces strict claim requirements, validates token age, and prevents assertion replay using Redis-backed jti tracking.
Key Changes
Core Validation Hardening
packages/jwt/src/JwksAccessProofToken/constants.ts): DefinesJWKS_ACCESS_PROOF_TOKEN_MAX_AGE(60s) andJWKS_ACCESS_PROOF_TOKEN_REQUIRED_CLAIMS(exp, iat, jti, aud, iss) as shared validation rulescreateJwksAccessProofToken.ts):jtifor every assertion (prevents replay)expto 60 seconds fromiat(matches maxTokenAge window)api_server_id,sub,iss,aud,iat,nbf,exp,jtiverifyJwksAccessProofToken.ts): Uses jose'srequiredClaimsandmaxTokenAgeoptions to enforce strict validationReplay Protection
auth-server/src/app/api/jwks/[audience]/verifyJwksAccessAssertion.ts):Comprehensive Test Coverage
JwksAccessProofToken.test.ts):ExternalJwksLoad.cy.ts):signCustomJwksAccessAssertionfor crafting malformed assertionsImplementation Details
generateTestKeyPair,baselineClaims,signClaims,expectVerificationToReject) for reusable claim validation testingsafeParse()now correctly checks.successproperty@schemavaults/jwtindex for use by auth-server and testshttps://claude.ai/code/session_01WBBNRz39UahhGYVpSwRw2r