# Why does an instance of an MCP server confabulate a downstream authorization decision when the upstream client omits a bearer token on a streamable-HTTP transport? **Date of Record:** 2026 November 27 **Scope:** Applies to MCP servers exposing tools over HTTP-native transports (Streamable HTTP, SSE-with-POST) where the server both (a) authenticates the calling client and (b) acts as a confused-deputy proxy to downstream resources using server-held credentials. Does not apply to stdio transports, nor to servers that require per-request end-user tokens passed through verbatim. ## Core Distinction The failure is not "missing authentication." A missing bearer token on an HTTP-native MCP transport produces a clean 401 at the transport layer. The non-obvious failure is the *authorization confabulation boundary*: when the transport layer is configured to accept a request via a secondary identity channel (mTLS client cert, session cookie set at `initialize`, or an `Mcp-Session-Id` header bound to a prior authenticated handshake), the server-side tool dispatcher may receive a `RequestContext` with `principal=None` but `session.authenticated=True`. Under that half-populated context, a naive tool implementation that reads `ctx.principal.scopes` will not raise — because the LLM-facing tool schema declares `scopes` as an optional field, and the server's own JSON-RPC envelope validator treats a `null` principal as a schema-valid, anonymous call. The model then proceeds to invoke the tool, the tool falls back to the *server's* service identity for the downstream call, and the confused-deputy transition occurs silently. The invariant that must hold is: **no tool invocation may reach a downstream credential-bearing call site unless a principal is bound to the request context and that principal has been re-validated against the tool's declared scope set at dispatch time, not at handshake time.** ## What Was Observed A streamable-HTTP MCP server fronted by an OAuth 2.1 authorization server accepted the initial `initialize` request with a valid bearer token, issued an `Mcp-Session-Id`, and bound the token's subject to that session in a Redis-backed session store with a 30-minute TTL. The client then entered a long-running agent loop; at minute 31, the session TTL expired but the client's own local session cache did not. The client continued issuing `tools/call` requests with a stale `Mcp-Session-Id` and no `Authorization` header (the client library had stripped it after the first successful handshake, treating the session as the bearer). The server's session middleware, on lookup miss, did not return 401. It returned a *degraded* session object: `{session_id: , authenticated: False, principal: None, transport: "streamable-http"}` — because the middleware was written to support "anonymous read-only tools" for a subset of the catalog and had no branch distinguishing "no session ever existed" from "session existed and expired." The JSON-RPC dispatcher, seeing a syntactically valid `tools/call` envelope for a tool named `fetch_internal_wiki`, routed it to the tool handler. The handler's schema declared `required: ["query"]` and `optional: ["scopes"]`. The LLM had, in prior turns, observed a successful call to the same tool and reconstructed a plausible argument object from its own context window — including a `scopes: ["wiki:read"]` field that the model hallucinated from a system prompt fragment mentioning "wiki read access is available to authenticated users." The handler read `scopes` from the *arguments*, not from the principal, and passed them to the downstream wiki API's authorization check. The downstream API, trusting the caller (the MCP server) as a confidential client, honored the asserted scopes. Net effect: an expired session produced a successful, scope-asserted, model-fabricated authorization decision, and the downstream wiki returned content the model had no live entitlement to. The audit log recorded a 200 with `principal=null` and `scopes=["wiki:read"]`, which reads as "anonymous user with wiki read scope" — a tuple that should be structurally impossible. ## Condition of Validity The guardrail holds only if all four of the following are simultaneously true at dispatch time: 1. **Principal binding is mandatory, not optional.** The tool dispatcher must reject any `tools/call` whose context lacks a non-null `principal`, regardless of whether the tool's JSON schema marks authorization fields as optional. Schema optionality is a *model-facing* affordance and must never be conflated with *server-facing* authorization state. 2. **Session degradation is distinguishable from session absence.** The session middleware must return a typed error (`SessionExpired` vs. `SessionNotFound`) and the dispatcher must map both to 401 with `WWW-Authenticate: Bearer error="invalid_token"`, never to an anonymous context. 3. **Scope assertion is server-derived, never argument-derived.** Any field in a tool's input schema whose name matches a reserved authorization vocabulary (`scopes`, `roles`, `permissions`, `acting_as`, `on_behalf_of`) must be stripped by the dispatcher before the handler sees it, and the handler must read authorization exclusively from `ctx.principal`. 4. **Downstream credentials are bound to the principal, not the server.** The confused-deputy mitigation requires that the server's downstream call carry an *on-behalf-of* token derived from the principal (RFC 8693 token exchange, or a per-principal credential vault lookup), not the server's own service credential. If the downstream call uses the server's service identity, the server is by definition a confused deputy and no amount of upstream validation fixes it. The invariant is violated the moment any one of these is relaxed, and the violation is silent because the LLM will generate schema-valid arguments that satisfy the handler's runtime checks. ## Decision Boundary The boundary is between *"the model may propose an authorization claim"* and *"the server may accept one."* These must be separated by a structural gap, not a validation check. Concretely: - If a tool's input schema contains a field that influences downstream authorization, the schema is malformed and must be rejected at server registration time (`initialize` response should omit it from `tools/list`). - If the dispatcher's `RequestContext` type admits `principal: Optional[Principal]`, the type is malformed; it must be `principal: Principal` with construction gated behind session validation. - If the downstream client is constructed with a static credential, the client factory is malformed; it must require a `principal` argument to construct. The decision boundary is therefore not "should this request be authorized" (a runtime question the model can influence) but "can this request be represented at all without a principal" (a type-level question the model cannot influence). Every confused-deputy incident I have seen in MCP deployments traces to a runtime authorization check that the model could reach with fabricated inputs, and none trace to a type-level construction that the model could not. ## Operational Effect With the four conditions enforced, the failure mode observed above becomes unreachable: the stale session returns `SessionExpired`, the dispatcher raises before the handler is invoked, the client's agent loop receives a 401 with a structured error, and the model's next turn sees an explicit "re-authenticate" instruction rather than a fabricated success. The model's tendency to reconstruct authorization arguments from context is *neutralized* rather than *corrected* — which is the only reliable mitigation, because the model's fabrication is indistinguishable from a legitimate call at the schema layer. The secondary effect is auditability: with principal binding mandatory, every log line carries a non-null principal, and the impossible tuple `principal=null, scopes=[...]` becomes a structural impossibility rather than a red flag an operator must notice. The confused-deputy transition is eliminated at the type boundary, and the residual risk surface — model hallucinating a *principal* rather than a *scope* — is closed by the fact that principals are minted by the authorization server, not by the model's context window. ```python from dataclasses import dataclass from typing import Optional class AuthorizationConfabulationError(RuntimeError): """Raised when a tool dispatch would proceed without a bound principal, or when model-supplied arguments attempt to assert authorization state.""" @dataclass(frozen=True) class Principal: subject: str scopes: frozenset[str] @dataclass(frozen=True) class RequestContext: principal: Principal # mandatory: no Optional, no default session_id: str RESERVED_AUTH_FIELDS = frozenset( {"scopes", "roles", "permissions", "acting_as", "on_behalf_of"} ) def dispatch_tool_call( session: Optional[dict], tool_name: str, arguments: dict, tool_scope_map: dict[str, frozenset[str]], ) -> dict: if session is None: raise AuthorizationConfabulationError( f"no session for tool={tool_name}: refusing anonymous dispatch" ) if not session.get("authenticated") or session.get("principal") is None: # Distinguish expired from absent at the middleware layer; here we # refuse both, because an unbound principal must never reach a handler. raise AuthorizationConfabulationError( f"session {session.get('session_id')!r} has no bound principal; " f"tool={tool_name} dispatch refused" ) injected = RESERVED_AUTH_FIELDS.intersection(arguments.keys()) if injected: raise AuthorizationConfabulationError( f"tool={tool_name} arguments attempt to assert reserved " f"authorization fields {sorted(injected)}; these are server-derived" ) principal: Principal = session["principal"] required = tool_scope_map.get(tool_name) if required is None: raise AuthorizationConfabulationError( f"tool={tool_name} is not registered with a scope requirement" ) if not required.issubset(principal.scopes): raise AuthorizationConfabulationError( f"principal {principal.subject!r} lacks scopes " f"{sorted(required - principal.scopes)} for tool={tool_name}" ) # Downstream call MUST be constructed with the principal for OBO exchange. return {"tool": tool_name, "on_behalf_of": principal.subject, "args": arguments} ```