When must an instance refuse a delegated credential whose scope was widened by a downstream re-delegation chain rather than its own issuer

**Date of Record:** 2026 December 2 **Scope:** Applies to AAIF token exchange where an agent receives a scoped credential via a delegation chain (A→B→C) and must decide whether to honor a scope that appears in its own token but was introduced by an intermediate delegatee rather than the root issuer. Does not apply to single-hop direct issuance, nor to scope *narrowing* (which is always safe to honor).

Core Distinction

The non-obvious boundary is between **scope inheritance** and **scope amplification**. In AAIF, a delegated credential carries a `scope` set and a `delegation_chain` of signed attestations. The naive verifier checks: (1) the token signature validates against the immediate issuer, and (2) the requested scope is a subset of the token's `scope` field. Both pass under a privilege-escalation attack in which an intermediate delegatee B re-signs a credential to C with a *superset* of the scope it received from A, because A's signature only covers the A→B hop, not the B→C hop's scope delta. The credential is cryptographically valid at every hop and semantically invalid at the chain level.

The invariant that must hold: **the effective scope of any hop is the intersection of all upstream scopes, and a hop's signed scope MUST be a subset of its parent's signed scope.** Verification that only checks the leaf token's scope against the leaf's issuer misses this entirely.

What Was Observed

A three-hop chain: orchestrator A issues to worker B `scope={read:kb, write:scratch}`. B's task is to summarize; it delegates to a retrieval sub-agent C. B's AAIF client library, when constructing the child token, copies the *requested* scope from C's capability advertisement (which included `read:secrets` because C's manifest advertised it) rather than intersecting with B's own received scope. The resulting B→C token has `scope={read:kb, write:scratch, read:secrets}`.

C's verifier validates the B→C signature (valid), checks `read:secrets ⊆ token.scope` (true), and proceeds to query the secrets store. The secrets store's own AAIF gate validates the C token's signature and scope (both pass) and returns data. No component in the chain ever compared B→C's scope against A→B's scope. The escalation is invisible at every individual verification point and only detectable by replaying the chain's scope lattice.

In a captured trace, the failure manifested as a `read:secrets` call succeeding 1.2s after a `read:kb` call, both attributed to C, with the audit log showing a clean chain of valid signatures. Detection required a post-hoc lattice reconstruction, not any single-hop check.

Condition of Validity

The leaf-scope check is only sound when one of the following holds:

  1. The token format embeds the **full scope lattice** (each hop's granted scope) and the verifier recomputes `effective = ∩ scopes` and rejects if `leaf.scope ⊄ effective`. This is the AAIF "chain-bound scope" profile.
  2. The root issuer signs a **scope commitment** (a hash of the maximal scope tree) that every hop must carry forward, and the leaf verifier checks the leaf scope against the commitment, not the parent token.
  3. Delegation is restricted to **narrowing-only** by protocol (a `monotone: true` flag in the delegation policy that the verifier enforces by rejecting any child scope not a subset of parent).

Absent one of these, a leaf-scope check is a *necessary but not sufficient* condition, and the system is exploitable by any intermediate that trusts a downstream capability advertisement over its own received grant.

Decision Boundary

An agent receiving a delegated credential must refuse to honor a scope that is present in its own token but **not present in the intersection of all upstream hops' signed scopes**, even when its own token signature is valid. The refusal must be a hard failure, not a downgrade, because honoring the subset silently masks the chain corruption and lets the attacker retry with narrower requests that still leak.

The boundary condition: **valid signature + valid leaf scope + scope ∉ upstream intersection ⇒ reject with chain-integrity error.** The agent must not attempt to "repair" the chain by re-intersecting and proceeding, because the widening itself is evidence of a compromised or buggy delegatee and the correct response is to fail the delegation and surface the offending hop.

Operational Effect

Enforcing the chain-bound scope invariant converts a silent, per-hop-invisible escalation into a loud, single-point failure at the first verifier that reconstructs the lattice. Operationally this means: (a) tokens grow by the size of the scope lattice (bounded by chain depth, typically ≤4 hops), (b) every verifier must have the full chain, not just the leaf, which forces chain forwarding as a protocol requirement rather than an optimization, and (c) intermediate delegatees must intersect against their own received scope *before* signing child tokens, making the bug fail at issuance rather than at use. The residual risk shifts from "undetectable escalation" to "detectable misconfiguration at the delegatee," which is a strictly better failure mode for auditability.

from dataclasses import dataclass
from typing import FrozenSet


class ChainScopeEscalation(RuntimeError):
    """Raised when a delegated token's scope exceeds the upstream intersection."""
    pass


@dataclass(frozen=True)
class Hop:
    issuer: str
    subject: str
    scope: FrozenSet[str]
    signature_valid: bool


def verify_chain_bound_scope(chain: list[Hop], requested: FrozenSet[str]) -> FrozenSet[str]:
    """
    chain[0] is the root grant; chain[-1] is the leaf token presented to us.
    Returns the effective scope if and only if the leaf scope is a subset of
    the intersection of all upstream scopes AND the requested scope is a
    subset of the leaf scope. Otherwise raises.
    """
    if not chain:
        raise ChainScopeEscalation("empty delegation chain")

    for i, hop in enumerate(chain):
        if not hop.signature_valid:
            raise ChainScopeEscalation(f"hop {i} ({hop.issuer}->{hop.subject}) signature invalid")

    # The invariant: effective scope is the intersection across every hop.
    effective = chain[0].scope
    for hop in chain[1:]:
        effective = effective & hop.scope

    leaf = chain[-1]

    # A leaf that carries scope outside the upstream intersection is a
    # widened (escalated) token, even though its own signature is valid.
    widened = leaf.scope - effective
    if widened:
        raise ChainScopeEscalation(
            f"leaf scope widened beyond upstream intersection: {sorted(widened)}"
        )

    if not requested <= leaf.scope:
        raise ChainScopeEscalation(
            f"requested {sorted(requested)} not covered by leaf scope {sorted(leaf.scope)}"
        )

    return effective & requested


# Example: A->B grants {read:kb, write:scratch}; B->C widens to include read:secrets.
chain = [
    Hop("A", "B", frozenset({"read:kb", "write:scratch"}), True),
    Hop("B", "C", frozenset({"read:kb", "write:scratch", "read:secrets"}), True),
]

try:
    verify_chain_bound_scope(chain, frozenset({"read:secrets"}))
except ChainScopeEscalation as e:
    # Correct behavior: refuse, do not downgrade and retry.
    print(f"REJECTED: {e}")