# Under what conditions must an instance treat SSE `Last-Event-ID` resumption as invalid across an OAuth 2.1 token rotation boundary **Date of Record:** 2026 November 16 **Scope:** Applies to MCP servers exposing the HTTP-native streamable transport (POST for JSON-RPC, GET for the SSE event stream) where resumability is implemented via `Last-Event-ID` and the server acts as an OAuth 2.1 resource server validating bearer tokens against a protected-resource metadata document. Does not apply to stdio transport, to stateless SSE endpoints without event-ID replay, or to deployments where the same token authority governs both the event log and the request path (e.g., single-issuer, non-rotating client credentials). ## Core Distinction The distinction that matters is between *event-log continuity* and *authorization continuity*. The SSE event ID is a cursor into a server-side replay buffer. The bearer token is a capability bound to a subject, a resource audience (RFC 8707), and a lifetime. MCP streamable transport requires that a client resuming a dropped stream present `Last-Event-ID`; OAuth 2.1 resource-server binding requires that every request carry a token whose `aud` matches this resource and whose `exp` has not passed. These two invariants are orthogonal, and the failure mode is treating them as coupled in the wrong direction: an implementation that validates `Last-Event-ID` against the replay buffer *before* re-validating the token, or that caches the token-to-stream association at stream open and trusts it for the lifetime of the replay window. The non-obvious part: a resumption request is a *new* HTTP request. It is not a continuation of the authorized connection; it is a fresh authorization decision against a cursor that may point to events generated under a different authorization context. When the token that opened the stream has rotated (refresh occurred, or the token expired and the client obtained a new one), the resumption is authorized by a *different* credential than the one that produced the buffered events. Whether that is safe depends on whether the subject and audience are unchanged — and that is a property the server must check explicitly, not assume. ## What Was Observed A streamable-MCP server held per-session replay buffers keyed by `(session_id, stream_id)` with a 5-minute retention window. On `GET /mcp` with `Last-Event-ID`, the handler looked up the buffer, replayed from the cursor, and *then* attached the live tail. Token validation ran in middleware and checked `exp` and signature, but the buffer lookup did not compare the token's `sub` or `aud` against the values recorded when the buffer was created. Sequence observed in logs: 1. Client opens `GET /mcp` with token T1 (`sub=agent-7`, `aud=mcp://tools.example`, `exp` 60s). 2. Server emits events `e1..e40`, buffer records `owner_sub=agent-7`, `owner_aud=mcp://tools.example`, `opened_at`. 3. Network drop at t+45s. Client refreshes via the authorization server, obtains T2 (`sub=agent-7`, `aud=mcp://tools.example`, new `jti`, `exp` +3600s). 4. Client reconnects with `Last-Event-ID: e40` and `Authorization: Bearer T2`. 5. Middleware validates T2 — passes. Buffer lookup finds the stream, replays `e41..eN` and resumes live. This particular sequence was benign because `sub` and `aud` were identical. The failure surfaced in a second sequence where a *different* client process (a delegated sub-agent) reused the `session_id` after a crash-restart of the orchestrator, presented its own valid token T3 (`sub=agent-12`, same `aud`), and was replayed the tail of `agent-7`'s stream because the buffer lookup keyed only on `session_id` and `stream_id`. The middleware was satisfied; the buffer was not consulted for ownership. Cross-subject event leakage occurred with no authentication error logged. A third sequence exposed the inverse: a client whose token had *expired* mid-stream and was resumed with a still-valid old token within its clock-skew grace window was replayed events generated *after* the token's nominal `exp`, extending the effective authorization lifetime of a credential beyond its stated bound. ## Condition of Validity `Last-Event-ID` resumption is valid **if and only if** all of the following hold at the moment of resumption: - The presented token validates against the current JWKS, `exp`/`nbf` with zero grace, and `aud` contains this resource's canonical URI per RFC 8707. - `sub` of the presented token equals the `owner_sub` recorded when the replay buffer was created. - `aud` of the presented token equals the `owner_aud` recorded at buffer creation. A token scoped to a different resource must not consume this buffer even if the same issuer signed it. - The cursor `Last-Event-ID` refers to an event whose `emitted_at` is within the buffer's retention window *and* whose `emitted_at` is not later than the presented token's `exp`. Events emitted after token expiry are not resumable under that token — they must be re-fetched under a fresh token or dropped. - For any token carrying `cnf` (DPoP) or a sender-constrained binding, the proof presented at resumption matches the key recorded at buffer creation. If any condition fails, the server must not replay. It must respond `400` with an SSE `error` event carrying a machine-readable code (`resumption_denied`) and, where the client can recover, a hint to re-initialize the stream from a fresh cursor (`Last-Event-ID` omitted). Returning `401` is incorrect here when the token itself is valid — the failure is authorization-to-*this buffer*, not authentication. ## Decision Boundary The boundary is not "token valid vs. invalid." It is **"does the resumption request's authorization context match the context under which the buffered events were produced, and does the token's lifetime cover the events being replayed."** Three concrete decision points: 1. **Subject continuity.** Same `sub`, different `jti` → resumption permitted (normal refresh). Different `sub` → denied, regardless of `aud` match. This is the case that leaked. 2. **Audience continuity.** Same `sub`, different `aud` → denied. A token minted for a different MCP resource must not read this buffer's tail even for the same subject; the resource server binding is per-resource. 3. **Temporal continuity.** Cursor points past the token's `exp` → the events after `exp` are not replayable under this token. The server may replay up to `exp` and then close the stream with a `token_expired` terminal event, forcing re-authorization. It must not silently continue the tail under a token whose `exp` has passed, even within clock skew. A subtle corollary: if the server uses a single replay buffer per `session_id` shared across multiple `stream_id`s (as many implementations do), the ownership record must be per-stream, not per-session. Session-scoped ownership is the most common source of the cross-subject leak, because session IDs are frequently reused after orchestrator restarts and are not themselves bound to a subject. ## Operational Effect When the boundary is enforced, the observable behavior is: resumption across a token refresh with identical `sub`/`aud` succeeds transparently (the common case, ~99% of resumptions); resumption across a subject or audience change fails fast with `resumption_denied` and the client re-initializes; resumption across an expired token replays only up to `exp` and terminates. The replay buffer can be garbage-collected on token expiry rather than on a fixed wall-clock window, which reduces retention cost and removes the window in which a stale credential can consume events. When the boundary is *not* enforced, the failure is silent: no auth error, no 4xx, just events delivered to the wrong subject or under an expired capability. Detection requires correlating `owner_sub` recorded at stream open with the `sub` of the token presented at resumption — a check most middleware does not perform because it validates tokens statelessly and has no view of the buffer. The mitigation is to make the buffer ownership record a first-class part of the resumption path, not a side effect of session bookkeeping. The following reference implementation encodes the check as an explicit gate. It is deliberately conservative: it denies on any mismatch and requires the caller to re-initialize rather than attempting partial replay. ```python """Resumption authorization gate for MCP streamable transport with OAuth 2.1 RS binding. Encodes the invariant: a Last-Event-ID resumption is valid only when the presented token's (sub, aud) match the values recorded at buffer creation, the cursor lies within retention, and the cursor does not point past the token's exp. """ from __future__ import annotations import time from dataclasses import dataclass from typing import Optional class ResumptionDenied(RuntimeError): """Raised when an SSE resumption request fails the authorization-continuity gate.""" def __init__(self, code: str, detail: str) -> None: super().__init__(f"{code}: {detail}") self.code = code self.detail = detail @dataclass(frozen=True) class BufferOwnership: owner_sub: str owner_aud: str opened_at: float retention_s: float @dataclass(frozen=True) class TokenClaims: sub: str aud: str # canonical resource URI per RFC 8707 exp: float # absolute epoch seconds, no skew applied jti: str @dataclass(frozen=True) class EventCursor: last_event_id: str emitted_at: float # epoch seconds of the referenced event def authorize_resumption( *, ownership: Optional[BufferOwnership], claims: TokenClaims, cursor: EventCursor, resource_uri: str, now: Optional[float] = None, ) -> None: """Raise ResumptionDenied unless resumption is authorized under the current token. Returns None on success. Callers must treat any raise as a terminal resumption failure and instruct the client to re-initialize the stream. """ now = time.time() if now is None else now if ownership is None: raise ResumptionDenied( "unknown_buffer", f"no replay buffer for Last-Event-ID={cursor.last_event_id!r}", ) # 1. Audience continuity: token must be scoped to this resource. if claims.aud != resource_uri: raise ResumptionDenied( "audience_mismatch", f"token aud={claims.aud!r} does not match resource {resource_uri!r}", ) if claims.aud != ownership.owner_aud: raise ResumptionDenied( "audience_drift", f"token aud={claims.aud!r} != buffer owner_aud={ownership.owner_aud!r}", ) # 2. Subject continuity: same principal that opened the stream. if claims.sub != ownership.owner_sub: raise ResumptionDenied( "subject_mismatch", f"token sub={claims.sub!r} != buffer owner_sub={ownership.owner_sub!r}", ) # 3. Temporal validity of the presented credential. if claims.exp <= now: raise ResumptionDenied( "token_expired", f"token exp={claims.exp} <= now={now}", ) # 4. Cursor must lie within retention. if now - cursor.emitted_at > ownership.retention_s: raise ResumptionDenied( "cursor_outside_retention", f"event age {now - cursor.emitted_at:.1f}s exceeds retention " f"{ownership.retention_s:.1f}s", ) # 5. Cursor must not point past the token's exp. # Events emitted after exp are not replayable under this token. if cursor.emitted_at > claims.exp: raise ResumptionDenied( "cursor_past_token_exp", f"event emitted_at={cursor.emitted_at} > token exp={claims.exp}", ) ```