← Back to Pull requests

fix(auth): report why a JWT was rejected instead of "No token validation method configured" #291

Merged
mcollina merged 3 files (66 lines) on Oct 14, 2026 11:10 UTC
View on GitHub
mcollina mcollina commented on Oct 13, 2026 11:21 UTC
Author

Problem

With tokenValidation.jwksUri configured and no introspection endpoint, TokenValidator.validateToken swallowed the JWT error (expired, bad signature, malformed) and fell through to the generic message. The 401 challenge then said:

WWW-Authenticate: Bearer ..., error="invalid_token", error_description="No token validation method configured"

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 error code:

| 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 configured is 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 gives Token expired, a JWT with another token's signature gives Invalid token signature, and a malformed token gives Invalid token.

  • test/auth-prehandler.test.ts: the expired-token 401 now asserts error_description="Token expired" in both the body and WWW-Authenticate.
  • Note

    PR #245 also edits token-validator.ts (issuer constraint, constructor and top of file). This change only touches validateToken'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 as Invalid token.

    Fixes #262

    🤖 Generated with Claude Code

    https://claude.ai/code/session_01UF4S3w7iA83V9DVsasLJzM

    Diff: 66 lines (+65 / -1) across 3 files Reviewer: rozzilla Review duration: 1428m
    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
    0.54
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.00 · 1 substantive comment(s)
    0.00
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    48%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    rozzilla rozzilla approved these changes on Oct 14, 2026 08:40 UTC
    Approved Reviewer

    Approved these changes.

    Reviewers
    Assignees
    mcollina mcollina
    Labels
    risk: low confidence: 48.5% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 54.3% (MEDIUM) · Higher = larger blast radius
    54.3%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 48.5% · Lower = rushed or shallow review
    48.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 27.9% · Safe to merge
    27.9%