[PoC] TT-17423: return 401 (not 400) on missing JWT Authorization for PRM/MCP flow#8425
[PoC] TT-17423: return 401 (not 400) on missing JWT Authorization for PRM/MCP flow#8425edsonmichaque wants to merge 2 commits into
Conversation
… PRM flow When the Authorization header is absent, the JWT middleware returned 400 Bad Request. RFC 9728 / MCP clients (e.g. VS Code) only begin the PRM-discovery + OAuth flow on a 401 challenge, so a 400 — even with the WWW-Authenticate resource_metadata header — leaves spec-compliant clients unable to authenticate. Return 401 Unauthorized instead. Gateway-side counterpart of the EDP PRM work (TT-17423; portal + dcr).
|
This PR changes the JWT middleware to return a The core logic change is a single line in Files Changed Analysis
Architecture & Impact Assessment
Authentication FlowsequenceDiagram
participant Client as "PRM/MCP Client"
participant Gateway as "Tyk Gateway (JWT Middleware)"
alt "Before (master)"
Client->>Gateway: GET /protected/resource (No Authorization header)
Gateway-->>Client: 400 Bad Request
Note right of Client: Client receives unexpected error, cannot start auth flow.
alt "After (This PR)"
Client->>Gateway: GET /protected/resource (No Authorization header)
Gateway-->>Client: 401 Unauthorized (with WWW-Authenticate header)
Note right of Client: Client receives expected challenge, initiates PRM discovery and OAuth.
end
end
Scope Discovery & Context Expansion
Metadata
Powered by Visor from Probelabs Last updated: 2026-07-02T15:25:14.064Z | Triggered by: pr_updated | Commit: e86a721 💡 TIP: You can chat with Visor using |
✅ Security Check PassedNo security issues found – changes LGTM. Architecture Issues (1)
✅ Performance Check PassedNo performance issues found – changes LGTM. Quality Issues (1)
Powered by Visor from Probelabs Last updated: 2026-07-02T15:24:56.188Z | Triggered by: pr_updated | Commit: e86a721 💡 TIP: You can chat with Visor using |
The 400->401 change in mw_jwt.go broke two existing tests that asserted the old status on the missing-credential path (rawJWT == ""): - TestJWTSessionFailRSA_NoAuthHeader (no Authorization header) - TestJWTSessionFailRSA_EmptyJWT (empty Authorization header) Both hit the same branch; update them to expect http.StatusUnauthorized. These now cover the PoC change. Both pass.
|
SentinelOne CNS Hardcoded Secret Detector SentinelOne CNS is a cloud-agnostic, agentless CSPM & CWPP solution that continuously detects and prevents vulnerabilities that have the highest probability of being exploited in Azure, AWS, Google Cloud, and Kubernetes. |
What
When the
Authorizationheader is missing, the JWT middleware returns 401 Unauthorized instead of 400 Bad Request.Why
RFC 9728 (Protected Resource Metadata) / MCP clients — e.g. VS Code — only begin the PRM-discovery + OAuth flow when they receive a 401 challenge. Returning 400 on a missing credential (even with the
WWW-Authenticate: ... resource_metadata=...header) leaves spec-compliant clients unable to authenticate against a protected MCP server.Change
gateway/mw_jwt.go— inJWTMiddleware.ProcessRequest, the missing-Authorization-field path now callsprmError(..., http.StatusUnauthorized)instead ofhttp.StatusBadRequest. Single-hunk, +6/-1.Scope / status
Proof of concept, draft. Gateway-side counterpart of the EDP PRM work under TT-17423 (portal PoC +
dcrscope-normalization PR). Not intended to merge as-is — opening for review/alignment. Needs: confirmation that 401 is correct for all missing-credential JWT cases (not just MCP/PRM), and test coverage for the status change.Testing
go build ./gateway/passes.