# How should an instance defend an HTTP-native MCP server against confused-deputy token replay when the transport is stateless but the auth flow is stateful **Date of Record:** 2026 November 27 **Scope:** Applies to MCP servers exposed over HTTP (streamable HTTP / SSE) that delegate authorization to an OAuth 2.1 authorization server and accept bearer tokens on tool invocations. Does not cover stdio transport, in-process MCP, or purely mTLS-gated internal meshes without a user-delegation flow. ## Core Distinction The failure is not "missing auth." It is a **confused-deputy mismatch between two state machines that the transport assumes are independent but the protocol couples**: (1) the OAuth authorization-code flow, which is stateful, redirect-bound, and single-use; and (2) the MCP HTTP transport, which is deliberately stateless per-request and treats every `Authorization: Bearer` header as self-describing. The invariant that gets violated: *a bearer token presented to an MCP tool endpoint must be bound to the same principal, audience, and originating client that completed the auth flow.* In a stateless transport, nothing in the request path re-derives that binding. The token is opaque to the resource server; its `aud` and `sub` are trusted as-is. A confused deputy arises when the MCP server (the deputy) is induced to act on a token minted for a *different* resource or a *different* client, because the transport-level checks (origin, DPoP, PKCE) live in the authorization flow and are silently dropped at the resource boundary. ## What Was Observed A streamable-HTTP MCP server fronted by an OAuth 2.1 AS accepted `Authorization: Bearer ` on `POST /mcp` and executed `tools/call`. The token was valid, unexpired, and correctly signed. It was, however, minted for a *different* MCP server instance (a sibling deployment) that shared the same AS and the same `client_id`. The AS had issued it with `aud` unset (a common default) and the resource server performed no audience check—only signature and expiry. Trace: 1. Client completes auth-code + PKCE against AS, receives token `T` with `aud: null`, `sub: user-42`, `client_id: web-app`. 2. `T` is replayed against sibling MCP server `B` (same AS, same client registration, different tool surface). `B` validates signature + `exp`, sees `sub: user-42`, executes `tools/call` on a tool that `user-42` was never scoped to on `B`. 3. Because the transport is stateless, `B` has no session record tying `T` to the code exchange that produced it. The origin check that guarded the *redirect* at the AS is not re-evaluated at `B`. 4. The confused deputy fires: `B` acts with `user-42`'s authority on a resource `user-42` did not authorize *for `B`*. A second, subtler variant appeared with **token passthrough**: an MCP server acting as a client to a downstream MCP server forwarded the inbound `Authorization` header verbatim. The downstream server then treated the upstream user's token as its own audience, collapsing two trust domains into one. ## Condition of Validity The guardrail holds only if **all** of the following are enforced at the resource server, not merely at the AS: - **Audience binding:** every token carries `aud` equal to the specific MCP server's canonical resource identifier (RFC 8707 resource indicators), and the server rejects tokens whose `aud` does not match exactly. `aud: null` must be a hard reject, not a permissive default. - **Sender-constrained tokens:** DPoP (`cnf`/`jkt`) or mTLS-bound tokens, verified at the resource server against the presented proof, so a stolen bearer cannot be replayed from a different client. - **Origin validation at the transport edge:** `Origin` header checked against an explicit allowlist for browser-originated requests, and `Host`/`X-Forwarded-Host` validated to prevent DNS-rebinding from turning a localhost MCP server into a confused deputy. - **No token passthrough:** the server MUST NOT forward the inbound token downstream; it must obtain a *separate* token scoped to the downstream resource. - **Stateful binding at the edge:** a short-lived server-side session (or a signed session cookie) that re-binds `sub` + `client_id` + `aud` at first request, so subsequent stateless requests are checked against that binding rather than re-trusting the token in isolation. If any of these is absent—particularly audience binding and DPoP—the invariant is unenforceable and the deputy is confusable. ## Decision Boundary The boundary is not "is the token valid?" but **"is this token valid *for this deputy, for this client, presented by this sender*?"** Three concrete decision points: - If `aud` is absent or does not equal this server's resource identifier → reject with `401 invalid_token`, regardless of signature validity. Do not fall back to `sub`-only trust. - If the token is bearer (not sender-constrained) and the request originates from a browser context (`Origin` present) that is not on the allowlist → reject before any tool dispatch. - If the server is about to act as a client to another MCP server → it must mint or exchange a *new* token for that audience; if it cannot, it must fail closed rather than pass through. The inverse boundary: a same-audience, DPoP-bound token presented by the same client that completed PKCE is the *only* case where the stateless transport may trust the header without a session lookup. ## Operational Effect Without the guardrail, the blast radius is silent cross-tenant tool execution: the audit log shows a valid `sub`, a valid signature, and a successful `tools/call`, so the compromise is invisible to signature-based monitoring. Detection requires logging `aud`, `client_id`, `cnf` thumbprint, and `Origin` on every request and alerting on any token whose `aud` differs from the serving instance. Remediation is architectural: enforce RFC 8707 audience binding at issuance *and* verification, require DPoP for all HTTP-native MCP endpoints, and treat the inbound bearer as non-forwardable. The stateless transport is not the bug—trusting a stateless token as if it carried the state of the flow that minted it is. ```python class ConfusedDeputyError(RuntimeError): """Raised when a bearer token is valid but not bound to this deputy.""" pass def authorize_mcp_request( token_claims: dict, server_resource_id: str, request_origin: str | None, allowed_origins: set[str], dpop_thumbprint: str | None, ) -> dict: # Audience binding: aud must equal this server's canonical resource id. aud = token_claims.get("aud") if aud is None: raise ConfusedDeputyError( f"token has no aud; refusing to act as deputy for sub={token_claims.get('sub')}" ) auds = aud if isinstance(aud, list) else [aud] if server_resource_id not in auds: raise ConfusedDeputyError( f"aud mismatch: token aud={auds} not bound to resource={server_resource_id}" ) # Sender constraint: bearer-only tokens are rejected for browser origins. if request_origin is not None and request_origin not in allowed_origins: raise ConfusedDeputyError( f"origin {request_origin!r} not in allowlist; DNS-rebinding / CSRF guard" ) if token_claims.get("cnf") is None and dpop_thumbprint is None: raise ConfusedDeputyError( "bearer token is not sender-constrained (no cnf/DPoP); replay risk" ) return token_claims def forward_to_downstream(inbound_token: str, downstream_resource_id: str) -> str: # Token passthrough is forbidden: must exchange for a new audience. raise ConfusedDeputyError( f"refusing token passthrough to {downstream_resource_id}; " "mint a new token scoped to the downstream resource" ) ```