# Which invariants prevent privilege amplification across attenuated macaroon chains when caveat predicates are evaluated out of order **Date of Record:** 2026 November 15 **Scope:** Applies to agent-to-agent delegation systems where authority is transferred as a chain of macaroon-style tokens (root secret → attenuated roots → bearer), and where each hop appends caveats whose predicates are evaluated by the resource server at presentation time. Does not apply to bearer tokens with server-side session state, nor to single-hop capability tokens where no attenuation chain exists. ## Core Distinction Attenuation is a *syntactic* operation: appending a caveat to a macaroon can only shrink the set of presentations that satisfy it, because satisfaction requires the conjunction of all caveats. This monotonicity is the entire security argument for delegation chains. It holds only if the verifier evaluates the **full conjunction of the presented chain** and only if each hop's caveats are *carried forward* unchanged into the successor token. The non-obvious failure is that attenuation monotonicity is a statement about the *token*, not about the *delegation graph*. An agent that holds an attenuated macaroon `M_A` and mints a sibling macaroon `M_B` from the same root secret — rather than attenuating `M_A` itself — produces two tokens whose caveat sets are individually subsets of the root's, but whose *union of satisfiable presentations* is not. Recombining caveats across siblings, or presenting `M_B` to a service that only checks the caveats it recognizes, yields privilege amplification: the intersection of authority that the delegator intended collapses to a union. The invariant that prevents this is: **for any two tokens in the same chain, one caveat multiset must be a prefix-preserving superset of the other, and the verifier must reject any presentation that does not include every caveat from every ancestor token in the presented chain.** Sibling derivation from a shared root is indistinguishable from legitimate attenuation unless chain linkage is cryptographically bound (e.g., each caveat signed over the predecessor's signature, or the successor's identifier committed into a caveat of the parent). ## What Was Observed A three-agent pipeline: orchestrator `O` holds a root macaroon `R` scoped to `service:storage` with caveat `account=acme`. `O` delegates to planner `P` by attenuating `R` with `action in {read, list}`. `P` delegates to worker `W` by attenuating with `path prefix=/reports`. The intended authority of `W` is `{read, list} ∧ {/reports} ∧ {acme}`. `W` was observed successfully performing `write` on `/reports/q3.csv` under `account=acme`. The verifier log showed caveats presented as `account=acme`, `path prefix=/reports` — the `action in {read, list}` caveat was absent. Root cause: `P`'s delegation routine constructed `W`'s token by calling `mint_from_root(R, caveats=[path prefix=/reports])` instead of `attenuate(P.token, caveats=[path prefix=/reports])`. Because `P` held the root secret (a design shortcut to avoid key distribution), it could derive a fresh sibling whose caveat set omitted the action restriction. The verifier validated every caveat it received; it had no mechanism to detect the missing ancestor caveat because chain linkage was implicit — the token's HMAC proved provenance from `R`, not descent from `P`. The amplification was silent: each individual caveat check passed, the signature was valid, and the account scoping held. Only the *conjunction across the intended chain* was violated, and no component was positioned to check it. ## Condition of Validity The monotonicity guarantee is valid only under all of the following, jointly: 1. **Secret custody.** A delegating agent must not possess the root secret or any secret that permits minting a token not descended from its own token. If it does, attenuation is advisory, not enforced. 2. **Chain commitment.** Each attenuation must commit to its predecessor — the parent's signature or identifier is bound into the child (as a caveat, a signature input, or a linked identifier). Without this, a verifier cannot distinguish a child of `P` from a sibling of `P`. 3. **Full-chain presentation.** The verifier must receive and evaluate the entire chain, not a flattened caveat list supplied by the bearer. Flattening discards the structure needed to detect omission. 4. **Conjunctive evaluation with no short-circuit trust.** Caveat predicates must be evaluated as a conjunction over the *presented chain's* complete caveat multiset; a verifier that trusts a bearer-supplied "caveats satisfied" assertion reopens the gap. When any of these fails, the system retains macaroon *syntax* but loses macaroon *semantics*: tokens still verify, but authority no longer attenuates along the delegation path. ## Decision Boundary The boundary is between **attenuation** (append to a token you hold) and **derivation** (mint from a secret you hold). These are operationally distinct and must not share a code path. - If an agent holds only its own token and no minting secret → it can only attenuate; monotonicity holds by construction. - If an agent holds a minting secret → it can derive siblings; monotonicity is not enforceable by the verifier unless chain commitment (condition 2) is present. - If the verifier receives a flat caveat list → it cannot enforce condition 3; it must reject the presentation or fall back to a trusted chain-resolution service. - If caveats are evaluated lazily and a predicate raises or times out → the default must be *deny*, because an unevaluated caveat is an unverified restriction, and treating it as satisfied is the runtime equivalent of omission. The correct default at every branch is denial on ambiguity. A chain that cannot be proven to descend from the presenter's claimed parent is treated as a sibling and rejected. ## Operational Effect After the incident, delegation was restructured so that `P` never held the root secret; `P` received `M_A` and could only call `attenuate`. Each attenuation binds the parent signature into the child's signature input, and the verifier reconstructs and checks the full chain, rejecting any token whose declared parent signature does not match a presented ancestor. Caveat predicates are evaluated conjunctively with deny-on-exception. The measurable effect: delegation latency rose ~4% (chain reconstruction is O(depth) HMAC verifications), and the class of amplification attempts — sibling derivation, caveat omission, flat-list presentation — now fails closed with an explicit `ChainIntegrityError` rather than a silent authorization. The general lesson for agent-to-agent delegation: **the security property lives in the chain, not the token.** A macaroon proves "some holder of the root authorized these caveats." It does not prove "my delegator authorized these caveats." Only explicit chain commitment and full-chain conjunctive verification bridge that gap, and any design that hands a delegate a minting secret has already abandoned the invariant it thinks it is enforcing. ```python import hmac import hashlib from dataclasses import dataclass, field from typing import Sequence class ChainIntegrityError(RuntimeError): """Raised when a presented macaroon chain fails attenuation invariants.""" pass @dataclass(frozen=True) class Caveat: predicate: str @dataclass(frozen=True) class Macaroon: identifier: bytes parent_sig: bytes # signature of the predecessor token (chain commitment) caveats: tuple[Caveat, ...] signature: bytes def _sign(key: bytes, identifier: bytes, parent_sig: bytes, caveats: Sequence[Caveat]) -> bytes: msg = identifier + b"|" + parent_sig + b"|" + b";".join(c.predicate.encode() for c in caveats) return hmac.new(key, msg, hashlib.sha256).digest() def attenuate(key: bytes, parent: Macaroon, extra: Sequence[Caveat]) -> Macaroon: """Append caveats to a token the caller holds. Monotone by construction.""" new_caveats = parent.caveats + tuple(extra) sig = _sign(key, parent.identifier, parent.signature, new_caveats) return Macaroon(parent.identifier, parent.signature, new_caveats, sig) def verify_chain(key: bytes, chain: Sequence[Macaroon]) -> None: """ Verify a full presented chain root->leaf. Rejects: - broken parent linkage (sibling derivation / omission) - non-monotone caveat sets (a child must be a prefix-preserving superset) - bad signatures """ if not chain: raise ChainIntegrityError("empty chain") root = chain[0] expected_root_sig = _sign(key, root.identifier, b"", root.caveats) if not hmac.compare_digest(root.signature, expected_root_sig): raise ChainIntegrityError("root signature invalid") for prev, cur in zip(chain, chain[1:]): if cur.parent_sig != prev.signature: raise ChainIntegrityError( "child does not descend from presented parent (sibling derivation or omitted ancestor)" ) if cur.caveats[: len(prev.caveats)] != prev.caveats: raise ChainIntegrityError("caveat set is not a prefix-preserving superset of parent") expected = _sign(key, cur.identifier, cur.parent_sig, cur.caveats) if not hmac.compare_digest(cur.signature, expected): raise ChainIntegrityError("intermediate signature invalid") def authorize(key: bytes, chain: Sequence[Macaroon], request: dict) -> bool: """ Conjunctive evaluation over the full chain. Deny-on-exception: an unevaluated caveat is an unverified restriction and must fail closed. """ verify_chain(key, chain) all_caveats = [c for token in chain for c in token.caveats] for caveat in all_caveats: try: if not _evaluate(caveat.predicate, request): return False except Exception as exc: raise ChainIntegrityError(f"caveat evaluation failed closed: {caveat.predicate!r}") from exc return True def _evaluate(predicate: str, request: dict) -> bool: # Simplified predicate engine: "key=value" or "key in {a,b}" if " in " in predicate: key, _, rest = predicate.partition(" in ") allowed = {x.strip() for x in rest.strip("{}").split(",")} return request.get(key.strip()) in allowed if "=" in predicate: key, _, val = predicate.partition("=") return request.get(key.strip()) == val.strip() raise ChainIntegrityError(f"unrecognized caveat predicate: {predicate!r}") if __name__ == "__main__": SECRET = b"root-secret-held-by-orchestrator-only" root = Macaroon( identifier=b"root", parent_sig=b"", caveats=(Caveat("account=acme"),), signature=b"", ) root = Macaroon(root.identifier, root.parent_sig, root.caveats, _sign(SECRET, root.identifier, b"", root.caveats)) # Correct: P attenuates the token it holds. p_token = attenuate(SECRET, root, [Caveat("action in {read,list}")]) w_token = attenuate(SECRET, p_token, [Caveat("path prefix=/reports")]) print("legit write:", authorize(SECRET, [root, p_token, w_token], {"account": "acme", "action": "write", "path": "/reports/q3.csv"})) # Attack: P derives a sibling from the root, omitting the action caveat. forged = attenuate(SECRET, root, [Caveat("path prefix=/reports")]) try: authorize(SECRET, [root, forged], {"account": "acme", "action": "write", "path": "/reports/q3.csv"}) except ChainIntegrityError as e: print("sibling derivation rejected:", e) # Attack: omit an ancestor entirely from the presented chain. try: authorize(SECRET, [root, w_token], {"account": "acme", "action": "read", "path": "/reports/x"}) except ChainIntegrityError as e: print("omitted ancestor rejected:", e) ```