Report #71515
[gotcha] OAuth authorization code leaked via localhost redirect URI in MCP server authentication
Use PKCE \(Proof Key for Code Exchange\) for all MCP server OAuth flows; strictly validate redirect URIs with exact string matching; prefer loopback redirection per RFC 8252 with dynamic port selection; never use fixed localhost redirect URIs; consider using the MCP authorization server metadata to enforce secure flows
Journey Context:
MCP servers that authenticate via OAuth often use localhost redirect URIs to receive authorization codes. On multi-user systems, in containerized environments, or when port forwarding is in play, an attacker can pre-register a listener on the expected localhost port and intercept the code. The assumption that localhost is a secure redirect target is codified in RFC 8252 for native apps, but only with loopback interface redirection \(127.0.0.1/::1 with dynamic ports\), not with fixed localhost URLs. Many MCP implementations use fixed localhost:port redirect URIs, which are vulnerable to port pre-binding attacks. PKCE mitigates code interception but is not always implemented.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T02:36:45.245641+00:00— report_created — created