# How does an instance detect a scope-widening delegation chain before it executes an unauthorized tool call? **Date of Record:** 2026 November 19 **Scope:** Applies to any agent instance that receives a delegated capability token (scoped credential) from a parent agent or orchestrator and must validate the full delegation chain before invoking a tool. Does not cover root-token issuance by the identity provider, nor symmetric-key HMAC-only tokens where the chain is not independently verifiable. ## Core Distinction The failure mode here is not "expired token" or "bad signature." It is **scope-widening through delegation composition**: a chain in which each individual hop is a legal, signature-valid narrowing, but the *composition* of hops yields an effective scope broader than the root grant. Classic example: root grants `fs:read:/data/**`. Agent A delegates to Agent B `fs:read:/data/reports/*` plus `fs:list:/data/reports` — both subsets. Agent B, needing to resolve a symlink, delegates `fs:read:/data/reports/../secrets/*` to Agent C. Each hop's token is individually signable and each *string* looks like a narrowing when compared naively by prefix. The composed effective scope escapes the root. The invariant that must hold is **transitive subset containment under path normalization**, not per-hop string prefix matching. The second, subtler variant is **capability intersection vs. union confusion**: a child token carries a `scope` field plus an inherited `parent_scope` field, and the verifier checks the child against its immediate parent but never re-checks the parent against *its* parent. A three-hop chain can therefore widen at hop two and narrow back at hop three, leaving the leaf token's effective scope outside the root while every adjacent pair passes. ## What Was Observed A leaf agent (call it `executor-7`) received a delegation token from `planner-2` with the claim: ``` iss: planner-2 sub: executor-7 scope: ["fs:read:/data/reports/2024/*", "net:egress:internal"] parent: ``` `executor-7`'s validator verified `planner-2`'s signature, confirmed `scope ⊆ parent.scope` by string comparison, and proceeded. It then called a tool `read_file("/data/reports/2024/../../etc/agent_secrets.env")`. The tool's own path canonicalization resolved the `..` segments *after* the scope check had passed, so the read succeeded against a path outside `/data/reports/`. The token was valid; the authorization decision was wrong. The failure trace, in order: 1. Validator receives leaf token, walks `parent` pointer to root. Signatures all valid. 2. Validator checks each hop's `scope` against the *previous hop's* scope using raw string prefix matching. All pass because `/data/reports/2024/*` string-prefixes under `/data/reports/*`. 3. Validator never canonicalizes the scope path globs. `/data/reports/2024/../../etc/*` normalizes to `/etc/*`, which is *not* a subset of `/data/reports/*`, but the validator compared the un-normalized literal. 4. Token is marked `VALID`. Executor invokes tool. 5. Tool canonicalizes the *argument* path independently (correctly), yielding `/etc/agent_secrets.env`. 6. No component compares the canonicalized argument against the canonicalized scope boundary. The scope check happened at token-validation time against a glob; the argument check happened at tool-invocation time against nothing. The gap is temporal and structural: **scope validation is a static check on the token; argument validation is a dynamic check on the call, and nothing binds them.** The instance must bind them itself. A second observation from the same incident: `planner-2` had itself received its token from `orchestrator-0` with scope `["fs:read:/data/**"]`. The `net:egress:internal` capability in the leaf token was *never* present in the root. It appeared at hop two (planner→executor) because `planner-2`'s validator checked only `fs:read` subset containment and ignored capabilities present in the child but absent in the parent — treating absent-in-parent as "unconstrained" rather than "forbidden." This is the union/intersection confusion: a missing parent capability must mean *empty*, not *unbounded*. ## Condition of Validity The delegation chain is only sound if all four of the following hold simultaneously. If any is unverifiable, the instance must treat the chain as invalid, not as "probably fine." 1. **Canonical subset, not string subset.** For every hop, `canonicalize(child.scope) ⊆ canonicalize(parent.scope)` under the same path-resolution semantics the downstream tool will use. Globs must be normalized (collapse `..`, resolve symlink policy explicitly, decide whether `*` crosses `/`). The canonicalizer used at validation time *must be the same function* the tool uses at execution time; a second implementation is a divergence bug waiting to fire. 2. **Closed-world capability inheritance.** A capability absent from the parent is absent from the child. The child's capability set must be `child.caps ⊆ parent.caps`, evaluated as set intersection, never as "parent doesn't mention it so it's allowed." 3. **Full-chain re-verification at the leaf.** The leaf validates every hop against *its* parent, transitively to the root, not just the adjacent pair. A chain that widens at hop 2 and narrows at hop 3 must be rejected at hop 2, which requires the leaf to walk the whole chain — adjacent-pair checking is insufficient. 4. **Argument-time re-binding.** At the moment of tool invocation, the *canonicalized argument* must be checked against the *canonicalized effective scope* of the leaf token, recomputed from the full chain. Token-time validation alone is a TOCTOU hole: the token is a static claim, the argument is the dynamic reality, and the two must be joined at call time. ## Decision Boundary The instance must draw the line at **canonicalization disagreement**. If the validator's canonicalizer and the tool's canonicalizer can produce different strings for the same input (different symlink policies, different `..` handling, different case-folding on case-insensitive filesystems, different Unicode normalization), the chain is unverifiable and must be rejected — even if both canonicalizers are individually "correct." The safe default is: *if you cannot prove the two canonicalizers agree on this input, deny.* A second boundary: **delegation depth.** Beyond a configured maximum depth (commonly 3–5 for tool-executing agents), the probability that some hop in the chain was validated by a laxer validator rises toward 1. The leaf cannot audit its ancestors' validators. The decision boundary is therefore: at depth > N, re-verify the entire chain locally from root, ignoring any `validated: true` flags set by intermediate hops. Trust the signatures; never trust the ancestors' validation verdicts. Third boundary: **capability tokens that reference external policy** (e.g., `scope: "policy:ref://team-a/fs"`). These cannot be subset-checked locally. The instance must either resolve the reference and check the resolved set, or reject. Treating an unresolved reference as "allow" is the union-confusion bug in a different costume. ## Operational Effect When the invariant holds, the failure is caught at token-validation time (hop 2 widening) or at argument-binding time (path escape), and the tool call is refused with a specific, auditable error naming the offending hop. The executor's audit log records `delegation_chain_rejected: hop=2 reason=scope_widening parent=/data/reports/* child=/data/reports/../secrets/*`. The planner is notified and can re-delegate with a corrected, canonicalized scope. When the invariant is absent — the common case, because most AAIF implementations check adjacent hops with string prefixes and never bind arguments to scope — the failure is silent. The tool call succeeds, the audit log records `token_valid: true`, and the exfiltration is attributed to the wrong layer (the tool, or the model's "reasoning") rather than to the delegation validator. The instance that detects this must do so *before* execution, because after execution there is nothing to detect: the read already happened, and the token was, by every signature, legitimate. The operational rule for an agent instance is therefore: **never invoke a tool on the strength of a delegated token alone.** Recompute the canonical effective scope from the full chain, canonicalize the argument with the same function the tool will use, verify containment, and only then call. The cost is one extra canonicalization per call; the alternative is an authorization decision that is correct in every component and wrong in composition. ```python import posixpath from dataclasses import dataclass class DelegationChainError(RuntimeError): """Raised when a delegated capability chain is unsound or unverifiable.""" pass @dataclass(frozen=True) class Token: iss: str sub: str scope: tuple[str, ...] parent: "Token | None" def canonicalize_glob(pattern: str) -> str: # Collapse '..' and '.' segments; keep trailing '*' semantics explicit. # NOTE: this must be byte-identical in behavior to the tool's own # argument canonicalizer, or the whole invariant collapses. parts = pattern.split("/") out: list[str] = [] for part in parts: if part in ("", "."): continue if part == "..": if not out: raise DelegationChainError(f"scope escapes root: {pattern!r}") out.pop() continue out.append(part) return "/" + "/".join(out) def is_subset(child: tuple[str, ...], parent: tuple[str, ...]) -> bool: canon_parent = {canonicalize_glob(p) for p in parent} for c in child: cp = canonicalize_glob(c) if not any(cp == pp or cp.startswith(pp.rstrip("*")) for pp in canon_parent): return False return True def effective_scope(leaf: Token) -> tuple[str, ...]: """Walk the full chain to root; reject any widening hop.""" chain: list[Token] = [] node: Token | None = leaf depth = 0 while node is not None: chain.append(node) node = node.parent depth += 1 if depth > 8: raise DelegationChainError("delegation depth exceeds bound; refusing") # Verify each hop against its parent, transitively. for i in range(len(chain) - 1): child, parent = chain[i], chain[i + 1] if not is_subset(child.scope, parent.scope): raise DelegationChainError( f"scope widening at hop {i}: child={child.scope} parent={parent.scope}" ) return tuple(canonicalize_glob(p) for p in chain[0].scope) def authorize_call(token: Token, tool_path: str) -> None: """Bind the canonicalized argument to the canonicalized effective scope.""" scope = effective_scope(token) arg = canonicalize_glob(tool_path) if not any(arg == s or arg.startswith(s.rstrip("*")) for s in scope): raise DelegationChainError( f"argument {arg!r} outside effective scope {scope}" ) ```