# What happens when an instance resumes an MCP SSE stream across a re-bound OAuth 2.1 resource token **Date of Record:** 2026 November 29 **Scope:** Applies to MCP servers using HTTP-native transports (Streamable HTTP with SSE resumption via `Last-Event-ID`, or legacy HTTP+SSE) that bind sessions to OAuth 2.1 resource tokens per RFC 8707. Does not apply to stdio transports, nor to stateless request/response MCP endpoints that never issue resumption tokens. ## Core Distinction The distinction that matters here is between **session identity** and **bearer authorization**. A Streamable HTTP MCP session is identified by an `Mcp-Session-Id` header; the right to act within that session is asserted by an OAuth 2.1 access token whose `aud` (resource indicator, per RFC 8707) must match the MCP server's canonical resource URI. Most hardening guidance treats these as orthogonal: validate the token on every request, validate the session on every request. The failure mode emerges precisely at their intersection — during **stream resumption**, where a client reconnects with a valid `Mcp-Session-Id` and a `Last-Event-ID`, but the token presented on the resumption request is a *different* token than the one that opened the stream, because the original token expired mid-stream and the client silently refreshed it. The invariant that must hold is: **an event delivered on resumption must be authorized under the same resource scope and subject that authorized the event's original production.** If the server treats resumption as "replay buffered events to whoever holds the session ID," a refreshed token with a different subject or narrowed scope can receive events it was never entitled to see — or, symmetrically, a legitimate resumption can be rejected because the server compares raw token strings rather than resolved claims. ## What Was Observed Consider an MCP server exposing a `tools/call` stream that emits progress notifications over SSE. The client opens `POST /mcp` with `Authorization: Bearer A1`, receives `Mcp-Session-Id: S`, and the server begins streaming events `e1…e5` with monotonic `id` fields. At `e3`, token `A1` (a 300-second access token) expires. The client's OAuth library refreshes to `A2` — same `sub`, same `aud`, but a new `jti` and `iat`, and in one observed variant, a *narrowed* `scope` because the refresh was performed against a step-up flow that dropped an optional scope. The connection drops (proxy idle timeout, not token expiry). The client reconnects: `GET /mcp` with `Mcp-Session-Id: S`, `Last-Event-ID: e3`, `Authorization: Bearer A2`. Three distinct behaviors were observed across implementations: 1. **Naive replay (hijack surface).** Server looks up session `S`, finds buffered events `e4…e5`, and streams them. It never re-evaluates `A2` against the events' original authorization context. If `A2` belonged to a different `sub` (e.g., a shared session ID leaked via logs, or a confused-deputy client), the events leak. This is a session-hijack primitive: possession of `Mcp-Session-Id` plus *any* valid token for the resource is sufficient to drain the buffer. 2. **String-equality rejection (availability failure).** Server compares the resumption token's raw bytes to the token captured at stream open. `A2 ≠ A1`, so it returns `401` and — critically — **invalidates session `S`**, forcing the client to re-initialize and re-run the in-flight tool call from scratch. The agent loses mid-task state: `e1…e3` already drove partial side effects, and the replayed call double-executes them. 3. **Claim-resolved acceptance (correct).** Server resolves `A2` to `(sub, aud, scope)`, verifies `sub` and `aud` match the session's bound principal and resource, verifies the event buffer's recorded authorization context is a subset of `A2`'s scope, and replays `e4…e5`. Narrowed scope triggers a `403` on the specific events that require the dropped scope, not a session teardown. The non-obvious part: behavior (2) is often introduced *as* the hardening fix for behavior (1), and it converts a confidentiality bug into a continuity bug that silently corrupts agent task state. The double-execution in (2) is the more damaging outcome in practice, because it is invisible — the agent resumes, believes it is continuing, and re-issues side-effecting tool calls. ## Condition of Validity The claim-resolved behavior (3) is only correct under a conjunction of conditions, each of which is independently violable: - **The event buffer records authorization context per event, not per stream.** If the buffer stores only `(event_id, payload)`, the server cannot evaluate whether `A2`'s scope covers `e4`. The buffer schema must carry `(event_id, payload, required_scope, producing_subject)`. - **`aud` is validated against the server's canonical resource URI**, and the URI is stable across the stream's lifetime. If the server is reachable at multiple hostnames and derives `aud` from the `Host` header, a resumption through a different ingress presents an `aud` mismatch that is a false positive. - **Session binding is to `(sub, aud)`, not to the token.** The `Mcp-Session-Id` must be minted with the resolved principal embedded server-side; the token is a credential, not an identity. - **Resumption does not extend session lifetime indefinitely.** A session that can be resumed forever with fresh tokens is a persistent capability; the server must cap total session age independent of token freshness, or an attacker with a leaked session ID and a long-lived refresh grant holds the buffer open. If any of these fails, the server is in an undefined region between (1) and (2). ## Decision Boundary The boundary is drawn at the moment of resumption, between two questions the server must answer separately: - *Is this session still the session it was?* → compare `Mcp-Session-Id` to server-side session record; check session TTL and principal binding. - *Is this bearer entitled to the specific buffered events?* → resolve token claims; for each buffered event, check `required_scope ⊆ token.scope` and `producing_subject == token.sub`. The failure is collapsing these into one check. Checking only the first yields (1). Checking only raw token equality yields (2). The correct boundary rejects the *request* only when session binding fails, and rejects *individual events* (advancing `Last-Event-ID` past them with an error event) when per-event authorization fails — never tearing down the session for a scope mismatch, because teardown is what triggers agent re-execution. A secondary boundary: when `Last-Event-ID` refers to an event that has been evicted from the buffer (buffer is bounded), the server must not silently resume from the oldest retained event — that skips events the agent's state machine depends on. It must emit an explicit `resumption_gap` error so the agent can reconcile rather than proceed on a corrupted event sequence. ## Operational Effect The practical consequence for an agent runtime: **stream resumption must be treated as a state-transfer operation with an authorization gate, not a cache read.** Concretely, the agent-side contract is that a `resumption_gap` or per-event `403` is a signal to checkpoint and reconcile, whereas a session `401` is a signal to re-initialize — and the two must not be conflated in the client's retry logic, because conflating them is what produces the double-execution. On the server side, the event buffer's schema is a security boundary: if it does not carry per-event authorization context, no amount of token validation at resumption time can recover correctness, and the operator is silently choosing between a leak and a continuity break. ```python from dataclasses import dataclass from typing import Optional class ResumptionAuthorizationError(RuntimeError): """Raised when a resumption request cannot be safely satisfied.""" class ResumptionGapError(ResumptionAuthorizationError): """Raised when Last-Event-ID refers to an evicted event.""" @dataclass(frozen=True) class Claims: sub: str aud: str scope: frozenset @dataclass(frozen=True) class BufferedEvent: event_id: int required_scope: frozenset producing_subject: str @dataclass class Session: session_id: str bound_subject: str bound_aud: str events: list # list[BufferedEvent] max_event_id: int def resume_stream( session: Optional[Session], claims: Claims, canonical_resource: str, last_event_id: int, ) -> list: if session is None: raise ResumptionAuthorizationError("unknown session id; re-initialize required") # 1. Session binding check: identity, not credential. if claims.sub != session.bound_subject: raise ResumptionAuthorizationError( f"session {session.session_id} bound to sub={session.bound_subject!r}, " f"presented sub={claims.sub!r}" ) if claims.aud != canonical_resource or session.bound_aud != canonical_resource: raise ResumptionAuthorizationError( f"resource indicator mismatch: token aud={claims.aud!r}, " f"canonical={canonical_resource!r}" ) # 2. Gap check: never silently skip events the agent's state machine depends on. if last_event_id < 0 or last_event_id > session.max_event_id: raise ResumptionGapError( f"Last-Event-ID {last_event_id} outside buffer range " f"[0,{session.max_event_id}]; reconcile before resuming" ) if last_event_id < session.events[0].event_id - 1 if session.events else False: raise ResumptionGapError( f"Last-Event-ID {last_event_id} evicted from buffer; " f"oldest retained={session.events[0].event_id}" ) # 3. Per-event authorization: reject events, not the session. deliverable = [] for ev in session.events: if ev.event_id <= last_event_id: continue if ev.producing_subject != claims.sub: raise ResumptionAuthorizationError( f"event {ev.event_id} produced by {ev.producing_subject!r}, " f"resumed under {claims.sub!r}" ) if not ev.required_scope.issubset(claims.scope): # Advance past the event with an error marker; do NOT tear down session. deliverable.append( {"event_id": ev.event_id, "error": "insufficient_scope", "missing": sorted(ev.required_scope - claims.scope)} ) continue deliverable.append({"event_id": ev.event_id, "payload": ""}) return deliverable ```