fix(auth): report why a JWT was rejected instead of "No token validation method configured" #291
All Vouch review confidence checks passed
Residual risk 0.28 = Change Risk (0.54) × (1 − Review Confidence (0.48)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.54 · 66 lines diff across 3 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.00 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Shallow Review Depth
shallow_review_depth
0.350
Diff Size
diff_size
0.252
Sensitive Paths
sensitive_paths
0.054
Real PR Conversation Timeline
2 items
Approved
Approved these changes.
rozzilla
mcollina
Problem
With
tokenValidation.jwksUriconfigured and no introspection endpoint,TokenValidator.validateTokenswallowed the JWT error (expired, bad signature, malformed) and fell through to the generic message. The 401 challenge then said:That misleads clients and operators: a validation method is configured, the token just failed it.
Fix
In
src/auth/token-validator.ts, record a sanitized reason when JWT verification fails, based on the fast-jwt errorcode:| fast-jwt code |
error|| --- | --- |
|
FAST_JWT_EXPIRED|Token expired||
FAST_JWT_INACTIVE|Token not yet valid||
FAST_JWT_INVALID_SIGNATURE,FAST_JWT_MISSING_SIGNATURE|Invalid token signature|| anything else |
Invalid token|If no introspection endpoint is configured, that reason is returned. The fast-jwt messages are not passed through because they can include claim values taken from the token.
No token validation method configuredis now only returned when neither JWKS nor introspection is set. When introspection is configured, the introspection result is still used as before.Tests
test/token-validator.test.ts: an expired JWT givesToken expired, a JWT with another token's signature givesInvalid token signature, and a malformed token givesInvalid token.test/auth-prehandler.test.ts: the expired-token 401 now assertserror_description="Token expired"in both the body andWWW-Authenticate.Note
PR #245 also edits
token-validator.ts(issuer constraint, constructor and top of file). This change only touchesvalidateToken's catch/fallthrough and adds a helper at the bottom of the file, so the two should merge cleanly. An issuer mismatch from #245 would show up here asInvalid token.Fixes #262
🤖 Generated with Claude Code
https://claude.ai/code/session_01UF4S3w7iA83V9DVsasLJzM