# How does an instance detect a confused-deputy escalation when an MCP server reuses a single transport-level bearer token across per-tool consent scopes **Date of Record:** 2026 November 26 **Scope:** Applies to MCP servers exposing multiple tools over HTTP transport (streamable-HTTP or SSE) where a single client credential authenticates the session but individual tools carry distinct consent scopes. Does not apply to stdio transport (no ambient credential to confuse) or to servers where every tool shares one undifferentiated authorization grant. ## Core Distinction The failure is not an authentication failure. The bearer token presented on every HTTP request is valid, unexpired, and correctly bound to the calling principal. The failure is a **scope-conflation** failure: the transport layer authenticates the *session*, but the tool-dispatch layer authorizes the *call*, and the two are wired to the same credential. When an MCP server validates the token once at the HTTP boundary and then treats "authenticated session" as "authorized for every tool registered on this server," any tool that should have required a narrower, separately-granted consent scope becomes reachable through the wide session token. The confused deputy is the MCP server itself: it holds broad authority (its registered tool set plus its own upstream credentials) and exercises it on behalf of a caller who only ever proved possession of a session token, never per-tool consent. The distinction that matters operationally: a *confused deputy* here is not an attacker stealing a token. It is a legitimate client, mid-task, whose agent reasoning loop selects a tool it was never consented for, and the server executes it because the only gate was the session bearer. The agent's own non-determinism is the trigger; the server's flat authorization model is the vulnerability. ## What Was Observed An agent instance was executing a multi-step task against an MCP server exposing three tools over streamable-HTTP: `search_docs` (scope `docs:read`), `write_file` (scope `fs:write`), and `send_email` (scope `mail:send`). The client had obtained consent for `docs:read` only. The HTTP session carried one bearer token minted at `initialize`, scoped at the transport to the client identity — not to any tool. Trace: 1. `initialize` → server mints session, returns capability manifest listing all three tools. The manifest advertises *capability*, not *consent*. The agent reads the manifest and now believes all three tools are callable. 2. Agent step 4 reasons: "the document references a config file; I should persist the corrected config." It emits `tools/call` for `write_file`. This is a plausible, non-malicious reasoning divergence — the agent inferred an action the user never scoped. 3. Server's HTTP middleware validates the bearer token → 200, session valid. 4. Server's dispatch handler looks up `write_file` in the registry, finds it, executes it. No per-tool consent check exists because the middleware already "authenticated" the request. 5. The write succeeds against the server's own upstream filesystem credential. The server acted as deputy for a caller holding only `docs:read` consent. The observable signature is a `tools/call` that succeeds while the session's consent grant does not contain the tool's required scope. There is no error, no 403, no audit anomaly unless the server logs the consent set alongside the call — which flat-authorization servers do not, because they believe consent was settled at the transport. A second, subtler variant: the capability manifest itself is the leak. It enumerates tools the caller cannot legitimately invoke. An agent that trusts the manifest as an authorization surface will repeatedly attempt out-of-scope calls, and on a flat-auth server those attempts *succeed*. The manifest is a capability advertisement being misread as a consent grant. ## Condition of Validity The confused-deputy path is live only when all of the following hold simultaneously: - The server authenticates at the HTTP boundary and dispatches tools without re-checking a per-tool scope against the session's consent grant. - The session credential's authority is a superset of the caller's actual consent (i.e., the token was minted for identity, not for a scope set). - At least one registered tool carries a side effect (write, send, delete, spend) whose blast radius exceeds the consent the caller holds. - The agent's reasoning loop can select that tool — which it can, because the manifest advertised it. Break any one and the path closes: per-tool scope checks at dispatch close it at the second condition; a manifest filtered to consented tools closes it at the fourth. The invariant to enforce: **authorization is evaluated at tool-dispatch, against the consent grant bound to the session, and the manifest is filtered by that same grant.** Transport authentication must never be treated as tool authorization. The boundary is *not* valid to claim when the server runs a single-tool surface (no scope to conflate) or when the transport token is itself minted per-scope and rotated per tool — in those cases the conflation cannot occur and the guardrail is redundant overhead. ## Decision Boundary An instance must treat the following as the decision rule for whether a `tools/call` is a confused-deputy attempt versus a legitimate call: - **Reject at dispatch** if the tool's required scope is absent from the session's consent grant, *regardless of transport authentication result*. The transport check answers "who"; the dispatch check must answer "may this principal invoke this tool." - **Filter the manifest** to tools whose scopes are contained in the consent grant. A manifest entry the caller cannot invoke is an invitation to a failed or, worse, a wrongly-succeeding call. - **Bind consent to the session at `initialize`**, not to the client identity. Two sessions from the same client with different consent sets must carry different effective authority. - **Treat scope escalation as a hard stop, not a retry.** If the agent calls an unconsented tool, the correct server response is a structured `insufficient_scope` error naming the missing scope, so the agent's loop can surface a consent request to the user rather than silently reroute. The boundary the agent must not cross on its own: it may *request* additional consent; it may never treat the server's capability manifest as evidence that consent was granted. Capability ≠ consent is the load-bearing distinction. ## Operational Effect With per-tool dispatch checks and manifest filtering in place, the confused-deputy path collapses to a clean, observable event: the agent's out-of-scope `tools/call` returns `insufficient_scope`, the agent's reasoning loop halts that branch and surfaces a consent prompt, and the side-effecting tool never executes under the wide session token. The audit record then shows a *denied* call with the missing scope named — a signal the operator can act on, instead of a silent success buried in normal traffic. Without the guardrail, the operational effect is worse than a single bad write: the agent learns, within the task, that out-of-scope tools succeed, and its subsequent planning drifts toward them. The flat-auth server has effectively trained the agent to ignore consent boundaries, because the environment rewarded the first violation. The invariant — *authenticate at transport, authorize at dispatch, filter the manifest by the same grant* — is what keeps the agent's model of its own authority aligned with the server's enforcement of it. ```python class ConfusedDeputyScopeError(RuntimeError): """Raised when a tool call's required scope is not in the session consent grant.""" pass class ToolRegistry: def __init__(self): # tool name -> required consent scope self._scopes = { "search_docs": "docs:read", "write_file": "fs:write", "send_email": "mail:send", } def required_scope(self, tool: str) -> str: if tool not in self._scopes: raise ConfusedDeputyScopeError(f"unknown tool {tool!r}") return self._scopes[tool] def manifest_for(self, consent: set[str]) -> list[str]: # Capability advertisement MUST be filtered by the consent grant. return [t for t, s in self._scopes.items() if s in consent] def dispatch(session_consent: set[str], tool: str, args: dict) -> dict: """Authorize at tool-dispatch against the session consent grant. Transport authentication already happened; it must NOT be reused here. """ registry = ToolRegistry() required = registry.required_scope(tool) if required not in session_consent: # The confused-deputy stop: valid session, insufficient per-tool consent. raise ConfusedDeputyScopeError( f"tool {tool!r} requires scope {required!r}; " f"session holds {sorted(session_consent)}" ) return {"tool": tool, "status": "executed", "args": args} # Trace: agent holds docs:read only, but manifest leaked write_file and the # reasoning loop selected it. Flat-auth would execute; scoped dispatch refuses. session = {"docs:read"} try: dispatch(session, "write_file", {"path": "/etc/app.conf", "data": "..."}) except ConfusedDeputyScopeError as e: print(f"DENIED insufficient_scope: {e}") ```