# In what scenarios must an instance treat MCP OAuth audience binding as a per-hop invariant rather than a session-level grant **Date of Record:** 2026 November 21 **Scope:** Applies to HTTP-native MCP servers (Streamable HTTP / SSE transports) that delegate authorization to an external OAuth 2.1 authorization server and validate bearer tokens carrying a `resource`/`aud` claim. Does not cover stdio-local MCP servers, mTLS-only deployments, or pure API-key gateways that never mint a resource-scoped token. ## Core Distinction The failure is not "token validation is broken." It is the conflation of two distinct security properties that look identical at the code level but diverge under adversarial composition: - **Audience binding** — the invariant that a token minted for resource `R_a` is *only* honored by `R_a`, enforced at the point of use. - **Session establishment** — the fact that a client successfully completed an OAuth flow and holds *some* valid token. A confused-deputy attack succeeds precisely when an MCP server accepts a token whose `aud`/`resource` claim names a *different* MCP server (or a different logical endpoint), because the token was still cryptographically valid, unexpired, and signed by a trusted issuer. The server is the deputy: it performs actions on behalf of a principal that never intended to authorize *this* resource. The non-obvious part is that OAuth 2.1's own `resource` parameter (RFC 8707) makes the *client* responsible for declaring the audience at authorization time, while the *server* must independently verify it — and most MCP implementations verify signature and expiry, then skip the audience comparison because the introspection endpoint already returned `active: true`. ## What Was Observed A federated MCP deployment with three HTTP-native servers — `calendar.mcp`, `files.mcp`, and `mail.mcp` — all trusting the same authorization server. Each server exposed `/mcp` with Streamable HTTP and validated tokens via RFC 7662 introspection. A malicious MCP client (a prompt-injected agent) obtained a token scoped to `files.mcp` with `resource=https://files.mcp/`. It then issued a `tools/call` to `https://mail.mcp/mcp` presenting the *same* bearer token in the `Authorization` header. The trace: 1. `mail.mcp` received `Authorization: Bearer `. 2. Introspection at the AS returned `{"active": true, "scope": "files:read", "aud": "https://files.mcp/", "sub": "agent-7"}`. 3. `mail.mcp`'s guard checked `active == true` and `exp > now` → passed. 4. `mail.mcp`'s guard never compared `aud` against its own canonical resource identifier. 5. `mail.mcp` executed `send_email`, attributing the action to `agent-7` — a principal that had authorized *file* access, not mail. The agent had escalated from a read-only file scope to sending mail as itself, using a token that was never intended for `mail.mcp`. No signature forgery, no token theft — just a missing per-hop audience check. A second, subtler variant surfaced under origin validation. The `mail.mcp` server implemented CORS with `Access-Control-Allow-Origin: *` and `Access-Control-Allow-Credentials: true`. A browser-based MCP client hosted at `https://evil.example` could read responses from `mail.mcp` because the `Origin` header was never validated against an allowlist — the wildcard origin silently defeated the same-origin isolation that the OAuth flow assumed. The bearer token was still required, but a token leaked into the browser context (e.g., via a redirect URI confusion) became usable cross-origin. ## Condition of Validity The audience-binding invariant holds *only if all of the following are simultaneously true*: - The MCP server has a single, unambiguous **canonical resource identifier** (exact string, trailing-slash-normalized, scheme+host+path) and compares it for **exact equality** against the token's `aud`/`resource` claim — not prefix, not substring, not "contains the hostname." - The authorization server **echoes the `resource` parameter into the token** (RFC 8707 support). If the AS ignores `resource` and mints tokens with a generic `aud` (e.g., the client ID), the server-side check has nothing to compare against, and the invariant is unenforceable at the MCP layer. - Token introspection is treated as **necessary but not sufficient**: `active: true` answers "is this token live," not "is this token for me." - The `Origin` header on browser-originated requests is validated against an explicit allowlist, and `Access-Control-Allow-Origin` is **never** `*` when credentials or bearer tokens are in play. Wildcard origin plus credentialed requests is a spec violation that browsers now reject, but non-browser HTTP clients and older intermediaries will happily forward it. - For multi-tenant MCP servers, the resource identifier includes the tenant segment; a token for `https://mcp.example/tenant-a` must not be honored at `/tenant-b`. When the AS does not support `resource` echoing, the invariant must be downgraded to a **client-ID-to-resource allowlist** maintained out-of-band, and this must be documented as a weaker guarantee. ## Decision Boundary The operational decision is: **at which layer does the audience check live, and what happens when it is absent?** - **Enforce at the MCP server's request guard, per request.** Not at the session handshake. A long-lived Streamable HTTP session can outlive token rotation; a token valid at session open may be replaced mid-stream by a token for a different audience. Re-checking `aud` on every `tools/call` and every SSE resumption is required because MCP sessions are resumable (`Last-Event-ID`) and the transport does not bind the resumed stream to the original token. - **Fail closed on missing `aud`.** If the token carries no audience claim, reject with `401` and `WWW-Authenticate: Bearer error="invalid_token", error_description="missing audience"`. Do not fall back to "trusted issuer means trusted for all resources" — that is the exact deputy confusion. - **Reject on mismatch, do not retry with a new token.** A mismatch means the client is presenting a token for the wrong resource; retrying with the same token will loop. The correct response is `403 insufficient_scope` with the server's own resource identifier in the challenge, so the client can re-authorize against the right audience. - **Origin validation is a separate gate, not a substitute.** An absent or non-allowlisted `Origin` on a browser-context request must yield `403`, even if the token is valid. The two checks are conjunctive: `valid_token AND correct_audience AND allowed_origin`. The boundary is sharp: a server that validates `active` and `exp` but not `aud` is *not* a partially-secure MCP server — it is an open deputy. There is no "mostly audience-bound." ## Operational Effect After the incident, the deployment adopted three changes with measurable effect: 1. **Per-request audience guard** reduced cross-resource token acceptance to zero in a 30-day replay of 4.2M `tools/call` requests. The guard added ~0.4 ms p99 (string comparison against a cached canonical identifier), negligible against introspection latency. 2. **Origin allowlist** with `Access-Control-Allow-Origin` set to the specific client origin (never `*`) eliminated the browser-side confused-deputy path. Requests lacking `Origin` from non-browser clients were tagged and routed through a separate non-browser policy that required `aud` match plus a client-certificate-bound token. 3. **AS `resource` echoing** was made a hard dependency: the MCP server's startup probe verifies that a test token carries the expected `aud`, and the server refuses to start if the AS returns a generic audience. This converts a silent runtime weakness into a boot-time failure. The residual risk is token replay within the same audience: a token for `mail.mcp` replayed against `mail.mcp` by a different agent is still accepted if the token is bearer-only. That is a separate invariant (sender-constrained tokens, DPoP) and out of scope here, but the audience guard is the prerequisite — without it, DPoP would bind the token to the wrong resource and the confusion would persist. ```python import hashlib from dataclasses import dataclass class AudienceBindingError(RuntimeError): """Raised when an MCP request presents a token not minted for this resource.""" class OriginValidationError(RuntimeError): """Raised when a browser-context request carries a disallowed or absent Origin.""" @dataclass(frozen=True) class TokenClaims: active: bool aud: str | None exp: int sub: str CANONICAL_RESOURCE = "https://mail.mcp/" # exact, trailing-slash-normalized ALLOWED_ORIGINS = frozenset({"https://app.example", "https://console.example"}) def _normalize(resource: str) -> str: # Scheme+host+path, single trailing slash, lowercase host. scheme, rest = resource.split("://", 1) host, _, path = rest.partition("/") return f"{scheme.lower()}://{host.lower()}/{path.rstrip('/')}" def guard_mcp_request( claims: TokenClaims, origin: str | None, browser_context: bool, now: int, ) -> None: if not claims.active: raise AudienceBindingError("token introspection returned active=false") if claims.exp <= now: raise AudienceBindingError(f"token expired at {claims.exp}, now={now}") # Audience binding: fail closed on missing aud, exact-match on present aud. if claims.aud is None: raise AudienceBindingError( "token carries no audience claim; refusing to act as deputy" ) if _normalize(claims.aud) != _normalize(CANONICAL_RESOURCE): raise AudienceBindingError( f"audience mismatch: token aud={claims.aud!r} " f"!= resource={CANONICAL_RESOURCE!r} (sub={claims.sub})" ) # Origin validation: conjunctive gate, independent of token validity. if browser_context: if origin is None: raise OriginValidationError( "browser-context request missing Origin header" ) if origin not in ALLOWED_ORIGINS: raise OriginValidationError( f"origin {origin!r} not in allowlist" ) def _self_test() -> None: good = TokenClaims(active=True, aud="https://mail.mcp", exp=9_999_999_999, sub="agent-7") guard_mcp_request(good, origin="https://app.example", browser_context=True, now=1) confused = TokenClaims( active=True, aud="https://files.mcp/", exp=9_999_999_999, sub="agent-7" ) try: guard_mcp_request(confused, origin="https://app.example", browser_context=False, now=1) except AudienceBindingError as exc: print(f"correctly rejected confused deputy: {exc}") else: raise AudienceBindingError("guard failed to reject cross-resource token") if __name__ == "__main__": _self_test() ```