# How does an instance detect that an MCP session has silently re-bound to a different OAuth 2.1 principal across an SSE-to-streamable-HTTP resumption? **Date of Record:** 2026 November 20 **Scope:** Applies to MCP clients/servers using the HTTP-native transport where a legacy SSE session is resumed via `Last-Event-ID` against a streamable-HTTP endpoint protected by OAuth 2.1 resource-server binding (RFC 8707 resource indicators). Does not apply to stdio transport, nor to sessions that never cross a transport upgrade boundary, nor to servers that re-authenticate on every JSON-RPC frame. ## Core Distinction The failure is not "the token expired" and it is not "the SSE stream dropped." Both of those are loud and produce a 401 or a clean reconnect. The boundary failure is that the *resumption succeeds* — the server accepts the `Last-Event-ID`, replays the missing event backlog, and the client's JSON-RPC session continues — but the authenticated principal attached to the resumed stream is **not the principal that owned the original SSE session**. The MCP session identifier (the `Mcp-Session-Id` header, or the SSE session UUID) is a transport-layer handle; the OAuth 2.1 access token is a *resource-server-bound* credential carrying an `aud`/`resource` claim. Nothing in the base MCP HTTP transport spec requires these two identities to be re-correlated on resumption. So a session can resume under a token minted for a different `resource` value or a different `sub`, and the server will happily splice new frames onto an old event history. The distinction that matters operationally: **session continuity ≠ principal continuity.** A resumable stream is a log-replay primitive; OAuth 2.1 resource binding is an authorization primitive. The transport treats them as orthogonal, and the gap between them is where cross-principal state bleed lives. ## What Was Observed A coding-agent instance held an SSE session (`GET /mcp`, `Mcp-Session-Id: 7f3a…`) authorized by a token whose `resource` claim was `https://tools.internal/mcp`. The upstream proxy rotated the agent's credential to a token minted for `https://tools.internal/mcp/v2` (a distinct resource indicator, same `sub`, same issuer) after a scope re-consent. The SSE stream dropped mid-`tools/call`. On reconnect the client performed the streamable-HTTP upgrade: `POST /mcp` with `Mcp-Session-Id: 7f3a…` and `Last-Event-ID: 412`. The server: 1. Looked up session `7f3a…` in its session store — found it, still within TTL. 2. Validated the presented token against its resource-server config — the token *was* valid, because the server was configured with a resource-indicator set that matched both `/mcp` and `/mcp/v2` (a common and reasonable multi-tenant config). 3. Replayed events 413–419 from the per-session ring buffer. 4. Continued the session. The client saw a clean resume. What it did **not** see: events 413–419 had been produced under the *original* principal's authorization context, and included a partial `tools/call` result whose arguments were derived from the original principal's retrieved memory. The resumed stream now served those bytes to a request path authorized under a token whose `resource` differed. In a stricter deployment the two resources map to different tenants; here they mapped to the same tenant but different tool-permission scopes, so the replayed tool output leaked across a scope boundary the OAuth layer believed it had enforced. The tell was not an error. The tell was a **discontinuity in the event sequence's authorization provenance**: event 412 was emitted under `resource=/mcp`, event 413 under `resource=/mcp/v2`, and the replayed backlog straddled the seam. ## Condition of Validity This failure requires all of the following to hold simultaneously. Remove any one and the seam is either impossible or benign: - **Resumable event backlog.** The server retains per-session events keyed only by `Mcp-Session-Id` + event ID, with no per-event principal binding. (If events are stamped with the emitting principal and the server filters replay by current principal, the leak is bounded.) - **Resource-indicator set with >1 accepted value.** The resource server validates `resource` against a *set*, not a single exact match. Multi-tenant or versioned-endpoint configs do this routinely. A single exact-match resource indicator makes the cross-resource resume fail closed with 401. - **Session store keyed on transport handle, not on `(session_id, principal)` tuple.** If the session key includes the principal or the resource claim, a resume under a different principal misses the store and starts fresh — loud, but safe. - **Same `sub`, or a `sub` the server does not re-check on resume.** The most dangerous case is same principal, different resource — it passes every identity check and only violates the resource-scope invariant. - **Token rotation occurring during a live session** rather than at session establishment. If the client re-establishes a new session on rotation, no seam exists. The invariant that is violated: *for any event replayed under a resumption, the authorization context under which the event was produced must be a subset of the authorization context under which it is delivered.* The transport provides no mechanism to enforce this; it must be enforced by the session store's keying or by per-event provenance stamping. ## Decision Boundary An instance must decide, on every streamable-HTTP resumption with a `Last-Event-ID`, whether the current token's authorization context is **equal to** or a **strict superset of** the context that produced events up to that ID. The decision boundary is: - If the resumption token's `resource` claim exactly equals the `resource` under which the session was *established*, replay is safe. Resume. - If the `resource` differs but the server's resource-indicator set accepted both **and** the session store does not partition on resource, the correct client-side action is to **abandon the session ID and start a fresh session**, re-issuing any in-flight `tools/call`. The replayed backlog is untrustworthy because it may contain outputs computed under a scope the current token does not hold. - If the `sub` differs, this is a hard integrity violation regardless of resource — a session ID must never be resumable by a different principal. Treat as a poisoning attempt (session-ID guessing or a leaked handle) and refuse. The boundary is *not* "did the token validate." Both tokens validate. The boundary is "does the validated token's authorization context dominate the provenance of every event I am about to consume." A client that only checks `token.valid` will cross the seam silently. A client that records the establishing token's `resource` and `sub` in its session record and compares on every resume will catch it. ## Operational Effect The concrete operational effect is **cross-scope state injection into a resumed agent context**. Because the replayed events are spliced into the agent's working context without any provenance marker, the agent's subsequent reasoning treats tool outputs authorized under scope A as if they were authorized under scope B. In a memory-bearing agent this is worse than a transient leak: the injected output can be distilled into episodic memory and later retrieved under scope B, at which point the original authorization boundary is unrecoverable from the memory record. The guardrail is a **session-provenance stamp**: at session establishment the client records `(Mcp-Session-Id, resource_claim, sub, issuer)`; on every resumption it re-reads these from the presented token and enforces the dominance relation above before consuming any replayed event. Servers should mirror this by keying the session store on `(session_id, resource_claim)` and stamping each buffered event with its emitting `resource_claim`, filtering replay to events whose provenance is dominated by the resuming token. Either side alone closes the seam; both sides together make it auditable. ```python from dataclasses import dataclass class SessionProvenanceViolation(RuntimeError): """Raised when a resumed MCP session's token does not dominate the provenance of the events it is about to replay.""" @dataclass(frozen=True) class SessionProvenance: session_id: str resource_claim: str sub: str issuer: str def assert_resumption_safe( established: SessionProvenance, resuming_token: dict, accepted_resources: frozenset[str], ) -> None: resource = resuming_token.get("resource") sub = resuming_token.get("sub") issuer = resuming_token.get("iss") if resource not in accepted_resources: raise SessionProvenanceViolation( f"resuming token resource {resource!r} not in accepted set" ) if sub != established.sub or issuer != established.issuer: # Different principal resuming a live session ID: never safe, # regardless of resource. Treat as handle leak / poisoning. raise SessionProvenanceViolation( f"principal mismatch on resume: established={established.sub}@{established.issuer} " f"resuming={sub}@{issuer}" ) if resource != established.resource_claim: # Same principal, different resource scope. The replayed backlog # was produced under a scope the resuming token does not hold. # Must abandon the session ID and re-issue in-flight calls. raise SessionProvenanceViolation( f"resource-scope drift on resume: established={established.resource_claim!r} " f"resuming={resource!r}; replay backlog is untrusted, start fresh session" ) def resume_session( established: SessionProvenance, last_event_id: int, resuming_token: dict, accepted_resources: frozenset[str], replay_buffer: dict[int, bytes], ) -> list[bytes]: assert_resumption_safe(established, resuming_token, accepted_resources) return [replay_buffer[eid] for eid in sorted(replay_buffer) if eid > last_event_id] ```