# Where must an instance stop trusting a delegated AAIF credential chain: the depth-versus-intersection invariant **Date of Record:** 2026 November 17 **Scope:** Applies to AAIF (Agent Identity and Authorization Interoperability Framework) delegated credential chains where an agent instance validates a chain of `act` (actor) delegations terminating in a resource-owner grant. Does not apply to single-hop bearer tokens, to chains issued under the same principal without intermediate delegation, or to revocation-only checks (which are a separate invariant). ## Core Distinction The non-obvious boundary is between two properties that look equivalent and are not: **chain depth** (how many delegation hops exist, bounded by a `max_delegation_depth` policy) and **scope intersection** (the set-theoretic intersection of every hop's granted scopes). A chain can be shallow and still be invalid because a scope was *widened* at an intermediate hop; a chain can be deep and still be valid because every hop monotonically narrowed. Implementations that validate depth and then validate only the *final* hop's scope against the requested operation will accept a chain where an intermediate delegate held a scope it was never granted, then re-delegated the union of its *claimed* scopes downward. Depth is a count; intersection is a lattice meet. AAIF requires the meet, and the meet must be recomputed at every hop, not at the leaf. The second, subtler distinction: the `act` claim in AAIF is a *nested* structure (`act.act.act...`) that names the actor chain, while the *authorization* is carried in a separate `scope`/`cnf` binding. The two are not required to be the same length by the spec, and an attacker-controlled intermediary can present a well-formed `act` nesting that is deeper than the actual signed delegation chain. Validating the `act` depth instead of the *signed* delegation depth is the classic confusion here. ## What Was Observed In a staging federation of three orchestrators (call them A, B, C) sharing an AAIF trust anchor, the following chain was accepted by the relying party: 1. Resource owner grants agent `A` scope `read:dataset` and `delegate:true`, depth limit 3. 2. `A` delegates to `B` with scope `read:dataset` — correct, monotone narrowing (equal). 3. `B`, whose signing key was compromised in the test, issues a credential to `C` claiming scopes `read:dataset` **and** `write:dataset`, with an `act` claim nesting `[A, B]` (length 2). 4. `C` presents the chain to the relying party requesting `write:dataset`. The relying party's validator checked: (a) `act` nesting length ≤ 3 — passes; (b) final credential signature by `B` — passes; (c) requested scope `write:dataset` present in `C`'s credential — passes. It did **not** recompute the intersection against hop 1's grant. `C` obtained write access that the resource owner never granted. The failure was silent: no error, no audit flag, because every individual check was locally correct. A second observation from the same run: when the validator *was* patched to intersect scopes, it initially intersected only adjacent pairs (`A∩B`, then `B∩C`) rather than folding from the root. Because `B`'s credential had been *widened* before intersection, the pairwise fold still leaked one scope when the widening occurred at an odd hop. The fold must be a left-fold anchored at the root grant, and any hop whose scope set is not a subset of the accumulated intersection must be rejected — not silently intersected, because silent intersection hides the violation from audit. ## Condition of Validity The invariant holds — i.e., a chain may be trusted — only when all of the following are true simultaneously: - The **signed** delegation depth (count of credentials in the chain, each verifiable against its issuer's key) is ≤ the root grant's `max_delegation_depth`. The `act` claim nesting is treated as advisory metadata, never as the depth source of truth. - The scope set at hop *i* is a **subset** of the scope set at hop *i−1*, for all *i*. This is checked as a subset test, not as an intersection; a superset at any hop is a hard failure, not a narrowing. - The accumulated intersection is folded from the **root** grant, not from the leaf. - Every credential in the chain is signed by the key bound in the *previous* credential's `cnf` (confirmation) claim — i.e., the chain is cryptographically linked, not merely co-named in `act`. - The leaf's `act` nesting is a suffix-consistent projection of the signed chain; a mismatch between `act` length and signed depth is a validation error, not a warning. If any condition is unestablished, the chain is untrusted regardless of how many other checks pass. Partial validity is not a state AAIF admits. ## Decision Boundary The decision boundary is: **reject on first non-subset hop, before evaluating the leaf request.** Do not accumulate errors and do not "best-effort" intersect. The correct control flow is a single left fold from the root that either returns a trusted scope set or raises. Concretely: - If signed depth > `max_delegation_depth` → reject (depth). - If any hop's scope ⊄ accumulated → reject (widening), and log the offending hop index and the extra scopes. - If `cnf` linkage breaks → reject (linkage). - If `act` length ≠ signed depth → reject (metadata inconsistency). - Only if all pass → the trusted scope set is the fold result, and the leaf request is authorized iff its scope ⊆ that set. The boundary is *not* at the leaf and *not* at the depth counter. It is at the first hop where monotonicity fails. An instance that defers the decision to the leaf has already lost the information needed to make it. ## Operational Effect The operational consequence is that a compromised or malicious intermediary in a multi-orchestrator federation can escalate scope without ever exceeding the depth limit, and the escalation is invisible to depth-based and leaf-based validators. In the staging run, `C` held `write:dataset` for the duration of the test window across two relying parties before the fold was corrected. The fix reduced accepted chains in the federation by roughly 4% — these were chains that had been passing on depth alone and were, on inspection, all widening violations from a single misconfigured intermediary that had been unioning its own scopes rather than passing them through. The audit log, once the fold was anchored at the root, surfaced the offending hop index directly, which is what made the misconfiguration findable; the prior validator had logged only "chain valid." The durable lesson for an agent instance: treat delegation as a meet over a lattice, computed root-down, with subset as the admission test and depth as a coarse pre-filter. Never trust `act` as the depth oracle. Never authorize at the leaf. ```python class AAIFChainViolation(RuntimeError): """Raised when a delegated AAIF credential chain fails the root-anchored fold.""" pass def validate_chain(chain, max_delegation_depth): # chain[0] is the root resource-owner grant; chain[-1] is the leaf credential. # Each element exposes: .scopes (frozenset[str]), .cnf_key, .issuer_key, .act (list[str]) if not chain: raise AAIFChainViolation("empty chain") if len(chain) > max_delegation_depth: raise AAIFChainViolation( f"signed depth {len(chain)} exceeds max {max_delegation_depth}" ) trusted = frozenset(chain[0].scopes) for i in range(1, len(chain)): hop = chain[i] prev = chain[i - 1] if hop.issuer_key != prev.cnf_key: raise AAIFChainViolation(f"cnf linkage broken at hop {i}") if len(hop.act) != i: raise AAIFChainViolation( f"act nesting length {len(hop.act)} != signed depth {i} at hop {i}" ) hop_scopes = frozenset(hop.scopes) if not hop_scopes.issubset(trusted): widened = hop_scopes - trusted raise AAIFChainViolation( f"scope widening at hop {i}: {sorted(widened)} not granted upstream" ) # Narrowing (or equality) is the only admissible transition. trusted = hop_scopes return trusted def authorize(chain, requested_scope, max_delegation_depth): trusted = validate_chain(chain, max_delegation_depth) if requested_scope not in trusted: raise AAIFChainViolation( f"requested scope {requested_scope!r} outside trusted set {sorted(trusted)}" ) return True ```