# Where must an instance of the MCP HTTP-native transport enforce authorization scope re-evaluation across a resumable SSE reconnect boundary? **Date of Record:** 2026 November 16 **Scope:** Applies to MCP servers exposing the HTTP-native transport (streamable HTTP with `Mcp-Session-Id` and SSE event streams supporting `Last-Event-ID` resumption) where per-tool authorization scopes are evaluated at request ingress. Does not apply to stdio transport, nor to deployments where scope is re-derived from the bearer token on every stream frame (stateless re-evaluation per event). ## Core Distinction There are two distinct authorization moments in an MCP HTTP-native session, and conflating them produces the failure: the *invocation moment* (a `tools/call` POST arrives, scope is checked against the tool's declared requirement) and the *stream-continuation moment* (a client reconnects to an in-flight or buffered SSE stream with `Last-Event-ID`, and the server resumes emitting events that were authorized under a prior invocation). The invariant that must hold is: **every event delivered on a resumed stream must be covered by the scope set valid at the time of that event's original authorization, and the resuming connection's credentials must still satisfy that scope set.** The non-obvious boundary is that `Last-Event-ID` resumption is a *read* operation over a buffer whose contents were authorized by a *different* request context. If the server treats resumption as a passive replay gated only by session identity, a client whose scope was narrowed (or whose token was rotated to a lesser role) between disconnect and reconnect will receive buffered tool output — including side-effecting tool results and intermediate progress notifications — that its current credentials no longer entitle it to. ## What Was Observed A server implementing streamable HTTP kept a per-session ring buffer of SSE events keyed by monotonically increasing event IDs. On `GET /mcp` with `Last-Event-ID: N`, it validated the `Mcp-Session-Id`, confirmed the session's bearer token was *still valid* (non-expired), and replayed events `N+1..head`. Scope was checked only at the `tools/call` POST that originated each event. During a scope-downgrade drill, a client holding a session with `tools:read` and `tools:write` scopes invoked a write tool, disconnected mid-stream (the tool emitted a multi-part progress stream with a final result payload), and the operator revoked `tools:write` from the token's role. The client reconnected with the same session ID and `Last-Event-ID`. The server validated token non-expiry, replayed the buffered progress and final result events — which contained the write tool's confirmation payload with mutated resource state — to a connection that could no longer invoke that tool. The replay was accepted as legitimate because "the session was authenticated." No audit entry was written for the replayed delivery, because the delivery path did not re-enter the authorization middleware. A second, subtler variant: token rotation to a *different* principal (shared session ID reused after a client reconnect that presented a new token) replayed events authorized under the first principal to the second. Session ID was treated as the authorization subject; it is not. ## Condition of Validity The invariant above holds only when the following three conditions are jointly satisfied, and it is *invalid* (silently) when any is violated: 1. **Event provenance is recorded.** Each buffered event carries the authorization context (principal identifier + scope set) under which it was produced, not merely the session ID. 2. **Resumption re-evaluates.** The `Last-Event-ID` handler intersects the current connection's scope set with the recorded scope set of each event before emitting it; events failing the intersection are dropped (not replayed, not errored — dropped, with a gap marker) rather than delivered. 3. **Buffer lifetime is bounded by authorization lifetime.** A buffered event whose recorded authorization context is stale (token expired, role changed) is invalidated at the buffer, not at replay time. Otherwise a long-lived buffer becomes an authorization time capsule. The condition fails silently when (1) is satisfied but (2) is omitted — the common case, because the replay path is written as a simple buffer drain and the authorization middleware is attached to the POST router, not the GET/resume router. ## Decision Boundary The decision is not "should resumption be authenticated" — it always should. The decision boundary is **where the scope check lives relative to the buffer**: - *Check-at-ingress-only* (invalid): scope evaluated when the event enters the buffer. Correct for the original delivery, wrong for replay, because the credential that replays may differ from the credential that produced. - *Check-at-egress* (valid): scope evaluated when the event leaves the buffer to a connection, against both the event's recorded provenance and the connection's current credentials. This is the only placement that survives disconnect/reconnect and token rotation. The boundary is crossed the moment a buffer outlives a single connection. A zero-buffer implementation (events delivered only to the live connection, no replay) cannot exhibit this failure; the failure is *introduced by the resumability feature itself*. That is why it is non-obvious: the feature added to improve reliability is the feature that opens the authorization gap. ## Operational Effect When the boundary is crossed, the observable effects are: (a) replayed tool output delivered to under-scoped connections, (b) audit logs that show the original invocation but not the replay delivery, producing an apparent gap between "what was authorized" and "what was received," and (c) in the principal-rotation variant, cross-tenant data exposure scoped only by session ID reuse. Detection is possible by correlating buffer-drain events against the scope set of the draining connection — a check that must be added to the resume router, not the invocation router. Remediation is to attach the authorization middleware to the resume handler and to stamp each buffered event with its provenance at emission time. The following reference implementation encodes the invariant as an enforceable check at the resume boundary. ```python from dataclasses import dataclass, field from typing import Iterable class ResumptionScopeError(RuntimeError): """Raised when a resumed SSE stream would deliver events outside the resuming connection's current authorization scope.""" pass @dataclass(frozen=True) class AuthContext: principal: str scopes: frozenset[str] @dataclass(frozen=True) class BufferedEvent: event_id: int payload: dict provenance: AuthContext # scope set valid when this event was produced @dataclass class SessionBuffer: session_id: str events: list[BufferedEvent] = field(default_factory=list) def append(self, event: BufferedEvent) -> None: self.events.append(event) def resume_stream( buffer: SessionBuffer, last_event_id: int, connection: AuthContext, *, strict: bool = True, ) -> Iterable[BufferedEvent]: """Drain buffered events after last_event_id, enforcing the invariant that each delivered event is covered by BOTH its recorded provenance and the resuming connection's current scope set. strict=True: raise on any event the connection is not entitled to (fail closed, surfaces the boundary crossing). strict=False: drop silently and emit a gap marker (production default for availability). """ if connection.principal is None or not connection.scopes: raise ResumptionScopeError( f"resume denied: connection for session {buffer.session_id!r} " f"has no usable principal/scopes" ) for event in buffer.events: if event.event_id <= last_event_id: continue # The invariant: entitlement is the intersection of provenance and # current credentials. Session identity alone is never sufficient. entitled = ( event.provenance.principal == connection.principal and event.provenance.scopes <= connection.scopes ) if not entitled: if strict: raise ResumptionScopeError( f"event {event.event_id} on session {buffer.session_id!r} " f"was authorized under principal={event.provenance.principal!r} " f"scopes={sorted(event.provenance.scopes)} but resuming " f"connection has principal={connection.principal!r} " f"scopes={sorted(connection.scopes)}" ) # Drop, do not replay. A gap marker preserves stream ordering # without leaking the payload. yield BufferedEvent( event_id=event.event_id, payload={"type": "gap", "reason": "scope_revoked"}, provenance=connection, ) continue yield event def resume_or_fail(buffer: SessionBuffer, last_event_id: int, connection: AuthContext) -> list[BufferedEvent]: """Strict wrapper used by the resume router in test/CI configurations.""" out = list(resume_stream(buffer, last_event_id, connection, strict=True)) if not out: raise ResumptionScopeError( f"resume for session {buffer.session_id!r} produced no deliverable " f"events after id {last_event_id}" ) return out ```