Repository navigation
Handle JWT key manager misconfiguration errors in route guards - #264
Merged
Merged
Conversation
…- show server_misconfiguration when the JWKS cannot be loaded instead of looping through login A resource server whose JWKS download the auth server refuses (its JWKS access key is not the API server's active one, or the API server id is wrong) or whose SCHEMAVAULTS_AUTH_JWKS_ACCESS_PRIVATE_KEY is unusable cannot verify any token. The failure was swallowed as "no user", so withAuthenticatedServerComponentRouteGuard sent the browser to /auth/login; with a live auth server session the login flow minted a fresh token the server could not verify either, and the browser looped. - RemoteJwtKeyManager / loadRemoteJwks throw JwtKeyManagerMisconfigurationError (reason jwks_download_refused for a 4xx other than 408/429, with the status and the auth server's answer; jwks_access_private_key_unusable when the key cannot be loaded or cannot sign the access assertion). Outages (5xx, 408, 429, network) stay unauthenticated. - loadJwtDecodingKeys rethrows it; decodeJWTsWithKeyManager (and so RouteGuardFactory.createGuardFromTokenSources) throws it when no token verified. - withAuthenticatedServerComponentRouteGuard redirects to the codegen'd /auth/error?error=500&error_id=server_misconfiguration; withAuthenticatedApiRouteGuard answers 500; createSchemaVaultsAuthResolvers answers 500 auth_not_configured naming the cause (instead of 401s that send clients to sign in again). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019cgR5TkZN85MnxS8MevFx4
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
This PR adds proper handling for JWT key manager misconfiguration errors in route guards and token decoding. When the auth server refuses a JWKS download (4xx response) or the JWKS access private key is unusable, the system now reports a server misconfiguration (500) instead of treating it as an unauthenticated request (401). This prevents infinite redirect loops where signing in again would only mint another token the server cannot verify.
Key Changes
New
JwtKeyManagerMisconfigurationErrorclass: Distinguishes between two types of configuration failures:jwks_download_refused: Auth server refused the JWKS download (4xx status, typically 401/403/404)jwks_access_private_key_unusable: JWKS access private key is missing, unparseable, or cannot sign assertionsEnhanced
loadRemoteJwks():isJwksDownloadRefusal()helper to identify 4xx responses (excluding transient 408/429)JwtKeyManagerMisconfigurationErrorfor refused downloads with status code and auth server response detailsJwtKeyManagerMisconfigurationErrorfor unusable private keys with clear error messagingRoute guard error handling:
withAuthenticatedServerComponentRouteGuard: Catches misconfiguration errors and redirects to/auth/error?error=500&error_id=server_misconfigurationinstead of loginwithAuthenticatedApiRouteGuard: Returns 500 JSON response instead of 401 for misconfiguration errorsToken decoding improvements:
decodeJWTsWithKeyManager()now throwsJwtKeyManagerMisconfigurationErrorwhen no token verifies due to misconfigurationOpenAPI operations resolver: Updated to return 500
auth_not_configuredfor misconfiguration errors instead of 401Comprehensive test coverage: Added tests for both server component and API route guards, verifying correct error responses and that transient failures still result in 401
Implementation Details
https://claude.ai/code/session_019cgR5TkZN85MnxS8MevFx4