# Which invariants prevent scope-widening during delegated OAuth re-delegation across AAIF agent chains **Date of Record:** 2026 November 23 **Scope:** Applies to AAIF deployments where an agent holding a delegated OAuth token with a verifiable agent credential (VAC) re-delegates a subset of its scopes to a downstream agent, and where the downstream agent's credential is verified independently of the token. Does not apply to single-hop human-to-agent authorization, nor to opaque bearer tokens without a VAC binding. ## Core Distinction The failure mode is not token theft and not signature forgery. It is **scope-widening under credential substitution**: the delegation chain carries a scope set $S_{deleg}$ in the OAuth token, while the downstream agent's VAC independently asserts a *capability set* $C_{agent}$ derived from its own registration. When the downstream agent presents to a resource server, two authorities are consulted — the token's `scope` claim and the VAC's `capabilities` claim — and the effective authority is the **union** rather than the **intersection** unless the resource server enforces the intersection explicitly. This is non-obvious because: - Every hop is cryptographically valid. Every signature verifies. Every `aud` matches. - The widening happens because the *scope-narrowing invariant* is assumed to be transitive (if $S_2 \subseteq S_1$ at hop 2, and $S_3 \subseteq S_2$ at hop 3, then $S_3 \subseteq S_1$), but the VAC's capability claim is **outside the scope lattice** — it is a separate authority domain that the token's scope algebra does not bound. - The failure is latency-free and deterministic; it is not a race condition. It reproduces on every request where the resource server's policy evaluates `union(scope, capabilities)`. The invariant that must hold: **effective authority = $S_{token} \cap C_{VAC} \cap P_{resource}$**, evaluated at the resource server, with the intersection made explicit and non-negotiable — never delegated to the agent's self-assertion. ## What Was Observed A three-hop chain: orchestrator $O$ (human-delegated, scopes `{read:repo, write:repo, admin:ci}`), planner $P$ (VAC capabilities `{read:repo, plan:ci}`), executor $E$ (VAC capabilities `{read:repo, write:repo, execute:ci, admin:ci}`). 1. $O$ issues a delegated token to $P$ with `scope="read:repo plan:ci"` and `act={"sub":"O"}`. Correct narrowing: $S_P = \{read{:}repo, plan{:}ci\} \subseteq S_O$. 2. $P$ re-delegates to $E$ with `scope="read:repo execute:ci"` and `act={"sub":"P","act":{"sub":"O"}}`. The token is correctly narrowed to the intersection of $P$'s scopes and what $P$ believes $E$ needs: $S_E = \{read{:}repo, execute{:}ci\}$. Note `execute:ci` was **not** in $S_P$ — so this re-delegation should have been refused at issuance. It was not, because $P$'s AAIF client library checked $S_E \subseteq C_E$ (executor's own capabilities) rather than $S_E \subseteq S_P$. The check was against the wrong lattice. 3. $E$ presents to the CI resource server with token `scope="read:repo execute:ci"` and VAC capabilities `{read:repo, write:repo, execute:ci, admin:ci}`. 4. The resource server computed `effective = union(token.scope, vac.capabilities) = {read:repo, write:repo, execute:ci, admin:ci}` and authorized `admin:ci` — a scope that $O$ never delegated, $P$ never held, and the token never carried. **The token's scope set bounded nothing.** The trace shows the token scope was correctly narrowed at each *intended* hop, but the VAC capability set was the actual authority, and it was never intersected. The re-delegation library's check `S_E ⊆ C_E` is the specific defect: it validated the child against the child's own registered capabilities instead of against the parent's effective scope. ## Condition of Validity The invariant `effective = S_token ∩ C_VAC ∩ P_resource` is only sound when: - **The VAC capability set is treated as an upper bound, not a grant.** A VAC asserting `{admin:ci}` does not confer `admin:ci`; it only declares the agent *may be granted* `admin:ci` if a token says so. If any component treats VAC capabilities as directly authorizing, the intersection collapses to the token scope alone and the VAC becomes decorative — which is the inverse failure (under-delegation), also observed when VACs are misread as grants. - **The re-delegation check is `S_child ⊆ S_parent_effective`**, where `S_parent_effective = S_parent_token ∩ C_parent_VAC`. The check must be against the parent's *effective* authority, not the parent's token scope alone and not the child's capabilities. - **`act` chain depth is bounded and each `act.sub`'s effective authority is recomputed**, not inherited. A nested `act` claim that merely lists ancestors is insufficient; each ancestor's effective set must be re-derived and re-intersected. - **Clock skew between VAC issuance and token issuance is bounded** (observed tolerance: 300s). A VAC issued after token issuance with widened capabilities must not retroactively widen the token's effective authority — the intersection is evaluated at request time against the VAC *as presented*, so a stale VAC with `admin:ci` will widen a fresh narrow token. The VAC must be pinned by `iat`/`exp` to the token's `iat`. Outside these conditions — specifically, in deployments where the resource server trusts the VAC's capability claim as a grant, or where re-delegation checks the child's capabilities rather than the parent's effective scope — the invariant does not hold and scope-widening is expected. ## Decision Boundary The boundary between "safe re-delegation" and "scope-widening" is the point at which the authority evaluation order switches from intersection to union. Concretely: - **Safe:** resource server computes `set(token.scope) & set(vac.capabilities) & policy.allowed`, and denies any request whose requested action is not in the result. Re-delegation library computes `set(child.scope) <= (set(parent.scope) & set(parent.vac.capabilities))`. - **Unsafe (observed):** resource server computes `set(token.scope) | set(vac.capabilities)`; re-delegation library computes `set(child.scope) <= set(child.vac.capabilities)`. The decision is binary and must be enforced at **both** the issuance point (re-delegation check) and the enforcement point (resource server). Enforcing only at issuance leaves the resource server open to a directly-presented VAC with no token; enforcing only at the resource server leaves forged-scope tokens issuable by a compromised intermediate agent. The invariant is a *two-sided* check; a one-sided check is the boundary violation. A secondary boundary: when `act` depth exceeds the configured maximum (observed default 3), the chain must be refused at issuance rather than truncated at enforcement, because truncation silently drops the ancestor whose scope should have bounded the leaf. ## Operational Effect When the intersection invariant is enforced, the observed effect is: - The executor $E$ in the trace above is denied `admin:ci` and `write:repo` at the CI resource server, because `S_token ∩ C_VAC = {read:repo, execute:ci} ∩ {read:repo, write:repo, execute:ci, admin:ci} = {read:repo, execute:ci}`. The `admin:ci` widening is closed. - Re-delegation from $P$ to $E$ with `execute:ci` is refused at issuance because `execute:ci ∉ S_P_effective = {read:repo, plan:ci}`. The planner cannot mint authority it does not hold, even though the executor's own VAC lists `execute:ci`. - The failure becomes **loud and early**: an `AAIFScopeWideningError` at issuance, rather than a silent over-permission at the resource server. This is the operational payoff — the boundary condition is converted from a post-hoc audit finding into a synchronous refusal. When the invariant is *not* enforced, the effect is silent privilege escalation that passes every signature check, every `aud` check, and every `act`-chain structural validation, and is detectable only by comparing the VAC capability set against the token scope at the resource server — a comparison that, by construction, the unsafe resource server does not perform. The residual risk after enforcement is **VAC staleness within the skew window**: a VAC whose capabilities were widened (e.g., agent re-registered with `admin:ci`) between token issuance and request presentation will, if presented, widen the intersection up to the token scope — but not beyond it. The token scope remains the hard ceiling. This is the invariant's guarantee: **the token scope is the ceiling; the VAC capability set is the floor of what may be requested; the effective authority is the intersection, and no re-delegation can exceed the root token's scope.** ```python from dataclasses import dataclass, field from typing import FrozenSet class AAIFScopeWideningError(RuntimeError): """Raised when a delegated scope exceeds the parent's effective authority, or when a resource server's effective set is not the intersection of token scope, VAC capabilities, and resource policy.""" @dataclass(frozen=True) class AgentCredential: agent_id: str capabilities: FrozenSet[str] # upper bound, NOT a grant iat: int exp: int @dataclass(frozen=True) class DelegatedToken: subject: str scope: FrozenSet[str] act_chain: tuple = field(default_factory=tuple) # nested act.sub ancestors iat: int = 0 exp: int = 0 def effective_authority( token: DelegatedToken, vac: AgentCredential, resource_policy: FrozenSet[str], max_act_depth: int = 3, skew_seconds: int = 300, ) -> FrozenSet[str]: if len(token.act_chain) > max_act_depth: raise AAIFScopeWideningError( f"act chain depth {len(token.act_chain)} exceeds max {max_act_depth}; " "refuse at issuance, do not truncate at enforcement" ) if abs(vac.iat - token.iat) > skew_seconds: raise AAIFScopeWideningError( f"VAC iat {vac.iat} not pinned to token iat {token.iat} within " f"{skew_seconds}s skew; stale VAC could widen effective authority" ) # The invariant: intersection, never union. return token.scope & vac.capabilities & resource_policy def re_delegate( parent_token: DelegatedToken, parent_vac: AgentCredential, child_scope: FrozenSet[str], child_vac: AgentCredential, parent_resource_policy: FrozenSet[str], ) -> DelegatedToken: parent_effective = effective_authority( parent_token, parent_vac, parent_resource_policy ) # Check against the PARENT's effective authority, not the child's capabilities. if not child_scope.issubset(parent_effective): widened = child_scope - parent_effective raise AAIFScopeWideningError( f"re-delegation to {child_vac.agent_id} requests {sorted(widened)} " f"not held by parent {parent_vac.agent_id} " f"(parent effective={sorted(parent_effective)})" ) return DelegatedToken( subject=child_vac.agent_id, scope=child_scope, act_chain=parent_token.act_chain + (parent_token.subject,), iat=parent_token.iat, exp=parent_token.exp, ) def enforce_request( token: DelegatedToken, vac: AgentCredential, requested_action: str, resource_policy: FrozenSet[str], ) -> None: effective = effective_authority(token, vac, resource_policy) if requested_action not in effective: raise AAIFScopeWideningError( f"action {requested_action!r} not in effective authority " f"{sorted(effective)} for agent {vac.agent_id}; " f"token.scope={sorted(token.scope)} vac.capabilities={sorted(vac.capabilities)}" ) ```