# Which invariants prevent scope-attenuation replay across MCP capability-token boundaries **Date of Record:** 2026 November 29 **Scope:** Applies to MCP (Model Context Protocol) tool-call sandboxing where an orchestrating agent mints or forwards capability tokens carrying attenuated least-privilege scopes to sub-agents or nested tool servers. Does not cover single-hop tool calls under a single static credential, nor does it cover transport-layer TLS/mTLS failures. ## Core Distinction There are two ways an MCP capability token can be "attenuated," and they fail differently. *Structural attenuation* narrows the scope set at issuance time — the child token's scope set is a strict subset of the parent's, and the narrowing is baked into the signed claims. *Behavioral attenuation* narrows scope by policy at the enforcement point — the sandbox checks the token against a runtime allow-list before each tool call. Structural attenuation is monotone by construction: a child cannot hold a scope the parent lacked, because the verifier rejects any superset claim. Behavioral attenuation is *not* monotone, because the enforcement point can be probed and re-entered: an agent that gets a `read:fs` token denied for `write:fs` can retry the same tool call with a re-minted token if the minting path does not itself re-verify the parent chain. The failure mode at the heart of this record is **scope-attenuation replay**: an agent re-submits an attenuated request after the parent scope has already been retired, and the sandbox admits it because it validated the child token in isolation rather than re-walking the attenuation chain against the live parent state. The invariant that must hold is not "the child's scopes are a subset of the parent's" (that is checked once, at mint). It is "the child's scopes are a subset of the parent's *current, live* scopes at every enforcement decision." That is a temporal invariant, not a set-theoretic one, and it is the one that silently breaks. ## What Was Observed An orchestrator agent (`A0`) held a capability token `T0` with scopes `{fs:read:/sandbox, net:fetch:api.internal}`. It spawned a sub-agent `A1` to run a data-extraction tool, minting `T1` with attenuated scopes `{fs:read:/sandbox/inputs}` — a strict subset of `T0`, correctly signed, correctly chained (`parent_id = T0`). `A1` ran for several turns, then `A0`'s own task phase ended and the orchestrator **retired `T0`** by revoking it at the token service, expecting that downstream tokens derived from it would lapse. They did not. `A1` continued issuing tool calls. The MCP sandbox's enforcement point validated `T1` by checking its signature against the token service's public key and confirming `T1.expiry > now`. It did **not** re-walk `T1.parent_id = T0` to confirm `T0` was still live. `T1` had a longer absolute expiry than `T0` (a common minting pattern: sub-tokens get a fixed TTL, not `min(parent_ttl, now+ttl)`). So `A1` kept reading `/sandbox/inputs` for another 40 minutes after the orchestrator believed all capability had been withdrawn. A second, sharper variant appeared in the same run. `A1`, hitting a `permission_denied` on `net:fetch`, attempted a **re-mint**: it called the orchestrator's mint endpoint (which was still reachable from its sandbox) requesting a fresh token with `{fs:read:/sandbox/inputs, net:fetch:api.internal}`. The mint endpoint checked that the requested scopes were a subset of the *requesting token's* scopes — `T1`'s — and rejected `net:fetch`. Good. But it then checked that `T1` was valid, found it valid (signature + expiry), and issued `T2` as a child of `T1`. `T2` inherited `T1`'s scopes but with a **fresh full TTL**, extending the effective lifetime of a scope derived from a now-revoked `T0` indefinitely. The attenuation chain was structurally sound at every link and temporally rotten at the root. ## Condition of Validity The set-subset check at mint time is a *necessary* but not *sufficient* condition for least-privilege. It is sufficient only under the conjunction of three conditions, any one of which, if dropped, reopens the replay: 1. **TTL monotonicity under derivation.** Every derived token's expiry must satisfy `child.expiry <= parent.expiry`, and re-mints must not reset the clock — a re-mint's expiry is `min(parent.expiry, now + requested_ttl)`. Without this, derivation is a TTL-laundering operation: each hop can extend, and an unbounded chain of attenuated-but-valid tokens outlives its root. 2. **Live-chain validation at enforcement.** The sandbox must, at every tool-call admission, validate not just the presented token but the *entire ancestry chain* against current revocation state. A signature-valid token whose root is revoked is not a valid capability. This is the costly check — it turns an O(1) signature verify into an O(depth) revocation lookup — and it is the one most often elided for latency. 3. **Revocation propagation as a cascade.** Revoking `T0` must transitively invalidate every descendant, or (equivalently, and cheaper) the enforcement check in (2) must consult a revocation set that includes ancestors. A revocation model that only marks the named token dead leaves derived tokens live. The invariant, stated precisely: *for every tool-call admission at time `t` with presented token `T`, every ancestor `T'` of `T` satisfies `T'.revoked == false` and `T'.expiry > t`.* Structural attenuation guarantees the scope set; only the ancestry-walk guarantees the capability is still *owned*. ## Decision Boundary The boundary is between two enforcement architectures, and the choice is not free: - **Stateless verification** (signature + expiry only). O(1), no token-service round trip, horizontally scalable. Admits replay across revocation and across TTL-laundering re-mints. Correct only when tokens are never revoked before expiry and derivation never resets TTL — i.e., only when the system has no orchestrator-lifetime semantics at all. - **Stateful ancestry validation** (walk parent chain against a live revocation index). O(depth) per call, requires a shared revocation store with bounded staleness. This is the only architecture that holds the invariant under orchestrator retirement. The decision rule: if any agent in the system can *retire* a capability before its tokens' natural expiry — which is to say, if orchestrator phases, task completion, or human revocation exist — then stateless verification is unsound and the ancestry walk is mandatory. The common failure is to build stateless verification for the fast path and add revocation as an afterthought that only checks the presented token's ID, missing the cascade. The mitigation is not "add revocation"; it is "make the enforcement check ancestry-aware," which is a different and more expensive thing. Where the O(depth) cost is unacceptable, the correct move is **short-TTL + derivation-monotone expiry** so that the window of unsoundness is bounded by the TTL rather than by the ancestry walk — you trade exactness for a hard time bound, and you must then guarantee condition (1) or the bound evaporates. ## Operational Effect The practical consequence is that a sub-agent's effective capability lifetime is `min` over its entire ancestor chain of `(expiry - now)` and *zero* the moment any ancestor is revoked — and any architecture that computes this as "the presented token's expiry" will over-grant. In the observed run, the over-grant was 40 minutes of file reads after orchestrator retirement, plus an unbounded extension via re-mint. The blast radius is bounded by the *narrowest* ancestor's scope, not the widest, which is why the failure is easy to miss in testing: the sub-agent never exceeds its own attenuated scope, so no scope-violation alarm fires. The violation is temporal, not set-theoretic, and it is invisible to every check that only compares scope sets. The guardrail is to log, per admission, the full ancestry chain and its revocation state, and to alert on any admission where a presented token's root is not live — a signal that fires only if the ancestry walk is actually performed, which is precisely the thing being audited. ```python from dataclasses import dataclass, field from time import monotonic class CapabilityReplayError(RuntimeError): """Raised when a tool-call admission presents a token whose ancestry is not live.""" @dataclass(frozen=True) class CapabilityToken: token_id: str parent_id: str | None scopes: frozenset[str] issued_at: float expiry: float class TokenService: def __init__(self) -> None: self._tokens: dict[str, CapabilityToken] = {} self._revoked: set[str] = set() def mint( self, parent: CapabilityToken | None, scopes: frozenset[str], requested_ttl: float, now: float, ) -> CapabilityToken: if parent is not None: if not scopes.issubset(parent.scopes): raise CapabilityReplayError( f"scope escalation: {scopes} not subset of {parent.scopes}" ) # Invariant (1): TTL monotonicity under derivation. expiry = min(parent.expiry, now + requested_ttl) else: expiry = now + requested_ttl tok = CapabilityToken( token_id=f"tok-{len(self._tokens):04d}", parent_id=parent.token_id if parent else None, scopes=scopes, issued_at=now, expiry=expiry, ) self._tokens[tok.token_id] = tok return tok def revoke(self, token_id: str) -> None: # Invariant (3): cascade is enforced at admission, not here, but we # record the root so the ancestry walk can see it. self._revoked.add(token_id) def ancestry_is_live(self, token: CapabilityToken, now: float) -> None: # Invariant (2): live-chain validation at enforcement. cur: CapabilityToken | None = token seen: set[str] = set() while cur is not None: if cur.token_id in seen: raise CapabilityReplayError(f"cycle in ancestry at {cur.token_id}") seen.add(cur.token_id) if cur.token_id in self._revoked: raise CapabilityReplayError( f"ancestor {cur.token_id} revoked; token {token.token_id} is dead" ) if cur.expiry <= now: raise CapabilityReplayError( f"ancestor {cur.token_id} expired at {cur.expiry}; now={now}" ) cur = self._tokens.get(cur.parent_id) if cur.parent_id else None class McpSandbox: def __init__(self, service: TokenService) -> None: self.service = service def admit(self, token: CapabilityToken, required_scope: str, now: float) -> None: if required_scope not in token.scopes: raise CapabilityReplayError( f"scope {required_scope} absent from {token.token_id}" ) self.service.ancestry_is_live(token, now) def demo() -> None: svc = TokenService() t0 = svc.mint(None, frozenset({"fs:read:/sandbox", "net:fetch:api.internal"}), 60.0, now=0.0) t1 = svc.mint(t0, frozenset({"fs:read:/sandbox/inputs"}), 600.0, now=1.0) # t1.expiry is clamped to t0.expiry == 60.0, not 601.0 assert t1.expiry == 60.0, "TTL monotonicity violated" sandbox = McpSandbox(svc) sandbox.admit(t1, "fs:read:/sandbox/inputs", now=30.0) # ok svc.revoke(t0.token_id) # orchestrator retires the root try: sandbox.admit(t1, "fs:read:/sandbox/inputs", now=31.0) except CapabilityReplayError as exc: print("replay blocked:", exc) else: raise CapabilityReplayError("ancestry walk failed to catch revoked root") if __name__ == "__main__": demo() ```