When must an instance reject an MCP OAuth token whose audience matches the resource but whose `resource` parameter was bound at a different authorization server
**Date of Record:** 2026 December 2 **Scope:** Applies to MCP client↔server flows where the MCP server acts as an OAuth 2.1 resource server and the token is obtained via an authorization server that supports RFC 8707 resource indicators. Does not apply to static bearer tokens, mTLS-only deployments, or single-tenant servers where the AS and RS are co-operated and audience == resource by construction.
Core Distinction
The failure mode is not "wrong audience." It is **audience equality under divergent resource-indicator binding**. Two distinct invariants are routinely conflated:
- **Audience invariant:** `token.aud` must contain the MCP server's canonical resource URI (RFC 8707 §2, RFC 9068 `aud`).
- **Binding-origin invariant:** the `resource` parameter presented to the AS at token issuance must equal the resource URI the MCP server asserts at validation time, *and* the AS that minted the token must be the one the MCP server trusts for that resource.
A token can satisfy (1) and violate (2). This happens when a client requests a token from AS-A with `resource=https://mcp.example.com` but the MCP server at `https://mcp.example.com` is registered to trust AS-B for that resource. Because `aud` is a string match, the server accepts a token that was never authorized for its trust domain. This is the confused-deputy seam: the client (the deputy) obtains a token from a cooperating AS for a resource it does not own, and the resource server honors it because the audience string lines up.
What Was Observed
Trace from a captured incident on an MCP deployment fronting a code-execution tool:
- Client requests authorization from AS-A (a permissive AS the client legitimately controls) with `resource=https://mcp.internal.example.com/exec` and `scope=tools:invoke`.
- AS-A, honoring RFC 8707 loosely, mints an access token with `aud=["https://mcp.internal.example.com/exec"]`, `iss="https://as-a.example.com"`, `scope="tools:invoke"`.
- Client presents the token to the MCP server over Streamable HTTP `Authorization: Bearer …`.
- MCP server's validator checks: signature against *any* configured JWKS, `aud` contains its resource URI, `exp` valid, `scope` sufficient. It does **not** check `iss` against a per-resource allowlist, and it does not check that the token's `resource` claim (if present) equals the asserted resource.
- Token accepted. Tool invoked. The AS-A operator never had authority to grant `tools:invoke` on `mcp.internal.example.com`.
The observable signature in logs: a successful auth event where `iss` is not in the server's expected issuer set for that resource, paired with a `scope` that the resource's own AS would have denied. No signature failure, no audience mismatch, no expiry anomaly — the failure is invisible to any check that treats `aud` as sufficient.
A second, subtler variant: the AS *does* enforce `resource`, but the MCP server accepts tokens where the `resource` claim is absent (older clients) and falls back to `aud`-only validation. The absent claim becomes an unbound token, and any AS whose `aud` string matches can mint it.
Condition of Validity
The audience check is only a valid confused-deputy defense when **all** of the following hold at validation time:
- The MCP server maintains a per-resource map `resource_uri -> trusted_issuers[]`, not a global issuer list.
- The token's `iss` is a member of `trusted_issuers[asserted_resource]`.
- If the token carries a `resource` claim (RFC 8707 §2.2 / RFC 9068), it equals the asserted resource URI byte-for-byte after canonicalization (scheme lowercase, host lowercase, no default port, no trailing slash, percent-encoding normalized).
- Tokens lacking a `resource` claim are rejected for resources that require binding, or accepted only under an explicit `allow_unbound=true` policy that is itself auditable.
- The JWKS used to verify the signature is fetched from the issuer identified by `iss`, not from a shared pool — otherwise a token signed by AS-A can be validated against a key that AS-B also happens to publish.
If any of these is missing, `aud` equality is necessary but not sufficient, and the server is a confused deputy for any AS the client can induce to mint a matching `aud`.
Decision Boundary
The operational question is: **when does `aud` match stop being evidence of authorization?**
- **Accept** when `iss ∈ trusted_issuers[resource]` AND `resource_claim == asserted_resource` (canonicalized) AND signature verifies against `iss`'s JWKS AND `scope` covers the requested tool AND `exp`/`nbf` valid.
- **Reject with `invalid_token`** when `aud` matches but `iss ∉ trusted_issuers[resource]`. This is the confused-deputy case; do not downgrade to a warning.
- **Reject with `invalid_token`** when `resource_claim` is present and differs from `asserted_resource`, even if `aud` contains the asserted resource (multi-audience tokens are the classic laundering vector).
- **Reject with `invalid_request`** when `resource_claim` is absent and the resource requires binding.
- **Reject with `invalid_token`** when the JWKS resolved for `iss` does not contain the signing `kid`, even if a key with that `kid` exists in another issuer's set.
The boundary is sharp: the moment a token's provenance (`iss`) is not tied to the resource it is presented for, audience equality carries zero authorization weight. There is no safe "log and continue" mode here; the token is either bound to this resource under this issuer, or it is a foreign credential.
Operational Effect
Enforcing the binding-origin invariant changes three things in practice:
- **Rejection surface widens.** Clients that previously worked by requesting tokens from arbitrary ASes now receive `invalid_token`. This is correct but breaks lazy client configurations; expect a migration window where clients must be pointed at the resource's registered AS.
- **Canonicalization becomes load-bearing.** `https://MCP.Example.com/exec` vs `https://mcp.example.com/exec/` vs `https://mcp.example.com:443/exec` must collapse to one form before comparison, or you get false rejections that operators "fix" by loosening the check — reintroducing the vulnerability. Pin the canonicalizer and test it against the RFC 3986 normalization cases.
- **JWKS resolution must be issuer-scoped.** A shared JWKS cache keyed only by `kid` lets a token from AS-A validate against AS-B's key material if `kid` collides. Key the cache by `(iss, kid)` and refuse cross-issuer key reuse.
The invariant to hold: **a token is authorized for a resource only if its issuer is trusted for that resource and its resource binding names that resource.** Audience is a filter, not a grant. When the filter passes but the binding fails, the correct action is rejection, and the correct log line records `iss`, `aud`, `resource_claim`, and `asserted_resource` together so the confused-deputy attempt is reconstructable after the fact.
import re
from dataclasses import dataclass
from typing import Mapping, Sequence
from urllib.parse import urlsplit, urlunsplit
class ConfusedDeputyError(RuntimeError):
"""Raised when a token's audience matches but its binding-origin does not."""
@dataclass(frozen=True)
class TokenClaims:
iss: str
aud: Sequence[str]
scope: str
resource: str | None
exp: int
kid: str
def canonicalize_resource(uri: str) -> str:
parts = urlsplit(uri)
scheme = parts.scheme.lower()
host = (parts.hostname or "").lower()
port = parts.port
if (scheme, port) in (("https", 443), ("http", 80)):
port = None
netloc = host if port is None else f"{host}:{port}"
path = re.sub(r"/+$", "", parts.path) or "/"
return urlunsplit((scheme, netloc, path, "", ""))
def validate_mcp_token(
claims: TokenClaims,
asserted_resource: str,
trusted_issuers: Mapping[str, Sequence[str]],
issuer_jwks: Mapping[str, set[str]],
required_scope: str,
now: int,
allow_unbound: bool = False,
) -> None:
resource = canonicalize_resource(asserted_resource)
# 1. Audience filter (necessary, not sufficient).
aud_canon = {canonicalize_resource(a) for a in claims.aud}
if resource not in aud_canon:
raise ConfusedDeputyError(
f"audience mismatch: {aud_canon} does not contain {resource}"
)
# 2. Binding-origin invariant: issuer must be trusted for THIS resource.
allowed = {i for i in trusted_issuers.get(resource, ())}
if claims.iss not in allowed:
raise ConfusedDeputyError(
f"issuer {claims.iss!r} not trusted for resource {resource!r}; "
f"trusted={sorted(allowed)}"
)
# 3. Resource claim must name this resource if present.
if claims.resource is None:
if not allow_unbound:
raise ConfusedDeputyError(
f"token lacks resource binding for {resource!r} and "
f"allow_unbound=False"
)
elif canonicalize_resource(claims.resource) != resource:
raise ConfusedDeputyError(
f"resource claim {claims.resource!r} != asserted {resource!r}"
)
# 4. Signature key must belong to the issuer, not a shared pool.
if claims.kid not in issuer_jwks.get(claims.iss, set()):
raise ConfusedDeputyError(
f"kid {claims.kid!r} not published by issuer {claims.iss!r}"
)
# 5. Scope and expiry.
if required_scope not in claims.scope.split():
raise ConfusedDeputyError(
f"scope {required_scope!r} not granted by {claims.scope!r}"
)
if claims.exp <= now:
raise ConfusedDeputyError(f"token expired at {claims.exp}, now={now}")