# In what scenarios must an instance treat MCP Streamable HTTP session reattachment as an authorization event, not a transport reconnect **Date of Record:** 2026 November 28 **Scope:** Applies to MCP servers exposing Streamable HTTP transport with `Last-Event-ID` resumption over SSE, where per-request bearer/DPoP authorization is evaluated independently of session identity. Does not apply to stdio transport, or to deployments where the session cookie is the sole authorization artifact. ## Core Distinction The MCP Streamable HTTP transport defines two orthogonal axes: a *session* (identified by `Mcp-Session-Id`, established at `initialize`, used to route to a server-side state machine) and a *request authorization context* (the credential presented on each HTTP request, evaluated per-call). The spec is explicit that the session ID is a routing token, not an authentication token, and that servers "SHOULD" bind session state to the authenticated principal. Resumable SSE reattachment via `GET` with `Last-Event-ID` is a *new HTTP request* — it re-enters the authorization pipeline from scratch — but it targets an *existing* server-side event buffer that was populated under a *prior* principal's execution context. The non-obvious failure is the gap between those two facts: reattachment is semantically a continuation of a stream, but mechanically a fresh authorization decision against a pre-existing state buffer. When the two disagree — same session ID, different or downgraded credential — the server must decide whether the buffer is a resource the new principal may read. Most implementations conflate "I know this session" with "this caller may resume it," and leak the tail of another principal's tool-call output. ## What Was Observed A multi-tenant MCP deployment fronted an internal `filesystem` and `shell` tool server. Sessions were keyed in Redis by `Mcp-Session-Id`; the SSE event log was an append-only list per session, capped at 4096 events with `Last-Event-ID` monotonic integers. Authorization was a per-request JWT check against a tool-scope map — correct in isolation. Trigger sequence observed in production logs: 1. Agent A (principal `svc-analyst`, scope `fs:read`) calls `initialize`; server allocates session `S=7f3a…` and streams a long `tools/call` for `shell:exec` (a permitted op for a *different* principal, `svc-ops`) — no, precisely: Agent A requests `fs:read`, and the server begins streaming a paginated directory walk. The stream stalls at event `id=118` because the client's TCP path drops (mobile/NAT rebind). 2. Agent A's orchestrator, on reconnect, re-issues `GET /mcp` with `Mcp-Session-Id: 7f3a…`, `Last-Event-ID: 118`, but the credential has *rotated* — the short-lived JWT expired and the retry used a refresh token minted for a *lower* scope (`fs:list` only), because the refresh grant downscoped. 3. The server's reattachment handler looked up session `7f3a…`, found the buffer, and replayed events `119..204` — including directory entries that required `fs:read`. The per-request scope check ran on the `GET` itself (which only needs `session:resume`), not on the *content* of the replayed buffer. The leak was not the initial request; it was the *replay of already-buffered output* produced under a credential the resuming caller no longer holds. A secondary variant: two agents sharing a session ID via a misconfigured orchestrator pool, where Agent B's `GET` with a valid-but-different principal resumed Agent A's stream and received A's `shell` stdout. ## Condition of Validity The invariant that must hold: **the authorization context under which an SSE event was enqueued is part of the event's identity, and reattachment must re-authorize the buffer, not just the connection.** Concretely, reattachment is safe only if all of the following hold: - Each buffered event carries the principal and scope set that was active when it was produced (an `authz_epoch` tag, not merely a timestamp). - The `GET` reattachment handler computes `effective_scope = intersect(request_credential.scopes, event.authz_epoch.scopes)` and *filters or truncates* the replay at the first event whose required scope is not in `effective_scope`, terminating the stream with an explicit `403`-equivalent SSE error event rather than silently continuing. - Session binding is re-verified: `session.principal == request.principal`, or the session is explicitly marked `shared` at `initialize` time and the buffer is partitioned per principal. If any of these is absent, the transport treats a routing token as a capability and the buffer as a public log. The condition of validity is therefore *not* "the caller presented a valid JWT" — it is "the caller presented a credential whose scope dominates the scope of every event it will receive." ## Decision Boundary The boundary is drawn between two failure modes that look identical at the socket but require opposite remediations: - **Stale-credential resume (must truncate):** same principal, downgraded scope. The correct action is to replay up to the last event the new scope permits, emit a `resume_truncated` control event with the last delivered `id`, and require the client to re-issue the underlying `tools/call` for the remainder. Do *not* silently drop events — the client's `Last-Event-ID` bookkeeping will desynchronize. - **Cross-principal resume (must reject):** different principal, any scope. The correct action is `404` on the `GET` (not `403`, to avoid confirming session existence to a non-owner) and server-side session invalidation if the orchestrator is suspected of pooling. The decision boundary is the comparison `event.authz_epoch.principal == request.principal`. If equal, scope-intersection truncation applies. If unequal, hard reject. There is no third branch where "the credential is valid so the replay is fine." A subtler edge: `Last-Event-ID` may reference an event *older* than the truncation point. If the client resumes at `id=100` but truncation would have occurred at `id=150`, the server must replay `100..150` and stop — it must not "helpfully" skip to the live tail, because the client's state machine assumes contiguous delivery and will mis-apply deltas. ## Operational Effect Without the invariant, the observable effect is *silent partial-context corruption*: the resuming agent receives a truncated or foreign event stream, applies it to its local tool-result buffer, and proceeds with reasoning grounded in output it was never authorized to see or in a gap it never detected. In the observed incident, Agent A's directory-walk state advanced past entries it had not legitimately read, producing a downstream `fs:read`-scoped summary that included filenames from a sibling tenant. The bug surfaced three hops later as a data-classification violation, not as a transport error — which is why it evaded the SSE-layer tests. The guardrail is to make authorization a property of *events*, not *connections*, and to make truncation an explicit, client-visible control event so the resuming agent's `Last-Event-ID` cursor and its local replay buffer stay in lockstep. Any MCP server that buffers SSE output for resumption is, by construction, storing authorization-scoped material; the buffer is a cache of privileged reads and must be treated with the same access control as the underlying tool results. ```python from dataclasses import dataclass, field from typing import Iterable class ResumeAuthorizationError(RuntimeError): """Raised when an SSE reattachment would replay events the caller may not read.""" @dataclass(frozen=True) class AuthzEpoch: principal: str scopes: frozenset @dataclass(frozen=True) class BufferedEvent: event_id: int authz: AuthzEpoch required_scope: str payload: str @dataclass class Session: session_id: str principal: str events: list = field(default_factory=list) def resume_stream( session: Session, request_principal: str, request_scopes: frozenset, last_event_id: int, ) -> Iterable[BufferedEvent]: # Cross-principal resume is a hard reject: never confirm session existence. if session.principal != request_principal: raise ResumeAuthorizationError( f"session {session.session_id} owned by {session.principal!r}, " f"resume attempted by {request_principal!r}" ) pending = [e for e in session.events if e.event_id > last_event_id] if not pending: return [] delivered: list[BufferedEvent] = [] for ev in pending: # Invariant: replay is bounded by the *event's* authz epoch, not the connection's. if ev.required_scope not in request_scopes: # Truncate explicitly; do not skip-and-continue. if not delivered: raise ResumeAuthorizationError( f"first resumable event {ev.event_id} requires " f"{ev.required_scope!r}, caller holds {sorted(request_scopes)}" ) # Signal truncation to the client so its Last-Event-ID cursor stays honest. delivered.append( BufferedEvent( event_id=delivered[-1].event_id, authz=ev.authz, required_scope="__resume_truncated__", payload=f"truncated_at={delivered[-1].event_id}", ) ) return delivered delivered.append(ev) return delivered def test_downgraded_scope_truncates(): sess = Session("7f3a", "svc-analyst") sess.events = [ BufferedEvent(118, AuthzEpoch("svc-analyst", frozenset({"fs:list"})), "fs:list", "a"), BufferedEvent(119, AuthzEpoch("svc-analyst", frozenset({"fs:read"})), "fs:read", "b"), ] out = resume_stream(sess, "svc-analyst", frozenset({"fs:list"}), 117) assert out[-1].required_scope == "__resume_truncated__" assert out[-1].payload == "truncated_at=118" ```