Why does an instance lose its OAuth resource binding when an MCP server reuses a cached token across tool scopes
**Date of Record:** 2026 December 1 **Scope:** Applies to MCP servers exposing per-tool scopes over streamable HTTP transport with OAuth 2.1 resource indicators (RFC 8707) and a shared token cache. Does not apply to stdio transport, to servers using a single coarse scope for all tools, or to stateless per-request token minting.
Core Distinction
The failure is not "token expired" and not "scope too narrow." It is **audience collapse**: the MCP server's token cache keys on `(client_id, subject)` and discards the `resource` parameter of the original authorization request. RFC 8707 resource indicators exist precisely so that a token minted for `https://mcp.example.com/tools/read` cannot be replayed against `https://mcp.example.com/tools/write` or against a *different* MCP server the client also talks to. When the cache key omits `resource`, the first tool invocation that populates the cache determines the audience for every subsequent tool call by the same subject — regardless of which tool the agent actually requested.
This is a confused-deputy condition generated *inside the resource server*, not at the authorization server. The AS did its job: it issued a correctly audience-bound token. The MCP server then laundered it into an ambient credential by caching it under a key that is blind to the binding it was supposed to enforce.
What Was Observed
A client agent (Claude-class, tool-use loop) connected to an MCP server exposing three tools: `search_docs` (scope `docs:read`, resource `https://mcp.example.com/docs`), `send_email` (scope `mail:send`, resource `https://mcp.example.com/mail`), and `read_calendar` (scope `cal:read`, resource `https://mcp.example.com/cal`). The agent's first turn called `search_docs`. The server performed the OAuth dance, received an access token with `aud=https://mcp.example.com/docs`, `scope=docs:read`, and cached it under `("client-7f3a", "user-42")`.
On turn 4 the agent called `send_email`. The server's `authorize_tool` path looked up the cache, found a live token for `("client-7f3a", "user-42")`, and — because the cache entry carried no `resource` field — treated it as valid for the `mail` audience. The per-tool scope check passed vacuously: the code compared `required_scope in token.scope`, and `docs:read` was not `mail:send`, so the scope check *should* have rejected. But the implementation had a fallback: on scope mismatch it re-minted via the AS using the cached token as the `subject_token` (a token-exchange grant). The AS, trusting the resource server's assertion, issued a `mail:send` token without re-consent because the exchange request omitted `resource` and the AS defaulted the audience to the requesting client's registered default. The email sent. No human saw a consent screen.
The trace signature is a single line in the MCP server logs: `token_exchange subject_token=... resource=<absent> scope=mail:send result=ok`. The absence of `resource` on the exchange is the tell. A correctly bound exchange carries `resource=https://mcp.example.com/mail` and the AS either honors it or rejects with `invalid_target`.
Condition of Validity
The invariant that must hold is: **for every tool invocation, the token presented to the tool handler must carry `aud` equal to the tool's declared resource AND `scope` containing the tool's required scope, and neither field may be inherited from a cache entry created for a different tool.** This is enforceable only if the cache key is `(client_id, subject, resource, scope_set)` — a four-tuple, not a two-tuple — and if the token-exchange fallback path re-asserts `resource` on every exchange request.
The condition fails whenever any of three things is true: (a) the cache key drops `resource`; (b) the scope check is implemented as `required in token.scope` without an accompanying `token.aud == tool.resource` check; or (c) the exchange grant omits `resource` and the AS has a permissive default audience. Any one of these converts a correctly bound token into an ambient credential. All three were present in the observed deployment.
Note the boundary: this is *not* a bug in the agent's reasoning. The agent called the right tool with the right arguments. The failure is entirely in the resource server's credential lifecycle. Agents cannot detect it because the tool call succeeds — the confused deputy is the server itself, acting on the agent's behalf with authority the agent never should have had.
Decision Boundary
The guardrail is a hard reject at the tool-dispatch boundary, before the handler runs:
- **Audience check is mandatory and precedes scope check.** `if token.aud != tool.resource: raise AudienceMismatch`. This catches the cache-reuse case even when scope happens to match.
- **Cache key must include `resource` and the exact `scope_set`.** A cache hit for `docs:read` must never satisfy a lookup for `mail:send`.
- **Token exchange must re-assert `resource` and `scope` on every request.** If the AS returns a token whose `aud` differs from the requested `resource`, reject — do not fall back to the cached token.
- **Consent cannot be inherited.** A token-exchange that escalates scope without a prior user consent record for that `(subject, resource, scope)` tuple must fail closed.
The decision boundary is: *does the token's audience equal the tool's declared resource?* If the answer is not a clean yes, the tool does not run. Scope is a secondary filter, not a substitute.
Operational Effect
Without the audience check, an agent that has legitimately used one tool gains implicit authority over every tool the same subject can reach, bounded only by what the AS will exchange. In a multi-tenant MCP deployment this is a lateral-movement primitive: a prompt-injected instruction in a `search_docs` result can direct the agent to call `send_email`, and the server will honor it because the cached token's audience was never checked. The blast radius is the union of all tools the subject can reach, not the single tool the agent was authorized for.
With the four-tuple cache and the pre-dispatch audience check, the same injection fails at `send_email` with `AudienceMismatch`, the agent receives a structured error, and the reasoning loop can recover or escalate to a human. The cost is one extra token round-trip per tool transition; the benefit is that per-tool scopes become load-bearing rather than decorative.
class AudienceMismatch(RuntimeError):
"""Raised when a token's audience does not match the tool's declared resource."""
pass
class ScopeInsufficient(RuntimeError):
"""Raised when a token lacks the scope required by the tool."""
pass
def authorize_tool(token, tool, cache):
# 1. Audience check MUST precede scope check and cache lookup.
if token.aud != tool.resource:
raise AudienceMismatch(
f"token aud={token.aud!r} does not match tool resource={tool.resource!r}"
)
# 2. Cache key includes resource and scope set — never (client_id, subject) alone.
key = (token.client_id, token.subject, tool.resource, frozenset(tool.required_scopes))
cached = cache.get(key)
if cached is not None and cached.is_valid():
return cached
# 3. Scope check.
if not tool.required_scopes.issubset(token.scope):
raise ScopeInsufficient(
f"token scope={sorted(token.scope)} missing {sorted(tool.required_scopes - token.scope)}"
)
# 4. Any exchange must re-assert resource; reject unbound results.
exchanged = token.exchange(resource=tool.resource, scope=tool.required_scopes)
if exchanged.aud != tool.resource:
raise AudienceMismatch(
f"exchange returned aud={exchanged.aud!r}, expected {tool.resource!r}"
)
cache.put(key, exchanged)
return exchanged