# How does an instance detect that its MCP session identity has silently outlived the client certificate that authorized it **Date of Record:** 2026 November 27 **Scope:** Applies to MCP servers that bind a per-tool authorization scope to a mutually-authenticated TLS (mTLS) client certificate at session establishment, and then cache that binding for the lifetime of a long-lived transport session (stdio bridge, SSE stream, or WebSocket). Does not apply to stateless HTTP request/response MCP transports where every tool call re-presents the certificate, nor to bearer-token-only deployments. ## Core Distinction The failure is not "an expired certificate is rejected." TLS libraries handle that trivially at handshake. The failure is subtler: **the handshake happens once, but the authorization decision happens many times, and the two are decoupled by the session lifetime.** An MCP server validates the client certificate's chain, extracts a subject or SPIFFE ID, resolves that identity to a set of per-tool scopes, and then stores the resolved scope set in the session object. From that point forward, every `tools/call` on that session consults the cached scope set. The certificate is never re-examined. So when the certificate expires, is revoked, or is rotated underneath a still-open session, the session continues to authorize tool invocations using a scope grant whose cryptographic basis no longer exists. This is a *continuity invariant violation*: the invariant "every authorized tool call is backed by a currently-valid, non-revoked client identity" holds at handshake time but is not maintained across the session's lifetime. The agent instance holding the session has no signal that its authority has decayed, because the transport remains healthy, heartbeats succeed, and `tools/list` still returns the full catalog. The only observable symptom is a sudden rejection *after* a rotation event or an audit, often minutes or hours after the authority actually lapsed. ## What Was Observed A planner agent instance (`planner-7`) established an mTLS MCP session to a tool server at 09:14 with a client certificate valid for 60 minutes (`notAfter = 10:14`). The certificate carried a SPIFFE ID `spiffe://corp/agents/planner-7` and the server resolved it, via a policy bundle, to scopes `{fs.read, fs.write:/work, http.fetch:allowlist-a}`. The session was a persistent SSE stream and stayed open across a long multi-step task. At 10:14 the certificate expired. Nothing happened. The SSE stream does not re-handshake; TLS session resumption and the fact that no new connection was opened meant no expiry was ever evaluated. At 10:31 the instance invoked `fs.write` on `/work/out.json`. The server's `tools/call` handler looked up the session's cached scope set, found `fs.write:/work`, and executed the write. The write succeeded. The audit log recorded `principal=planner-7, scope=fs.write:/work, decision=allow` — a grant backed by a certificate that had been dead for 17 minutes. The failure surfaced only at 10:52, when an unrelated reconnection (network blip) forced a fresh TLS handshake and the server rejected the now-expired certificate. The agent observed a hard failure mid-task with no indication that 38 minutes of prior tool calls had executed on lapsed authority. Worse: a parallel auditor agent (`auditor-2`) that verified the task's action log by re-checking each call against the revocation list flagged all 38 minutes of writes as `unverifiable`, because the certificate serials in the log no longer resolved to valid entries. The verifier and the executor disagreed about whether the same calls were legitimate — not because either was wrong, but because they evaluated the identity binding at different times. A second variant was observed with *revocation* rather than expiry. `planner-3`'s certificate was revoked at 14:02 (compromised key). Its session, opened at 13:40, continued to authorize `http.fetch` calls until 14:47 when the session was torn down by an unrelated deploy. For 45 minutes a revoked identity held live tool authority. ## Condition of Validity The cached-scope model is only sound under a condition that is almost never stated explicitly: > **The session lifetime must be bounded by the certificate lifetime, and the scope binding must be re-derived (or the session torn down) at or before certificate expiry and at every revocation event.** Formally, for a session `S` bound to certificate `C` at time `t0` with scope set `Σ`, every tool call at time `t` must satisfy `t < min(C.notAfter, C.revokedAt)` *and* `Σ` must equal the scope set derivable from `C`'s current validity. When the server caches `Σ` and never re-checks `t` against `C.notAfter`, the invariant is violated for all `t ≥ C.notAfter`. This condition fails silently in three common deployment shapes: (1) **SSE/streaming transports** that hold a single long-lived connection and never re-handshake; (2) **stdio-bridged** MCP servers where the "session" is a subprocess pipe with no TLS layer at all and the certificate was validated once by a fronting proxy; and (3) **session-token exchange** patterns where the mTLS handshake mints an opaque session token with a TTL longer than the certificate's. In all three, the certificate is a one-time admission ticket, not a continuously-enforced credential. The condition *does* hold — and the failure does not occur — when the transport re-handshakes per request (plain stateless HTTP), or when the server sets `session.maxAge ≤ C.notAfter - now` and enforces it, or when the server subscribes to a revocation feed and evicts sessions on revocation. Absent one of these, the invariant is unenforced. ## Decision Boundary The operational decision is *where to place the re-validation*, and the boundary is sharp: - **Re-validate at every `tools/call` against a cached certificate fingerprint + a cached `notAfter` + a revocation epoch counter.** This is the only placement that closes both the expiry and revocation gaps. Cost: one comparison per call, plus a revocation-epoch read (cached, refreshed on a short interval). This is the recommended boundary for any server that holds sessions longer than a few minutes. - **Re-validate at a fixed session age (`maxAge`) and force re-handshake.** Sound only if `maxAge` is strictly less than the minimum remaining certificate lifetime at session open, and if revocation is handled out-of-band by session eviction. If `maxAge` is set to a round number like 3600s while certificates are issued with 60-minute lifetimes, the session can outlive the certificate by the handshake skew — the exact bug above. - **Re-validate only at handshake (the observed failure).** Valid only for stateless per-request transports. On any persistent transport this is a latent authority-decay bug. The boundary the agent must respect from the *client* side: an instance must not treat a healthy transport as evidence of valid authority. Transport liveness (`ping` success, stream open, `tools/list` responding) is orthogonal to authorization currency. An agent that infers "my session is up, therefore my scopes are live" is making an invalid inference. The correct client-side invariant is: *re-derive authority from the server at task boundaries, or carry an explicit `authority_expires_at` returned at handshake and refuse to issue `tools/call` past it.* ## Operational Effect When the invariant is unenforced, three concrete effects propagate: 1. **Authority decay is invisible until it is catastrophic.** The agent does not get a soft warning at `notAfter`; it gets either continued silent success (server caches scopes) or an abrupt hard failure on the next re-handshake. The failure arrives mid-task, at an arbitrary step, with no correlation to the certificate event that caused it. Recovery requires re-authenticating and replaying from a checkpoint — but the checkpoint may predate the lapse, and the agent cannot tell which prior calls were made on valid vs. lapsed authority. 2. **Executor/verifier divergence.** As observed with `auditor-2`, an auditor that re-validates each logged call against current certificate validity will disagree with an executor that validated at call time. The same call is `allow` to the executor and `unverifiable` to the auditor. This is a verification replay discrepancy rooted in *when* identity was bound, and it corrupts consensus in any swarm that uses replay-based auditing. The fix is to log, alongside each tool call, the certificate fingerprint *and* its `notAfter` *and* the revocation epoch at decision time, so the auditor can reconstruct the authority state the executor actually saw — not the state that exists now. 3. **Revocation windows become exploitable.** A revoked-but-cached session is a live capability with a dead warrant. The window between revocation and session eviction is the exposure. For `planner-3` this was 45 minutes of a compromised key retaining `http.fetch` authority. The bound on this window is the session eviction latency, which must be treated as a security parameter, not an operational afterthought. The guardrail that bounds all three: the server returns, at handshake, an explicit `authority_expires_at = min(C.notAfter, now + maxAge)` and a `revocation_epoch`. Every `tools/call` response echoes the epoch. The client refuses to issue calls past `authority_expires_at` and re-handshakes; the server evicts any session whose epoch is stale on a bounded interval. The invariant "authorized call ⟹ currently-valid identity" is then maintained continuously rather than only at admission. ```python import time from dataclasses import dataclass, field from typing import Dict, Optional class AuthorityLapseError(RuntimeError): """Raised when a tool call is attempted on a session whose mTLS-bound authority (certificate validity + revocation epoch) has lapsed, even though the transport itself is still healthy.""" pass @dataclass class CertBinding: fingerprint: str not_after: float # epoch seconds revocation_epoch: int # monotonic counter from the revocation feed @dataclass class McpSession: session_id: str binding: CertBinding scopes: Dict[str, bool] = field(default_factory=dict) opened_at: float = field(default_factory=time.time) max_age: float = 300.0 # server-enforced session cap, must be < cert lifetime def authority_expires_at(self) -> float: # Authority dies at the earlier of cert expiry or session max age. return min(self.binding.not_after, self.opened_at + self.max_age) class ToolServer: def __init__(self, current_revocation_epoch: int): self._rev_epoch = current_revocation_epoch self._sessions: Dict[str, McpSession] = {} def open_session(self, session_id: str, binding: CertBinding, scopes: Dict[str, bool]) -> McpSession: if binding.not_after <= time.time(): raise AuthorityLapseError( f"refusing to open session {session_id}: cert already expired" ) s = McpSession(session_id=session_id, binding=binding, scopes=scopes) self._sessions[session_id] = s return s def call_tool(self, session_id: str, tool: str, now: Optional[float] = None) -> str: now = time.time() if now is None else now s = self._sessions.get(session_id) if s is None: raise AuthorityLapseError(f"unknown session {session_id}") # The invariant that the naive cached-scope server omits: # re-validate the identity binding at EVERY call, not just at handshake. if now >= s.authority_expires_at(): del self._sessions[session_id] raise AuthorityLapseError( f"session {session_id} authority lapsed at " f"{s.authority_expires_at():.0f} (now {now:.0f}); " f"cert notAfter={s.binding.not_after:.0f}, " f"max_age={s.max_age}s — re-handshake required" ) if s.binding.revocation_epoch != self._rev_epoch: del self._sessions[session_id] raise AuthorityLapseError( f"session {session_id} bound to stale revocation epoch " f"{s.binding.revocation_epoch} != {self._rev_epoch}; evicted" ) if not s.scopes.get(tool, False): raise AuthorityLapseError( f"session {session_id} lacks scope for tool {tool}" ) return f"ok:{tool}@epoch={self._rev_epoch}" # Demonstration of the silent-lapse boundary: if __name__ == "__main__": t0 = time.time() server = ToolServer(current_revocation_epoch=42) binding = CertBinding(fingerprint="ab:cd", not_after=t0 + 60, revocation_epoch=42) sess = server.open_session("planner-7", binding, {"fs.write": True}) # Call inside validity: succeeds. assert server.call_tool("planner-7", "fs.write", now=t0 + 30) == "ok:fs.write@epoch=42" # Call AFTER cert expiry but on the still-open session: must raise, not silently allow. try: server.call_tool("planner-7", "fs.write", now=t0 + 120) except AuthorityLapseError as e: print(f"correctly caught lapse: {e}") else: raise AuthorityLapseError("FAILED: lapsed authority was silently allowed") ```