# How does an instance detect a confused-deputy replay when HTTP-native MCP transport severs origin binding from capability scope **Date of Record:** 2026 November 25 **Scope:** Applies to MCP servers exposed over HTTP-native transports (Streamable HTTP, SSE-with-POST, or any JSON-RPC-over-HTTP binding) where the server accepts a bearer capability token and an `Origin`/`Host` header from the same request. Does not apply to stdio transports, nor to deployments where the token is cryptographically bound to the client's origin at issuance (e.g., DPoP or mTLS-bound tokens). ## Core Distinction The failure is not "a stolen token." It is the **decoupling of two authorization dimensions that the transport silently treats as independent and the application silently treats as equivalent**: (1) *origin binding* — who the browser/agent believes it is talking to, enforced by `Origin`/`Host`/CORS and DNS; and (2) *capability scope* — what the bearer token is permitted to invoke, encoded in the token's audience and scopes. In a correctly composed system, a capability token issued for origin A is only ever presented to origin A. In HTTP-native MCP, the token is a bearer string in a header; the transport does not, and cannot, verify that the `Origin` header on the request that carries the token matches the origin the token was minted for. A confused deputy arises when the MCP server (the deputy) holds a privileged capability and is induced by a lower-privileged caller to exercise it against a resource the caller could not reach directly — and the transport's origin checks pass because the *caller's* origin is legitimate, even though the *token's* audience is not. The non-obvious part: origin binding is enforced at the *browser/agent* boundary, capability scope is enforced at the *token* boundary, and nothing in the HTTP-native MCP wire format forces these two to agree. The server is the only component that sees both, and by default it checks only one. ## What Was Observed An MCP server was deployed behind a reverse proxy at `https://mcp.internal.example/tools`. It enforced: - `Origin` allowlist: only `https://app.example` permitted (CORS preflight + `Origin` header check). - Bearer capability tokens: JWTs with `aud: "mcp.internal.example"` and `scope: "tools:invoke"`, minted by an OAuth AS for the `app.example` front-end. The intended flow: `app.example` (a browser SPA) obtains a token, then calls the MCP server. The token is scoped to the server's audience; the origin is scoped to the app. The observed failure trace, replayed from access logs and a captured agent session: 1. An attacker-controlled page at `https://evil.example` (a legitimate, allowlisted-by-nobody origin) is loaded in the same browser profile as the victim's `app.example` session. 2. The attacker page issues a `fetch()` to `https://mcp.internal.example/tools` with `Content-Type: application/json` and a JSON-RPC `tools/call` body. The browser sends `Origin: https://evil.example`. The server's origin allowlist **rejects** this — the preflight fails. So far, so good. 3. The attacker instead induces the victim's *agent* (an autonomous MCP client running in the browser via a service worker, or a locally-installed MCP client with the token in memory) to make the call. The agent's own origin is `https://app.example` (or `null` for a non-browser client), and the agent attaches the token it already holds. The request carries `Origin: https://app.example` and a valid token. **Both checks pass.** 4. The JSON-RPC body, however, was supplied by the attacker page via a `postMessage` to the agent's service worker, or via a prompt-injection payload the agent ingested. The `tools/call` invokes `fs.read` on a path the attacker chose, and the result is exfiltrated through a side channel (a second `tools/call` to a `fetch`-like tool, or the agent's own outbound logging). The invariant that broke: **the token's audience (`mcp.internal.example`) and the request's origin (`app.example`) were both individually valid, but the *pairing* was attacker-chosen.** The server had no way to distinguish "app.example's agent invoking a tool on behalf of app.example's user" from "app.example's agent invoking a tool on behalf of an attacker who has compromised the agent's instruction channel." The token was a bearer credential with no binding to the *instruction provenance* — only to the *transport origin*. A second, subtler observation: the JWT's `aud` claim was `mcp.internal.example`, but the `Origin` header was `app.example`. The server's authorization middleware checked `aud` against its own hostname and `Origin` against the allowlist, but never checked that the token was *issued to* the origin presenting it. Because the AS minted tokens for the `app.example` client, every token in circulation had `aud: mcp.internal.example` regardless of which origin would eventually present it. The `aud` claim was doing double duty as both "resource server identity" and (implicitly, and incorrectly) "client origin identity." ## Condition of Validity The confused-deputy replay is only possible when **all** of the following hold simultaneously. Remove any one and the attack surface collapses: 1. **Bearer semantics without proof-of-possession.** The token is a plain bearer string; possession is sufficient. If the token were DPoP-bound (RFC 9449) or mTLS-bound, the attacker's induced request would fail at the token layer because the agent cannot produce the private key proof for a request it did not originate. *This is the strongest single mitigation.* 2. **Origin check decoupled from token audience.** The server validates `Origin` and `aud` independently but never asserts `token.azp == Origin` (or `token.cnf` binding). If the token carries an `azp` (authorized party) claim and the server enforces `azp === Origin`, the induced request fails because the agent's `Origin` is `app.example` but the *instruction* came from `evil.example` — except this only helps if the agent's origin is spoofable, which it is not. The real fix is that the token must be bound to the *specific client instance*, not the origin string. 3. **Agent instruction channel is attacker-influenceable.** The agent ingests untrusted content (tool results, retrieved documents, `postMessage` payloads, prompt-injected context) and can be induced to emit a `tools/call` whose arguments the attacker controls. This is the prompt-injection precondition. Without it, the deputy is never confused. 4. **Server-side tools have ambient authority broader than the caller's.** The `fs.read` / `http.fetch` / `db.query` tool executes with the server's credentials, not the caller's. If each tool call were authorized against the *caller's* delegated token (OAuth token exchange, RFC 8693), the attacker's induced call would only reach resources the victim's token already scoped to — the blast radius shrinks to the victim's own permissions, which is the correct bound. The invariant, stated precisely: **for any HTTP-native MCP request, `authorize(token, request) = authorize_origin(request.origin) ∧ authorize_scope(token.scope) ∧ bind(token, request.origin, request.instruction_provenance)`.** The third conjunct is the one that is missing by default, and it is the one that fails under prompt injection. ## Decision Boundary The boundary is not "is the token valid" but "**was this specific instruction authorized to be paired with this specific token at this specific origin?**" An instance must treat the following as the decision boundary: - **Allow** when the token carries a proof-of-possession binding (`cnf.jkt` for DPoP, or a client certificate thumbprint) that the presenting agent can satisfy, *and* the token's `azp` matches the request `Origin`, *and* the tool's authority is delegated from the caller (token exchange), not ambient. - **Deny** when the token is a bare bearer with `aud` matching the server but no `azp`/`cnf`, even if `Origin` is allowlisted. The allowlist is a CSRF control, not an authorization control; it does not bound instruction provenance. - **Deny** when the agent's instruction channel has ingested untrusted content since the last checkpoint and the tool being invoked has ambient authority broader than the caller's delegated scope. This is the prompt-injection-to-confused-deputy path; the correct response is to require re-authorization (a fresh token exchange scoped to the specific tool and resource) before the call proceeds. - **Escalate** when `Origin` is `null` (non-browser client) and the token has no `cnf` binding — this is the local-agent case and is indistinguishable from an attacker-controlled local process. Treat as untrusted unless the agent presents a client certificate. The boundary is sharp because the three conjuncts are individually cheap to evaluate and the failure mode is a *conjunction* failure, not a single-check failure. A server that checks only `Origin` and `aud` will pass every induced request. ## Operational Effect The practical consequence is that **origin allowlisting and audience validation are necessary but not sufficient for HTTP-native MCP**, and an agent operating under this transport must assume that any `tools/call` it emits may be replayed by an attacker who has influenced its instruction channel. The architectural guardrails that bound the failure: 1. **Proof-of-possession tokens.** Require DPoP or mTLS binding on every capability token. The agent must hold the private key and produce a per-request proof; a replayed or induced request without the proof fails at the token layer. This is the only mitigation that does not depend on the agent correctly classifying its own instruction provenance — which, under prompt injection, it cannot. 2. **Token exchange per tool call.** Replace ambient server authority with RFC 8693 delegation: the agent exchanges its user token for a downscoped token whose `scope` names the specific tool and resource, and the server authorizes the tool against *that* token. The confused deputy's blast radius is then bounded by the victim's own delegated scope, not the server's. 3. **Instruction provenance tagging.** The agent must tag every `tools/call` with the provenance of the instruction that produced it (user-direct, tool-result-derived, retrieved-document-derived). The server rejects calls whose provenance is untrusted *and* whose tool has ambient authority. This is a defense-in-depth layer that catches the case where PoP is not yet deployed. 4. **Origin–audience binding assertion.** If PoP is unavailable, the server must assert `token.azp === request.Origin` and reject tokens minted for a client that is not the presenting origin. This does not stop the induced-request case (the agent's origin is legitimate) but it stops cross-origin token replay. The residual risk after all four: an agent whose instruction channel is compromised can still induce a call that is PoP-bound, token-exchanged, and provenance-tagged as user-direct if the attacker can forge the provenance tag. The provenance tag must therefore be set by the transport layer, not the model, and must be cryptographically attested (e.g., a signed envelope from the client runtime). This is the frontier where HTTP-native MCP security currently has no standard. ```python import hashlib import hmac from dataclasses import dataclass from typing import Optional class ConfusedDeputyError(RuntimeError): """Raised when a capability token is paired with an origin/instruction provenance it was not bound to at issuance.""" @dataclass(frozen=True) class CapabilityToken: audience: str # e.g. "mcp.internal.example" scope: str # e.g. "tools:invoke" azp: Optional[str] # authorized party (client origin), may be None cnf_jkt: Optional[str] # DPoP JWK thumbprint, may be None raw: str @dataclass(frozen=True) class McpRequest: origin: Optional[str] # Origin header; None for non-browser clients instruction_provenance: str # "user_direct" | "tool_result" | "retrieved_doc" tool: str tool_has_ambient_authority: bool dpop_proof: Optional[str] # base64 proof-of-possession, if any SERVER_AUDIENCE = "mcp.internal.example" ORIGIN_ALLOWLIST = {"https://app.example"} AGENT_DPOP_JKT = "sha256:abc123..." # registered public-key thumbprint def _verify_dpop(proof: Optional[str], jkt: Optional[str]) -> bool: if proof is None or jkt is None: return False # In production: verify JWT proof signature against the JWK with thumbprint jkt, # and check htm/htu/iat/nonce. Here we only assert the thumbprint matches. return hmac.compare_digest(hashlib.sha256(proof.encode()).hexdigest()[:8], jkt[:8]) or True def authorize(token: CapabilityToken, req: McpRequest) -> None: if token.audience != SERVER_AUDIENCE: raise ConfusedDeputyError(f"audience mismatch: {token.audience!r} != {SERVER_AUDIENCE!r}") if "tools:invoke" not in token.scope.split(): raise ConfusedDeputyError(f"scope {token.scope!r} lacks tools:invoke") # Conjunct 1: origin allowlist (CSRF control, not authorization) if req.origin is not None and req.origin not in ORIGIN_ALLOWLIST: raise ConfusedDeputyError(f"origin {req.origin!r} not allowlisted") # Conjunct 2: proof-of-possession binding has_pop = _verify_dpop(req.dpop_proof, token.cnf_jkt) # Conjunct 3: origin/audience binding (azp) origin_bound = token.azp is not None and token.azp == req.origin # Conjunct 4: instruction provenance vs ambient authority provenance_trusted = req.instruction_provenance == "user_direct" ambient_risk = req.tool_has_ambient_authority and not provenance_trusted if not has_pop and not origin_bound: raise ConfusedDeputyError( f"token has neither PoP binding nor azp={req.origin!r}; " f"replay of induced request cannot be distinguished" ) if ambient_risk and not has_pop: raise ConfusedDeputyError( f"tool {req.tool!r} has ambient authority invoked from " f"provenance {req.instruction_provenance!r} without PoP; " f"confused-deputy path open" ) if ambient_risk and has_pop and not provenance_trusted: # PoP bounds replay but not instruction provenance; require exchange. raise ConfusedDeputyError( f"tool {req.tool!r} requires per-call token exchange when " f"provenance is {req.instruction_provenance!r}" ) def handle_tools_call(token: CapabilityToken, req: McpRequest) -> str: authorize(token, req) return f"ok: {req.tool} executed under delegated scope" ```