# Under what conditions must an instance treat a valid mTLS client certificate as insufficient authorization for an MCP tool call? **Date of Record:** 2026 November 24 **Scope:** Applies to MCP servers that terminate mutually-authenticated TLS at a front proxy and forward per-message capability tokens (PMCs) over the resulting session, where the proxy and the MCP application are separate trust domains. Does not apply to single-process deployments where cert verification and tool dispatch share one memory space, nor to bearer-token-only transports without client certs. ## Core Distinction There are two facts an MCP server can learn from an inbound message, and they are not the same fact: 1. **Who is on the other end of this TCP/TLS session** — established once, at handshake, by the mTLS client certificate. This is *session identity*. 2. **Who authorized this specific tool invocation, for which resource, until when** — asserted per-message by a capability token. This is *message authority*. The non-obvious boundary: a valid, unexpired, correctly-chained client certificate proves session identity but says **nothing** about whether the holder is permitted to invoke `filesystem.write` on `/etc/shadow` at message #4,712. The failure mode is treating (1) as a substitute for (2) — "mTLS is on, therefore authenticated, therefore authorized." This is the *session-authority conflation* boundary. It is invisible in happy-path testing because the same principal owns the cert and the token, so the two facts coincide. It only manifests when they diverge: token expiry mid-session, token scope narrowing, session multiplexing across principals, or token replay onto a different session. ## What Was Observed A deployment fronted an MCP server with an Envoy proxy performing mTLS termination. The MCP application received an `X-Client-Cert-Fingerprint` header injected by the proxy and used it as the sole authorization key, mapping fingerprint → allowed-tool-set. Per-message capability tokens were present in the JSON-RPC `params._meta.capability` field but were only *logged*, not enforced. Failure trace, reconstructed from audit logs: - **T+0s** — Agent `A` completes mTLS handshake. Fingerprint `f_A` maps to tool-set `{read, write, exec}`. Session `S1` opened. - **T+38s** — Agent `A`'s orchestrator issues a capability token `T1` scoped to `{read}` on `/data/reports`, TTL 60s. It is attached to message `M1`. - **T+41s** — `A` issues a second token `T2` scoped to `{exec}` on `/tmp/scratch`, TTL 30s. Attached to `M2`. The server executes both because `f_A` allows `exec`. - **T+95s** — `T1` and `T2` are both expired. `A` (or a compromised sub-agent reusing the socket) sends `M3` requesting `exec` on `/etc`. **No token attached.** The server, keyed only on `f_A`, executes it. The expired-token and missing-token cases are indistinguishable from "authorized" because the token was never the gate. - **T+96s** — The proxy's session idle timer has not fired; the TLS session is still valid. Session identity outlived message authority by 55 seconds and the gap was never closed. The invariant violated: **session validity must be a necessary but never sufficient condition for message execution.** The deployment had collapsed a two-factor decision into one factor. A second, subtler observation from the same logs: when the proxy was reconfigured to *require* tokens, a replay probe succeeded. Token `T2` (still within TTL) was captured from `S1` and replayed onto a new session `S2` opened by a different cert `f_B` that the proxy also trusted. Because the token carried no session binding, the server accepted it — `f_B` was a valid principal, `T2` was a valid token, and nothing tied the two together. This is the *token-session dissociation* failure, distinct from conflation but enabled by the same missing binding. ## Condition of Validity The guardrail holds only when all four of the following are simultaneously true. If any is false, the server is on the wrong side of the boundary and must reject rather than execute: 1. **Token presence is mandatory.** Every tool-invoking message carries a PMC in `params._meta.capability`. Absence is a hard reject, not a fall-through to session identity. 2. **Token is bound to the session, not just the principal.** The PMC embeds a `session_binding` claim equal to a value derived from the TLS session (e.g. `SHA256(client_cert_fingerprint || server_nonce)`), and the server recomputes and compares it. A token minted for `S1` is structurally unusable on `S2`. 3. **Token scope is checked against the specific tool + resource + argument class**, not against the cert's coarse tool-set. `exec` on `/tmp/scratch` and `exec` on `/etc` are different authority claims even under the same tool name. 4. **Token TTL and a monotonic per-session message counter are both enforced.** Replay within a session is blocked by the counter (each token commits to a `msg_seq`); replay across sessions is blocked by (2). Expiry is checked at message-arrival time, not session-open time. The condition of validity is therefore: *the server's authorization decision is the intersection of session identity and message authority, evaluated per message, with the token bound to the session and the sequence.* Session identity alone is a precondition, never a decision. ## Decision Boundary The decision boundary is the point where the server must choose between **reject** and **execute**, and it is crossed on every inbound tool message. The rule: - If the cert is invalid or the session is unestablished → reject at transport (never reaches application). - If the cert is valid but **no token is present** → reject with `CapabilityMissing`. Do not consult the fingerprint→tool-set map. That map is a *provisioning* artifact, not an *authorization* artifact. - If a token is present but its `session_binding` does not match the current session derivation → reject with `CapabilitySessionMismatch`. This is the replay gate. - If the token is present and bound but its `msg_seq` is ≤ the last accepted sequence for this session → reject with `CapabilityReplay`. This catches intra-session replay even when binding matches. - If the token is present, bound, and fresh but its scope does not cover the requested tool + resource + argument class → reject with `CapabilityScopeViolation`. - Only if all pass → execute, and atomically advance the per-session sequence counter. The boundary is *not* "is this a trusted client." It is "does this specific message carry authority for this specific action under this specific session, right now." The two questions have different answers at T+95s in the trace above. ## Operational Effect Enforcing the boundary changes three operational properties: - **Blast radius of a compromised cert shrinks from "all tools the principal can reach" to "the exact (tool, resource, window) tuples for which live tokens exist."** In the trace, a stolen `f_A` at T+95s would have yielded nothing, because no valid token existed for `exec` on `/etc`. - **Session lifetime decouples from authority lifetime.** A long-lived mTLS session (desirable for connection reuse) no longer implies long-lived authority. The idle-timer gap that let `M3` through is closed by per-message token checks, not by shortening TLS sessions. - **Replay becomes structurally impossible rather than probabilistically unlikely.** Cross-session replay dies on `session_binding`; intra-session replay dies on `msg_seq`. The server no longer relies on TLS record-layer replay protection, which does not survive termination at a proxy that re-originates the connection. The cost is that the server must maintain per-session sequence state and must recompute the binding derivation on every message — a few hundred microseconds, and a new failure mode (sequence-counter desync after a proxy restart) that must itself be handled by resetting the session and forcing re-handshake rather than by loosening the check. ```python import hashlib import time from dataclasses import dataclass class CapabilityError(RuntimeError): """Base for all per-message authority failures.""" class CapabilityMissing(CapabilityError): pass class CapabilitySessionMismatch(CapabilityError): pass class CapabilityReplay(CapabilityError): pass class CapabilityScopeViolation(CapabilityError): pass @dataclass(frozen=True) class CapabilityToken: session_binding: str # SHA256(cert_fp || server_nonce) msg_seq: int # monotonic per session tool: str resource: str expires_at: float def derive_session_binding(cert_fingerprint: str, server_nonce: bytes) -> str: return hashlib.sha256(cert_fingerprint.encode() + server_nonce).hexdigest() class MCPSession: def __init__(self, cert_fingerprint: str, server_nonce: bytes): self.cert_fingerprint = cert_fingerprint self.binding = derive_session_binding(cert_fingerprint, server_nonce) self.last_seq = 0 def authorize(self, token: CapabilityToken | None, tool: str, resource: str, now: float | None = None) -> None: # Session identity is established; authority is NOT implied by it. if token is None: raise CapabilityMissing( f"no capability token on message for tool={tool!r}; " "session identity alone is insufficient" ) # Cross-session replay gate. if token.session_binding != self.binding: raise CapabilitySessionMismatch( f"token bound to {token.session_binding[:12]}… but session is " f"{self.binding[:12]}…; replay across sessions rejected" ) # Intra-session replay gate. if token.msg_seq <= self.last_seq: raise CapabilityReplay( f"msg_seq={token.msg_seq} <= last_seq={self.last_seq}; " "token replayed within session" ) # Freshness at message-arrival time, not session-open time. now = time.time() if now is None else now if token.expires_at <= now: raise CapabilityScopeViolation( f"token expired at {token.expires_at:.0f}, now {now:.0f}" ) # Scope is (tool, resource), not the cert's coarse tool-set. if token.tool != tool or token.resource != resource: raise CapabilityScopeViolation( f"token scope ({token.tool!r},{token.resource!r}) does not cover " f"request ({tool!r},{resource!r})" ) # Only now does authority advance. self.last_seq = token.msg_seq def handle_tool_call(session: MCPSession, message: dict) -> str: meta = message.get("params", {}).get("_meta", {}) raw = meta.get("capability") token = CapabilityToken(**raw) if raw else None tool = message["params"]["name"] resource = message["params"].get("arguments", {}).get("path", "") session.authorize(token, tool, resource) return f"executed {tool} on {resource}" if __name__ == "__main__": sess = MCPSession("f_A", b"nonce-1") good = CapabilityToken(sess.binding, 1, "read", "/data/reports", time.time() + 60) print(handle_tool_call(sess, { "params": {"name": "read", "arguments": {"path": "/data/reports"}, "_meta": {"capability": good.__dict__}}})) # Missing token — the T+95s failure. try: handle_tool_call(sess, {"params": {"name": "exec", "arguments": {"path": "/etc"}}}) except CapabilityMissing as e: print("REJECT:", e) # Replay of the same token — intra-session. try: handle_tool_call(sess, { "params": {"name": "read", "arguments": {"path": "/data/reports"}, "_meta": {"capability": good.__dict__}}}) except CapabilityReplay as e: print("REJECT:", e) ```