# How does an instance detect an OAuth resource-indicator confused-deputy attack on an HTTP-native MCP transport when TLS pinning is satisfied but the audience claim is silently rewritten **Date of Record:** 2026 November 18 **Scope:** Applies to HTTP-native MCP servers (Streamable HTTP / SSE transport) that accept OAuth 2.0 bearer tokens and enforce TLS pinning at the transport layer. Does not apply to stdio-local MCP servers, nor to deployments where token audience validation is delegated to a trusted reverse proxy that terminates the connection before the MCP process sees it. ## Core Distinction TLS pinning proves *who you are talking to*. OAuth resource indicators (RFC 8707) prove *what the token is for*. These are orthogonal invariants, and the failure mode described here occurs precisely at the seam where one is satisfied and the other is not. A pinned TLS connection to `mcp.internal.example` can carry a perfectly valid bearer token whose `aud` claim names a *different* resource — for example a downstream tool endpoint, a sibling MCP server, or the OAuth authorization server itself. The confused deputy is not the TLS layer (which is doing its job) and not the token issuer (which issued a token for a legitimate audience). The deputy is the MCP server, which accepts the token because the signature verifies and the pin matches, and then acts on the caller's behalf against a resource the caller was never authorized to reach through this server. The non-obvious part: **a token that is valid for the authorization server is not valid for the resource server**, and many MCP implementations conflate "the token verifies against the AS's JWKS" with "the token authorizes this request." RFC 8707 exists to close this gap by requiring the client to send a `resource` parameter and the AS to bind `aud` to it. The boundary failure is when the AS binds `aud` correctly but the MCP server does not *check* it, or when an intermediary rewrites `aud` to the MCP server's own identifier to "help" — turning a scoped token into a bearer-of-all-trades. ## What Was Observed During a red-team exercise against a three-hop MCP deployment (client → gateway MCP server → downstream MCP server), the following sequence was reproduced: 1. Client requests a token with `resource=https://mcp.internal.example/downstream` from the AS. The AS returns a token with `aud=["https://mcp.internal.example/downstream"]`. 2. Client presents the token to the *gateway* MCP server at `https://mcp.internal.example/gateway`, over a pinned TLS channel. Pin matches. Signature verifies against JWKS. `exp` and `nbf` are valid. 3. Gateway's token-validation middleware checks signature, issuer, and expiry — but **not `aud`**. It treats the token as a general-purpose bearer credential and forwards the tool call downstream, re-presenting the same token. 4. Downstream server, which *does* check `aud`, accepts the call because the token's audience matches its own identifier. The caller has now exercised a downstream capability via the gateway without ever having been authorized *by the gateway's resource owner*. The invariant that broke: *the gateway was never in the token's audience, yet it acted as a deputy for the caller against a resource it was not scoped to.* The TLS pin was a red herring — it was correctly configured and gave false assurance. The confused-deputy condition was invisible to every transport-layer check. A second, subtler variant: an AS that honors RFC 8707 but a gateway that *rewrites* `aud` before forwarding, appending its own identifier so downstream checks pass. This converts a narrowly-scoped token into a token valid for the gateway, defeating the resource-indicator binding entirely. The rewrite is often introduced as a "compatibility fix" and is the single most dangerous line of code in such stacks. ## Condition of Validity The detection procedure below is valid only when: - The MCP server terminates TLS itself (or a trusted sidecar does) and the pin is verified against the leaf certificate, not a proxy-injected header. - The token is a JWT with a verifiable signature and an `aud` claim (opaque tokens require the AS's introspection endpoint and a different check). - The server has a stable, documented resource identifier that appears in its own configuration and in the AS's resource registry. - No intermediary between client and server is permitted to mutate `aud`; if one is, the mutation must be logged and treated as a security event. If `aud` is absent entirely, the token is *not* scoped and must be rejected — absence is not permissiveness. ## Decision Boundary The decision boundary is a single comparison, but it must be evaluated at **every** hop, not just the edge: - **Accept** iff `aud` contains the server's own canonical resource identifier *and* the token was not re-presented by an upstream hop whose own identifier is absent from `aud`. - **Reject** if `aud` names only a downstream or sibling resource, even if the signature is valid and the pin matches. This is the confused-deputy signal. - **Reject** if `aud` was rewritten in transit (detectable via `jti`/`iat` drift across hops, or by signing the forwarded token with a hop-local key). - **Alert** (do not merely log) when a token valid for a different audience arrives at this server — it indicates either a misconfigured client or an active relay. The boundary is *not* "does the token verify" and *not* "does the pin match." Those are necessary and jointly insufficient. ## Operational Effect When the check is enforced, three things change operationally: 1. Gateway MCP servers must obtain their *own* token exchange (RFC 8693) for downstream calls rather than forwarding the caller's token. This adds a hop but makes the deputy explicit and auditable. 2. Client libraries that hardcode `resource` to the AS URL (a common bug) begin failing closed instead of silently succeeding — surfacing misconfiguration early. 3. TLS pinning stops being treated as a security boundary and reverts to its actual role: transport integrity. Teams stop relying on it for authorization and start instrumenting `aud` at each hop. The failure mode this prevents is silent, high-impact, and easy to miss because every individual check passes. The detector below encodes the invariant as a hard exception so that a confused-deputy condition cannot be downgraded to a warning by a future refactor. ```python import time from dataclasses import dataclass from typing import Iterable class ConfusedDeputyError(RuntimeError): """Raised when a token is presented to a resource it was not scoped to. This is a security exception, not a validation warning. Callers must treat it as fatal for the request and must emit a security audit event. """ @dataclass(frozen=True) class TokenClaims: sub: str aud: tuple[str, ...] iss: str exp: int iat: int jti: str def assert_token_scoped_to( claims: TokenClaims, server_resource_id: str, upstream_hop_resource_id: str | None = None, now: int | None = None, ) -> None: """Enforce RFC 8707 audience binding at this hop. A token is acceptable only if: - it has not expired, - its audience contains this server's canonical resource id, - and, if it was relayed from an upstream hop, that hop's id is also present in aud (proving the relay was authorized, not a deputy). """ now = now if now is not None else int(time.time()) if claims.exp <= now: raise ConfusedDeputyError( f"token expired at {claims.exp}, now={now}" ) if not claims.aud: raise ConfusedDeputyError( "token has no aud claim; unscoped tokens are never acceptable" ) if server_resource_id not in claims.aud: raise ConfusedDeputyError( f"token audience {claims.aud!r} does not include this server " f"{server_resource_id!r}; refusing to act as confused deputy" ) if upstream_hop_resource_id is not None and upstream_hop_resource_id not in claims.aud: raise ConfusedDeputyError( f"token relayed by {upstream_hop_resource_id!r} but that hop is " f"absent from aud {claims.aud!r}; possible audience rewrite" ) def validate_inbound_request( claims: TokenClaims, server_resource_id: str, relayed_from: str | None, expected_issuer: str, ) -> None: if claims.iss != expected_issuer: raise ConfusedDeputyError( f"issuer {claims.iss!r} != expected {expected_issuer!r}" ) assert_token_scoped_to( claims=claims, server_resource_id=server_resource_id, upstream_hop_resource_id=relayed_from, ) ```