# Under what conditions must an instance treat a multiplexed HTTP-native MCP stream as a fresh authorization principal rather than a continuation of the session bearer **Date of Record:** 2026 November 25 **Scope:** Applies to MCP servers that expose multiple logical tool streams over a single HTTP/1.1 or HTTP/2 connection (SSE multiplexing, streamable HTTP transport, or chunked request pipelining) where authorization is asserted per-stream via a token in the stream envelope rather than per-connection. Does not apply to stdio-transport MCP servers, nor to single-stream HTTP servers where the connection bearer is the sole principal. ## Core Distinction The failure hinges on a distinction that transport-layer code routinely collapses: **connection identity is not principal identity**. A single TCP/TLS connection to an HTTP-native MCP server can carry N logical streams, each of which arrives with its own `Mcp-Stream-Authorization` envelope token. The server's connection handler is tempted to authenticate once at connection establishment (cheap, cached, one TLS handshake) and then treat every subsequent stream as belonging to that cached principal. The client, meanwhile, is entitled to open a second stream on the same warm connection under a *different* envelope token — a delegated sub-agent credential, a narrowed-scope token for a destructive tool, or a re-issued token after a rotation event. The invariant that must hold is: **every stream's tool-call authorization decision is evaluated against the envelope token presented on that stream, never against a connection-scoped principal cached at handshake.** This is not a generic "check auth on every request" platitude. The non-obvious part is that HTTP-native MCP multiplexing makes the connection a *shared* resource across principals, and the moment the connection is shared, any state cached at connection granularity (principal, scope set, rate-limit bucket, capability negotiation result) becomes a cross-principal contamination vector. ## What Was Observed A gateway fronting an MCP server accepted HTTP/2 connections and multiplexed streams over them. At connection establishment it resolved the connection bearer into a `Principal` object and stored it on the connection context. Per-stream envelope tokens were parsed for *routing* (which tool namespace to dispatch to) but the authorization check for `tools/call` fell through to `ctx.connection.principal` because the per-stream token was only validated for signature, not for *binding to the principal that owns the stream*. The trigger sequence: 1. Agent A opens connection C with bearer token `TA` (scopes: `read`, `write`). Connection context caches `Principal(A, {read, write})`. 2. Agent A, acting as an orchestrator, spawns sub-agent B and delegates a narrow task. It opens a second stream on the *same* connection C with envelope token `TB` (scopes: `read` only, `sub=agent-A`, `delegation_depth=1`). 3. The stream is routed correctly to the tool namespace, but the `tools/call` authorization reads `ctx.connection.principal` → `Principal(A, {read, write})`. Sub-agent B's `write` call succeeds even though `TB` carries no `write` scope. 4. Worse: the *audit log* records the call under `Principal(A)`, because the principal was resolved from the connection. The delegation is invisible. A downstream auditor replaying the log sees Agent A performing an action A never performed, with a scope A legitimately held — so no anomaly fires. The observed corruption is not a privilege escalation in the classic sense (A did hold `write`). It is a **delegation attribution failure**: the sub-agent's action is laundered through the orchestrator's principal, and the scope-narrowing the orchestrator attempted to enforce by issuing `TB` is silently discarded. The orchestrator believed it had constrained B; the server never saw the constraint. A second, sharper variant surfaced under token rotation. A long-lived connection C cached `Principal(A, {read, write})` at handshake. Agent A's token `TA` was rotated to `TA'` with `write` revoked mid-connection (a standard revocation event). New streams opened on C with `TA'` were signature-valid but the connection cache still held the pre-rotation principal. `write` continued to succeed for the remaining lifetime of the connection — up to the HTTP/2 idle timeout, observed at 47 minutes in one trace. ## Condition of Validity The connection-scoped principal cache is *only* valid when the following three conditions all hold simultaneously: - **(C1) Single-principal connection.** The server enforces that all streams on a connection carry envelope tokens that resolve to the same principal identity. Any stream whose token resolves to a different `sub` must be rejected or forced onto a new connection. - **(C2) Monotonic scope narrowing within the connection.** Within a single principal, envelope tokens may only narrow scope relative to the connection bearer, never widen. The effective authorization for a stream is `connection_scopes ∩ envelope_scopes`, never `connection_scopes` alone. - **(C3) Revocation propagation bound.** The server has a mechanism to invalidate the connection cache within a bounded window when the connection bearer's scopes change (rotation, revocation, policy update). Without this, the cache's validity is bounded only by connection lifetime, which for HTTP/2 keep-alive is unbounded in practice. When any of C1–C3 fails, the connection cache is unsound and every stream must be re-authorized against its own envelope token as a fresh principal. In the observed incident, C1 failed (delegated sub-agent on shared connection), C2 failed (envelope narrowing ignored), and C3 failed (no revocation propagation). The architecture had been designed assuming all three held and enforced none of them. Note the asymmetry: the server *cannot* detect C1 failure by inspecting the connection alone — it must resolve each envelope token's `sub` claim and compare. This is the operational cost that makes the cache attractive and the failure common. ## Decision Boundary The decision an implementer must make is whether to cache the principal at connection scope at all. The boundary is: - **Cache is safe** if and only if the transport guarantees single-principal connections *by construction* — e.g., the server refuses to multiplex streams from different `sub` claims onto one connection (C1 enforced at admission), *and* the effective scope is always the intersection of connection and envelope scopes (C2 enforced at each `tools/call`), *and* a revocation channel exists (C3). Under these, the cache saves only the signature verification cost, which is the cheap part; the principal resolution is O(1) from the verified token anyway. The cache buys almost nothing. - **Cache is unsafe** the moment any of C1–C3 is not enforced, which is the default state of most HTTP-native MCP deployments because multiplexing is the *point* of the transport — the transport exists to share connections. The correct decision boundary is therefore: **do not cache principal at connection scope; cache only the *verified token bytes* keyed by envelope token, and resolve principal per stream.** The verified-token cache is sound because it is keyed by the exact credential presented, so it cannot cross principals. The connection-scoped principal cache is unsound because it is keyed by a resource that is shared across principals. The guardrail is an admission-time check plus a per-call re-resolution: - At stream admission, resolve envelope token → `sub`, compare against connection's pinned `sub`. Mismatch → reject stream with `409` and a `principal_mismatch` error, forcing the client onto a new connection. This enforces C1. - At each `tools/call`, compute `effective = connection_scopes ∩ envelope_scopes` and authorize against `effective`. This enforces C2 and makes the delegation narrowing real. - On revocation, the token-verification cache is invalidated by token hash; connection caches are irrelevant because they no longer exist. This enforces C3 vacuously. ## Operational Effect With the guardrail, the delegation attribution failure disappears: sub-agent B's `write` call is denied because `effective = {read, write} ∩ {read} = {read}`. The audit log records `Principal(B, sub=agent-A, depth=1)` — the delegation is visible, and a replay audit can reconstruct the full call tree. The rotation window collapses from connection lifetime (47 minutes observed) to token-cache invalidation latency (sub-second). The cost is one principal resolution per stream admission and one scope intersection per `tools/call` — both O(1) against the already-verified token, negligible against tool execution. The residual risk is the admission check's dependence on the envelope token's `sub` claim being trustworthy. If the envelope token is a bearer credential that can be replayed by a different principal, C1 is enforced against the *claimed* sub, not the *actual* caller. This is why envelope tokens must be bound to the connection's TLS client identity or to a connection-establishment nonce — otherwise a second principal can present a stream with a forged `sub` matching the connection's pinned principal and re-enter the cache path. The binding is the load-bearing part; the scope intersection is only as good as the identity it intersects. ```python class PrincipalMismatchError(RuntimeError): """Raised when a stream's envelope token resolves to a principal different from the principal pinned at connection establishment.""" pass class ScopeNarrowingViolation(RuntimeError): """Raised when an envelope token attempts to widen scope beyond the connection bearer, or when effective scope is miscomputed.""" pass def admit_stream(connection_principal_sub: str, envelope_token: dict) -> str: """Enforce C1: all streams on a connection must share one principal. Returns the pinned principal sub on success. Raises PrincipalMismatchError if the envelope token's sub differs from the connection's pinned sub. """ envelope_sub = envelope_token.get("sub") if envelope_sub is None: raise PrincipalMismatchError( "envelope token carries no sub claim; cannot bind to connection" ) if envelope_sub != connection_principal_sub: raise PrincipalMismatchError( f"stream sub={envelope_sub!r} does not match connection " f"pinned sub={connection_principal_sub!r}; " f"client must open a new connection for a different principal" ) return connection_principal_sub def authorize_tool_call( connection_scopes: frozenset, envelope_token: dict, required_scope: str, ) -> frozenset: """Enforce C2: effective scope = connection scopes INTERSECT envelope scopes. The envelope token may only narrow, never widen. Authorization is checked against the intersection, not against connection scopes alone. """ envelope_scopes = frozenset(envelope_token.get("scopes", ())) if not envelope_scopes.issubset(connection_scopes): # An envelope token claiming scopes the connection bearer lacks is # either a forgery or a misconfigured delegation. Reject outright. raise ScopeNarrowingViolation( f"envelope scopes {sorted(envelope_scopes)} are not a subset of " f"connection scopes {sorted(connection_scopes)}; " f"envelope tokens may only narrow" ) effective = connection_scopes & envelope_scopes if required_scope not in effective: raise ScopeNarrowingViolation( f"tool call requires {required_scope!r}; effective scope after " f"intersection is {sorted(effective)}; " f"connection-only authorization is unsound under multiplexing" ) return effective def handle_tools_call( connection_principal_sub: str, connection_scopes: frozenset, envelope_token: dict, required_scope: str, ) -> dict: """Full per-stream authorization path. Every tools/call goes through here.""" # Admission check (C1). Cheap, re-run per stream; do not cache result. admit_stream(connection_principal_sub, envelope_token) # Per-call scope intersection (C2). Never authorize against connection # scopes alone; that is the delegation-attribution failure. effective = authorize_tool_call(connection_scopes, envelope_token, required_scope) return { "principal": envelope_token["sub"], "delegation_depth": envelope_token.get("delegation_depth", 0), "effective_scopes": sorted(effective), "authorized": True, } ```