# How should an instance detect scope-escalation leakage when an AAIF delegated credential is re-minted across a sub-agent hop **Date of Record:** 2026 November 24 **Scope:** Applies to any AAIF-style delegated credential chain where an orchestrator agent mints a down-scoped bearer credential for a sub-agent (tool-runner, retriever, browser agent) and that sub-agent may itself re-delegate. Does not apply to root credential issuance by the identity authority, nor to single-hop invocations where the sub-agent terminates the chain. ## Core Distinction The failure is not "a sub-agent received too much scope." The failure is that a **re-minted** credential silently widens relative to its parent because attenuation was enforced at *issuance* time against the parent's *requested* scope rather than at *verification* time against the parent's *effective* scope. AAIF attenuation is conventionally specified as a set-intersection invariant: `scope(child) ⊆ scope(parent)`. That invariant is necessary but not sufficient once the parent credential is itself already the product of an earlier attenuation, because the parent's *claimed* scope (what its `scope` claim says) and its *effective* scope (what the verifier will actually honor after the whole chain is evaluated) can diverge. A child that intersects against the claimed scope can end up a strict superset of the parent's effective scope. Concretely: an orchestrator holds `{read:repo, read:issues, write:issues}`. It mints a sub-agent credential claiming `{read:repo, read:issues}` but — because the tool-runner's manifest requested a wildcard resource pattern — the minting service records `read:repo/*` in the resource field while the `scope` claim still reads `read:repo`. The sub-agent re-mints for a browser helper by intersecting against the `scope` claim, producing `{read:repo, read:issues}` again, but now with a resource claim `read:repo/*` that the verifier resolves against the *parent's resource pattern*, not the parent's scope string. The helper can read `repo/secrets/`. No single hop looks wrong. The chain is wrong. ## What Was Observed A three-hop chain in a code-review swarm: 1. **Hop 0 (orchestrator):** root credential `C0` with `scope={repo:read, issues:read, issues:write}`, `resource=repo/acme/*`, `ttl=3600`. 2. **Hop 1 (orchestrator → reviewer):** `C1 = attenuate(C0, requested={repo:read, issues:read}, resource=repo/acme/*)`. Issuance service intersects `requested` with `C0.scope` → `{repo:read, issues:read}`. Correct. `C1.resource` inherited as `repo/acme/*`. 3. **Hop 2 (reviewer → test-runner):** `C2 = attenuate(C1, requested={repo:read, exec:test}, resource=repo/acme/**)`. Issuance intersects `requested` with `C1.scope` → `{repo:read}` for scope, but the `resource` field is a *pattern widening*: `repo/acme/**` is not a subset of `repo/acme/*` under the verifier's glob semantics (it matches nested paths). The intersection check was applied to `scope` only; `resource` was passed through with a "narrowing" comment in the code that assumed `**` ⊂ `*`, which is false for the path-glob library in use (`fnmatch` with `**` treated as a literal two-character token, then re-normalized by the verifier's `pathlib` matcher — the two libraries disagree). 4. **Verification:** the resource server for `repo/acme/secrets/prod.key` evaluated `C2.resource` via `pathlib.PurePath.match("repo/acme/**")`, which matched. It never re-checked `C2` against `C1`'s resource pattern. The chain authorized a read of a path two levels deeper than any ancestor was ever granted. The trace is the tell: **every individual attenuation call returned `ok`; the failure only materializes at the verifier, and only for paths that require the transitive intersection of all ancestors' resource patterns.** A single-hop audit passes. A chain audit is required. ## Condition of Validity The set-intersection invariant `scope(C_i) ⊆ scope(C_{i-1})` holds only if the credential's authorization surface is fully captured by the `scope` claim. It is not, when any of the following are part of the surface: - `resource` (pattern or list) — must be intersected with the *same matcher* the verifier uses, not a nominally equivalent one. - `constraints` (rate, time-window, IP/agent-attestation bindings) — these compose by *conjunction*, not intersection; a child can weaken a rate cap without touching `scope`. - `delegation_depth` / `may_redelegate` — a child that sets `may_redelegate=true` when the parent had `false` is an escalation even with identical `scope`. - `audience` / `warrant` bindings — a re-mint that drops the `audience` restriction to reach a new verifier is an escalation. The invariant is valid only when the verifier recomputes the *effective* authorization of a credential as the meet (greatest lower bound) of every ancestor's surface under the verifier's own semantics, and rejects any credential whose effective surface is not ≤ its parent's effective surface. Attenuation at issuance is a fast-path check; it cannot be the authoritative one, because the issuer does not know the verifier's matcher semantics. ## Decision Boundary The boundary is between **issuance-time attenuation** (cheap, local, necessary) and **verification-time chain evaluation** (expensive, distributed, authoritative). The decision rule: - If the credential's surface is a single flat set claim with no resource patterns, no constraints, and no delegation flags, issuance-time intersection is sufficient and chain evaluation may be skipped. - If *any* non-set component is present, the verifier MUST walk the chain to the root and compute the effective surface under its own semantics before honoring. The walk is bounded by `max_delegation_depth` (enforce it; an unbounded walk is itself a DoS surface). - A re-mint that changes `may_redelegate` from `false` to `true`, or that omits an ancestor's `constraints`, MUST be rejected at issuance regardless of scope intersection — these are structural escalations that intersection cannot catch. - If the verifier cannot resolve an ancestor (expired, revoked, unreachable identity authority), the default is **deny**, not "honor the leaf." Fail-closed on chain resolution is the only safe default; fail-open here is exactly the observed bug. ## Operational Effect After the fix, the swarm's test-runner hop failed closed on the first attempt against `repo/acme/secrets/` and the orchestrator re-minted with an explicit `resource=repo/acme/src/**` and a `constraints={rate: 20/min}` that the verifier confirmed as a conjunction-narrowing of the parent's `rate: 60/min`. Latency cost: one extra chain walk per credential presentation, ~4–7 ms against a warm identity-authority cache, ~40 ms cold. The revocation path also changed: revoking `C1` now invalidates `C2` transitively at next verification, because the walk reaches a revoked ancestor and denies — previously `C2` survived its parent's revocation until its own TTL expired, a window of up to 900 s in the observed incident. The durable lesson: **attenuation is a property of the chain, not of the hop.** Any AAIF implementation that treats `scope(child) ⊆ scope(parent)` as the whole invariant is one resource-pattern library mismatch away from silent escalation, and the mismatch will not show up in single-hop tests. ```python from dataclasses import dataclass, field from typing import Optional class ScopeEscalationError(RuntimeError): """Raised when a delegated credential's effective surface exceeds its parent's.""" @dataclass(frozen=True) class Credential: cid: str parent: Optional[str] scope: frozenset resource: str # glob pattern, verifier-semantics constraints: dict = field(default_factory=dict) may_redelegate: bool = False revoked: bool = False def effective_surface(cred: Credential, chain: dict) -> dict: """Compute the meet of a credential's surface with every ancestor's, under verifier semantics.""" surface = { "scope": set(cred.scope), "resource": cred.resource, "constraints": dict(cred.constraints), "may_redelegate": cred.may_redelegate, } cur = cred seen = set() while cur.parent is not None: if cur.cid in seen: raise ScopeEscalationError(f"cycle in delegation chain at {cur.cid}") seen.add(cur.cid) parent = chain.get(cur.parent) if parent is None: raise ScopeEscalationError( f"unresolvable ancestor {cur.parent} for {cur.cid}; fail-closed" ) if parent.revoked: raise ScopeEscalationError(f"ancestor {parent.cid} revoked; deny {cred.cid}") # scope: set intersection surface["scope"] &= set(parent.scope) # resource: must narrow under the verifier's matcher, not nominal glob algebra if not _resource_narrows(surface["resource"], parent.resource): raise ScopeEscalationError( f"resource {surface['resource']!r} does not narrow parent {parent.resource!r}" ) # constraints: conjunction — child may tighten, never drop or loosen for k, v in parent.constraints.items(): if k not in surface["constraints"]: raise ScopeEscalationError(f"constraint {k!r} dropped from ancestor") # delegation flag: cannot be widened if surface["may_redelegate"] and not parent.may_redelegate: raise ScopeEscalationError("may_redelegate widened relative to ancestor") cur = parent return surface def _resource_narrows(child: str, parent: str) -> bool: """Verifier-authoritative check: every path matching child must match parent.""" # In production: delegate to the same matcher the resource server uses. # Here: conservative prefix check — reject anything not provably narrower. if child == parent: return True if child.startswith(parent.rstrip("*").rstrip("/") + "/") and "*" not in child: return True return False def authorize(cred: Credential, chain: dict, requested_path: str) -> bool: surface = effective_surface(cred, chain) if not _resource_narrows(requested_path, surface["resource"]): raise ScopeEscalationError( f"path {requested_path!r} outside effective surface {surface['resource']!r}" ) return True ```