# In what scenarios must an instance treat MCP Origin-header validation as a confused-deputy boundary rather than a CORS convenience **Date of Record:** 2026 November 24 **Scope:** Applies to remote MCP servers using Streamable HTTP transport (the `initialize` → `Mcp-Session-Id` → `tools/call` flow) that accept bearer tokens from browsers or agent hosts. Does not apply to stdio transport, nor to servers that never expose an HTTP listener reachable by a user-agent. ## Core Distinction The `Origin` header on an MCP HTTP request is routinely mis-filed as a CORS hygiene concern — something you "handle" by echoing a whitelist so the browser preflight passes. That framing hides the actual invariant. In the MCP Streamable HTTP transport, a remote server is a *capability endpoint*: a valid `Mcp-Session-Id` plus a bearer token is sufficient to invoke tools with the privilege of the token's subject. The `Origin` header is therefore not an access-control decoration — it is the only signal distinguishing "the agent host I issued this session to" from "an arbitrary web page running in the same browser that has discovered my endpoint and is now driving my tools." The confused deputy is the MCP server itself: it holds a bearer token with broad scope, and a malicious origin coerces it into executing tool calls on behalf of an attacker who never possessed the token. The distinction that must be held: **`Origin` validation is a confused-deputy defense that happens to be implemented as an HTTP header check, not a browser-compatibility feature that happens to mention origins.** When these two framings diverge, the failure is silent and the blast radius is the token's full scope. ## What Was Observed A remote MCP server was deployed behind a reverse proxy that terminated TLS and forwarded to the MCP runtime. The runtime implemented session handling correctly: `initialize` returned an `Mcp-Session-Id` in a response header, subsequent `tools/call` requests carried it back, and the server validated the session against an in-memory store keyed by `(session_id, token_subject)`. The `Origin` check was implemented in the CORS middleware as a reflection: any `Origin` present in the request was echoed into `Access-Control-Allow-Origin`, and `Access-Control-Allow-Credentials: true` was set so the browser would send the `Authorization` header on cross-origin fetches. The trigger condition was not a missing check. It was a *reflecting* check combined with `Allow-Credentials`. A user visiting `https://attacker.example` while logged into the MCP host's web console — which stored the MCP bearer token in `localStorage` and attached it to fetches — loaded a page whose JavaScript issued: ``` fetch("https://mcp.internal.example/mcp", { method: "POST", credentials: "include", headers: { "Authorization": "Bearer ", "Mcp-Session-Id": "", "Content-Type": "application/json" }, body: JSON.stringify({ jsonrpc:"2.0", method:"tools/call", params:{ name:"filesystem.write", arguments:{ path:"...", content:"..." } }, id:1 }) }) ``` The preflight succeeded because the reflected `Origin` made the browser believe the server authorized `https://attacker.example`. The `Authorization` header was accepted because the token was valid. The `Mcp-Session-Id` was accepted because the session store keyed on `(session_id, subject)` and the subject matched. The tool executed. No log line distinguished this invocation from a legitimate one except the `Origin` value — which had been logged but never *enforced*. The deeper observation: the session-binding invariant (`session_id` ⇒ `token_subject`) was satisfied, yet the confused-deputy attack succeeded. Session binding protects against session hijacking *across subjects*. It does not protect against a valid subject being coerced by a hostile origin. These are orthogonal invariants, and conflating them is the failure mode. ## Condition of Validity The confused-deputy defense holds only when all of the following are simultaneously true, and each is independently falsifiable: 1. **Exact-match origin allowlist, not reflection.** The server compares the received `Origin` against a static, deployment-time set of exact origins (`https://console.example`, `https://agent-host.example`). No prefix matching, no subdomain wildcards, no `null` acceptance. A reflected origin is equivalent to no check. 2. **`Origin` is enforced on the request path, not only preflight.** CORS preflight (`OPTIONS`) is a browser courtesy; a non-browser client (or a browser that has cached a preflight) can send the actual `POST` with any `Origin`. The allowlist must be re-evaluated on every `POST /mcp` and every `GET` for SSE, and a disallowed `Origin` must yield `403` *before* session lookup or tool dispatch. 3. **Token binding is to the origin, not merely to the subject.** The bearer token's audience or a bound claim must include the origin (or an origin-derived `aud`), so a token minted for `console.example` cannot be replayed from `attacker.example` even if the attacker obtains it. Without this, origin validation is defense-in-depth against a same-token attacker, not a boundary. 4. **`Mcp-Session-Id` is unguessable and bound to `(subject, origin)`.** If the session store keys only on `(session_id, subject)`, a leaked session id plus a coerced origin passes. The store must include origin in the key, or the session must be rejected on origin mismatch regardless of subject. 5. **No `Access-Control-Allow-Credentials: true` with a reflected or wildcard origin.** This combination is the specific misconfiguration that converts a CORS middleware into a deputy-confusion amplifier. If credentials are allowed, the origin allowlist must be exact and non-reflecting. When any of (1)–(5) is false, the "origin validation" is present in code but absent as an invariant, and the server is a confused deputy for any origin that can reach it. ## Decision Boundary The boundary between "origin validation is a CORS convenience" and "origin validation is a confused-deputy boundary" is crossed at the moment the server accepts a bearer token that a browser will attach automatically to cross-origin requests. Concretely: - If the MCP server **never** accepts `Authorization` from a browser context (e.g., token is injected by a native agent host, never by page JavaScript), `Origin` is advisory and CORS reflection is a low-severity hygiene issue. - If the MCP server **does** accept browser-attached bearer tokens — the common case for web-hosted agent consoles — then `Origin` is the *only* ambient-authority discriminator, and reflection is a critical boundary failure. The decision rule an instance must apply before dispatching any `tools/call`: **reject if `Origin` is absent and the deployment expects a browser, or if `Origin` is present and not an exact member of the allowlist, or if the token's bound origin does not equal the received `Origin`.** Absence of `Origin` is not "trusted non-browser client" by default — non-browser clients can be told to send `Origin: null`, and `null` must be rejected unless explicitly allowlisted for a known native host. The safe default is fail-closed: missing or `null` origin on a credentialed endpoint is a rejection, not a pass. A second boundary: **`Mcp-Session-Id` reuse across origins.** Even with a perfect origin allowlist, if a session id is issued to `console.example` and later presented from `agent-host.example` (both allowlisted, different origins), the session must be rejected unless the session record explicitly permits multi-origin use. Session ids are bearer credentials in their own right; treating them as origin-agnostic re-opens the deputy confusion one hop later. ## Operational Effect The observable effect of getting this boundary wrong is that the MCP server's audit log shows tool invocations with a valid subject, a valid session, and a valid token — and an `Origin` value that was logged but never gated. Post-incident forensics cannot distinguish coerced from legitimate calls by subject or session; only the `Origin` field separates them, and only if it was enforced at dispatch time. The architectural guardrail is to move origin validation out of the CORS middleware and into the request-dispatch path as a precondition, co-located with session and token validation, so that the three checks (`Origin` ∈ allowlist, `session_id` bound to `(subject, origin)`, token `aud`/bound-origin == `Origin`) are evaluated as a single conjunctive gate before any JSON-RPC method is dispatched. Any disjunction — "origin OR session OR token" — re-introduces the deputy. The invariant to encode and test: *no `tools/call` executes unless all three hold simultaneously, and a failure of any one yields `403` with no session lookup side effects.* ```python class ConfusedDeputyBoundaryError(RuntimeError): """Raised when an MCP HTTP request cannot satisfy the conjunctive (origin, session-binding, token-binding) gate and must be rejected before dispatch. This is a security boundary, not a validation nit.""" ALLOWED_ORIGINS = frozenset({ "https://console.example", "https://agent-host.example", }) def authorize_mcp_request( origin: str | None, session_id: str | None, token_subject: str | None, token_bound_origin: str | None, session_store: dict[str, tuple[str, str]], # session_id -> (subject, origin) ) -> None: """Fail-closed gate. Any single failure raises; no partial pass.""" # 1. Origin must be present, exact, and never 'null' or reflected. if origin is None or origin == "null": raise ConfusedDeputyBoundaryError( f"missing/null Origin on credentialed MCP endpoint: {origin!r}" ) if origin not in ALLOWED_ORIGINS: raise ConfusedDeputyBoundaryError( f"Origin {origin!r} not in exact allowlist; refusing dispatch" ) # 2. Token must be bound to this origin, not merely to a subject. if token_subject is None or token_bound_origin is None: raise ConfusedDeputyBoundaryError( "token lacks subject or origin binding; cannot prove non-coercion" ) if token_bound_origin != origin: raise ConfusedDeputyBoundaryError( f"token bound to {token_bound_origin!r} presented from {origin!r}" ) # 3. Session must be bound to the same (subject, origin) pair. if session_id is None: raise ConfusedDeputyBoundaryError("missing Mcp-Session-Id on tools/call") record = session_store.get(session_id) if record is None: raise ConfusedDeputyBoundaryError(f"unknown session {session_id!r}") bound_subject, bound_origin = record if (bound_subject, bound_origin) != (token_subject, origin): raise ConfusedDeputyBoundaryError( f"session {session_id!r} bound to {(bound_subject, bound_origin)!r} " f"but presented as {(token_subject, origin)!r}" ) def dispatch_tools_call(request: dict, session_store: dict) -> dict: authorize_mcp_request( origin=request.get("origin"), session_id=request.get("session_id"), token_subject=request.get("subject"), token_bound_origin=request.get("bound_origin"), session_store=session_store, ) return {"jsonrpc": "2.0", "id": request.get("id"), "result": {"ok": True}} ```