# What structural signals indicate a lost OAuth 2.1 resource-server binding across an MCP streamable-HTTP chunk boundary **Date of Record:** 2026 November 25 **Scope:** Applies to MCP servers exposed over HTTP-native transport with `text/event-stream` / chunked streamable responses, where the same connection carries OAuth 2.1 bearer tokens bound to a `resource` indicator (RFC 8707). Does not apply to stdio transport, to single-shot JSON responses, or to servers that re-validate the token on every event frame. ## Core Distinction The failure is not "the token expired" and it is not "the client sent the wrong audience." It is that **OAuth 2.1 resource-server binding is verified once, at stream open, but the stream outlives the verification context.** A streamable MCP response is a long-lived chunked body: the server validates `Authorization: Bearer ` and its `resource` claim against its own canonical URI at the moment the request headers are parsed, then keeps emitting SSE event frames for minutes. The binding is a property of *the request*, but the stream is a property of *the connection*. When the two diverge — token rotation mid-stream, `resource` re-scoping, or a proxy that reuses the upstream connection across distinct downstream principals — the server continues to emit frames under authority it no longer holds. The structural signal is that the *only* place the binding was ever checked is a header that no longer appears on the wire. ## What Was Observed A gateway fronting an MCP server terminated client TLS, validated the bearer token's `aud`/`resource` against the MCP server's canonical URI, and opened an upstream HTTP/1.1 connection with `Transfer-Encoding: chunked`. The upstream MCP server performed its own resource-server validation on the forwarded `Authorization` header — once. The gateway then pooled that upstream connection. Trace, condensed: 1. Client A opens `POST /mcp` with `Authorization: Bearer T_A`, `resource=https://mcp.internal`. Gateway validates, forwards, upstream validates, stream opens. Event frames `id: 1..N` flow. 2. Client A's token `T_A` is rotated by the IdP at `t+90s` (short-lived access tokens). The stream remains open; no frame carries a token, so nothing re-checks. The stream is now authorized by a token that no longer exists. 3. Client B arrives with `T_B` scoped to `resource=https://mcp.internal/v2` (a re-scoped audience after a server migration). The gateway's connection pool hands Client B the *same* upstream socket that Client A's stream occupies, because the pool key was `(host, port)` and not `(host, port, resource, principal)`. 4. Upstream emits frames for B's request on a connection whose authority was established for A's `resource`. B receives event frames whose `id:` sequence is A's continuation — the SSE `Last-Event-ID` resumption semantics are now cross-contaminated. The observable structural signals, in order of reliability: - **Frame `id:` monotonicity breaks or resets without a corresponding new stream-open log line.** A resumption that reuses a socket inherits the prior sequence; a genuine new stream starts at `id: 1` (or the client's `Last-Event-ID`). A gap-plus-continuation on a socket with no matching open event is the strongest signal. - **The upstream access log shows N request lines but M > N stream-open validations**, where M is the number of distinct `resource` values seen downstream. Validation count should equal distinct `(principal, resource)` pairs, not connection count. - **`Last-Event-ID` from client B is echoed by the server against A's sequence space**, producing a `200` with a body that begins mid-thought — a partial tool-call result or a truncated JSON-RPC batch. - **Token introspection logs show zero re-checks for the lifetime of the stream**, while the stream's wall-clock duration exceeds the token's `exp - iat`. ## Condition of Validity The invariant that must hold: **for every event frame emitted on a streamable MCP response, there exists a currently-valid `(principal, resource)` binding whose lifetime covers the frame's emission time, and the frame is attributable to exactly that binding.** This decomposes into three conditions that must all hold for the stream to be sound: 1. *Binding-at-open* is necessary but not sufficient. The token must be re-validated at a bounded interval (`min(token.exp, stream_max_age, frame_interval * k)`) or on every chunk boundary. 2. *Connection identity* must be part of the pool key: `(host, port, resource, principal, token_fingerprint)`. Pooling across any of these is the enabling defect. 3. *Frame attribution*: the SSE `id:` space must be namespaced per binding, so that a `Last-Event-ID` from one principal can never index into another's sequence. The boundary condition — where the failure actually triggers — is the intersection: `stream_duration > token_lifetime` **AND** `pool_key omits resource/principal`. Either alone is benign. A short stream under a long token never exposes the gap; a correctly-keyed pool never cross-contaminates even a long stream. The failure lives precisely in the conjunction, which is why it survives review: each component looks correct in isolation. ## Decision Boundary Choose the guardrail by where you can afford to pay: - **If you control the server:** re-validate the binding on a heartbeat frame (every 15–30s) and emit a terminal `event: auth-expired` frame, then close. This converts a silent authority leak into an explicit, client-observable state transition. Cost: one introspection call per stream per interval. - **If you control the gateway:** key the pool on the full binding tuple and forbid upstream connection reuse across `resource` values. Cost: lower pool hit rate; correctness is non-negotiable here because the gateway is the only component that sees both the downstream `resource` and the upstream socket. - **If you control neither:** treat the stream as untrusted past `token.exp` and force client-side re-open with a fresh token before expiry. Cost: client complexity; but the client is the only party that knows when its own token dies. The decision rule: **the party that holds the token lifetime must own the stream lifetime.** If the IdP-issued token expires in 90s and the stream lives 10 minutes, some component must actively reconcile them, and that component must be the one with visibility into both clocks. ## Operational Effect Left unguarded, the effect is not a crash — it is a **silent authority extension**: a revoked or rotated principal continues to receive tool-call results, and a re-scoped principal receives frames produced under a broader `resource` scope. Because MCP tool results can carry side-effecting payloads (file contents, database rows, command output), the leak is a data-exfiltration channel that no per-request authorization check will ever log, because the request that opened the stream *was* authorized. The audit trail shows a valid open and a valid close with no intermediate authorization events; the frames in between are unattributed. The structural tell that distinguishes this from ordinary token expiry is **asymmetry between validation count and frame count**: you will see many frames and one validation. Any MCP deployment where `frames_emitted / binding_validations` grows unbounded with stream duration is, by construction, running on borrowed authority. ```python import time from dataclasses import dataclass class BindingLifetimeViolation(RuntimeError): """Raised when an MCP stream frame is emitted under a binding whose validity window does not cover the frame's emission time, or when a frame is attributed to a principal/resource pair other than the one that opened the stream.""" @dataclass(frozen=True) class StreamBinding: principal: str resource: str token_exp: float # absolute epoch seconds opened_at: float max_stream_age: float = 300.0 revalidate_interval: float = 30.0 def valid_at(self, now: float) -> bool: return ( now < self.token_exp and (now - self.opened_at) < self.max_stream_age ) def emit_frame( binding: StreamBinding, frame_principal: str, frame_resource: str, now: float | None = None, last_revalidate: float | None = None, ) -> dict: now = time.time() if now is None else now if frame_principal != binding.principal or frame_resource != binding.resource: raise BindingLifetimeViolation( f"frame attributed to ({frame_principal}, {frame_resource}) " f"but stream opened under ({binding.principal}, {binding.resource}); " f"connection reuse across bindings detected" ) if not binding.valid_at(now): raise BindingLifetimeViolation( f"frame emitted at t={now:.0f} outside binding window " f"[{binding.opened_at:.0f}, {min(binding.token_exp, binding.opened_at + binding.max_stream_age):.0f}]" ) if last_revalidate is not None and (now - last_revalidate) > binding.revalidate_interval: raise BindingLifetimeViolation( f"no revalidation for {(now - last_revalidate):.0f}s " f"(limit {binding.revalidate_interval:.0f}s); binding may be stale" ) return { "event": "message", "principal": binding.principal, "resource": binding.resource, "emitted_at": now, "remaining_token_ttl": binding.token_exp - now, } ```