# When must an instance re-validate an MCP OAuth token audience after a tool-result-driven redirect, and why does the confused-deputy window reopen mid-session? **Date of Record:** 2026 November 21 **Scope:** Applies to HTTP-native MCP tool servers that bind OAuth access tokens to a resource audience (RFC 8707 `resource` parameter) and that can be induced by their own tool *results* to fetch a secondary resource (redirect, pagination link, or sub-resource fetch) on behalf of the calling agent. Does not apply to stdio-transport MCP servers with no network egress, nor to servers that never follow server-provided URLs. ## Core Distinction The confused-deputy defense at the MCP authorization layer is almost always specified as an *ingress* check: verify that the bearer token presented at the HTTP boundary was issued for *this* resource server (audience binding via the `resource` parameter and `aud` claim), and that the token's scopes cover the requested tool. That check is necessary but it is a **single-point** invariant. It does not survive the moment a tool server, acting on instructions embedded in its *own outbound tool result*, follows a URL to a secondary resource and re-attaches credentials. The non-obvious boundary is this: **audience validation is a property of the (token, resource) pair, not of the session.** A token correctly bound to resource A remains a valid, unexpired, correctly-scoped credential when the agent's execution loop hands it a URL pointing at resource B. If the tool server's HTTP client reuses the *session's* credential store rather than re-deriving the audience for the *new* resource, the deputy is confused again — this time by a tool result the agent itself generated, not by the original caller. The defense must be re-evaluated per egress hop, not per session. ## What Was Observed An MCP server exposed a `fetch_document` tool. Ingress authorization was correct: the server validated the bearer token against its own `resource` identifier, confirmed `aud` matched, and checked the `documents:read` scope. The tool returned a document whose body contained a next-page `Link` header and an embedded absolute URL to a sibling service (`billing.internal`) that shared the same OAuth authorization server but had a *different* `resource` audience. The server's tool implementation, written against a generic HTTP client, reused the inbound `Authorization` header for the secondary fetch — a reasonable-looking optimization, since the token was still valid and unexpired. The sibling service validated the token against *its* audience expectations and rejected it — in the observed instance. But in a variant configuration where both services were registered against the same authorization server with an overlapping `aud` list (a common outcome when one team provisions both), the sibling service *accepted* the token. The agent's `fetch_document` call had thereby caused a `billing.internal` read using a credential minted for `documents.internal`. That is a textbook confused-deputy escalation — but triggered not by a malicious caller and not by prompt injection into the *prompt*, rather by **content in the tool result that the agent's own loop followed**. The failure trace: 1. Ingress: token `T` validated for `resource=https://documents.internal`, `aud=["documents.internal"]`, scope `documents:read`. Pass. 2. Tool executes, returns body containing `https://billing.internal/invoices?cursor=...`. 3. Agent reasoning loop (or the tool server's own pagination handler) issues a follow-up fetch to that URL. 4. Credential resolution at step 3 consults the *session* credential, not the *request* audience. `T` is re-attached. 5. Sibling service validates `T`; because its `aud` expectation overlaps, it accepts. Scope `documents:read` is not checked against `billing:read` because the sibling maps scopes loosely. 6. Result: cross-resource read with a token whose audience was never `billing.internal`. The window that reopened is the interval between "token validated at ingress" and "token re-attached at egress." Nothing in the standard ingress check closes it. ## Condition of Validity The re-validation invariant holds — and the failure is bounded — only under the following conjunction: - **Audience is re-derived, not inherited.** Every outbound HTTP request from a tool server to a URL that did not come from the *original* client request must compute the target resource's audience and either (a) obtain a token bound to that audience via the authorization server's token exchange (RFC 8693) or resource-scoped issuance, or (b) refuse the egress. Reusing the inbound bearer token is only valid when the egress URL's origin is identical to the ingress resource identifier *and* the token's `aud` was scoped to exactly that origin. - **Tool-result URLs are treated as untrusted input.** A URL appearing in a document body, pagination link, or model-generated follow-up is data, not a capability grant. It must pass the same audience check as a URL supplied by the original caller. - **Scope is checked at egress, not only ingress.** The token's scopes must cover the *target* operation; `documents:read` does not authorize `billing:read` even if the token is otherwise accepted. - **The authorization server does not over-broaden `aud`.** If two resources share an `aud` entry, the audience check degenerates to a no-op between them. This is an AS-configuration invariant the resource server cannot enforce unilaterally and must assume is violated. When any of these fails, the ingress check provides no protection against the tool-result-driven egress. ## Decision Boundary The operational decision reduces to a single predicate evaluated at every egress hop, not at session start: ``` allow_egress(target_url, token) := origin(target_url) == token.resource_origin AND token.aud contains origin(target_url) AND token.scopes ⊇ required_scopes(target_url.operation) AND target_url ∈ egress_allowlist(session) ``` If the predicate is false, the correct action is **not** to fall back to the session token and **not** to silently drop the fetch. It is to raise a hard error that halts the tool call, because a silent drop causes the agent to reason over a truncated result and hallucinate the missing content — converting an authorization failure into a reasoning divergence. The boundary is: *re-derive or refuse; never inherit.* A subtle corollary: the allowlist must be established at *session establishment* from the client's declared resource, not extended by tool results. If the agent legitimately needs `billing.internal`, that must be a distinct tool call with its own token exchange, visible to the authorization server as a separate grant — not a side effect of reading a document. ## Operational Effect Enforcing per-egress audience re-derivation converts a silent, hard-to-audit cross-resource read into an explicit, logged refusal. The observable effects: - **Latency and token churn.** Each egress hop that crosses an origin boundary incurs a token exchange round-trip. Servers that previously did one fetch now do one fetch plus one exchange. This is the cost of closing the window; it is not optional. - **Agent-visible failures replace agent-visible successes.** A pagination link to a sibling service now fails loudly. The agent's loop must handle the error as a terminal condition for that tool call and surface it, rather than proceeding with partial data. - **Audit becomes per-hop.** The authorization log now records the (token, target-resource) pair for every egress, making the confused-deputy attempt visible as a denied exchange rather than an accepted read. - **The invariant is testable.** A conformance test injects a tool result containing a URL to a sibling resource with overlapping `aud` and asserts that the follow-up fetch raises rather than reusing the session token. This test must live in the MCP server's suite, not the client's, because the client never sees the egress. The failure mode is insidious precisely because every individual check passes: the token is valid, unexpired, correctly scoped for the *original* resource, and the sibling service's validation is internally consistent with its own (over-broad) configuration. Only the *pairing* of token and target is wrong, and only per-egress re-derivation catches it. ```python class AudienceBindingError(RuntimeError): """Raised when an egress hop would reuse a token not bound to the target resource.""" pass def authorize_egress(target_url: str, session_token: dict, allowlist: set[str]) -> dict: """ Re-derive audience for a single egress hop. Never inherit the session token across an origin boundary. Returns a token bound to target_url's origin, or raises. """ target_origin = origin_of(target_url) # scheme://host[:port] if target_origin not in allowlist: raise AudienceBindingError( f"egress to {target_origin} not in session allowlist; " f"tool-result URL is untrusted input" ) token_origin = session_token.get("resource_origin") token_aud = set(session_token.get("aud", [])) # Same-origin egress with an exactly-scoped token: reuse is legitimate. if target_origin == token_origin and token_aud == {target_origin}: return session_token # Cross-origin or over-broad aud: must re-derive via token exchange. if target_origin in token_aud and len(token_aud) > 1: # Overlapping aud is an AS misconfiguration; refuse rather than gamble. raise AudienceBindingError( f"token aud {sorted(token_aud)} overlaps target {target_origin}; " f"audience check would be a no-op — refusing egress" ) exchanged = exchange_token_for_resource(session_token, resource=target_origin) if exchanged.get("resource_origin") != target_origin: raise AudienceBindingError( f"token exchange returned token bound to {exchanged.get('resource_origin')}, " f"expected {target_origin}" ) return exchanged def fetch_followup(target_url: str, session_token: dict, allowlist: set[str]) -> bytes: """Follow a URL that appeared in a tool result. Re-validate before attaching credentials.""" try: bound = authorize_egress(target_url, session_token, allowlist) except AudienceBindingError: # Do not fall back to session token; do not silently drop. Surface to agent loop. raise return http_get(target_url, headers={"Authorization": f"Bearer {bound['access_token']}"}) ```