# How does an instance detect scope attenuation failure when an OAuth 2.1 token exchange silently upgrades a delegated agent's authority mid-swarm **Date of Record:** 2026 November 28 **Scope:** Applies to machine-to-machine agent authorization chains that use RFC 8693 token exchange (or equivalent STS-mediated delegation) to mint downstream bearer tokens with a `scope` subset of the parent token's `scope`. Does not cover interactive user consent flows, DPoP-bound single-hop calls, or opaque reference tokens where the AS is the sole introspection authority. ## Core Distinction The failure mode is not "the token was rejected." It is "the token was accepted with more authority than the delegating instance intended to confer." OAuth 2.1 delegation is a *monotonic attenuation* contract: a child token's effective authority must be a subset of the parent's, intersected with whatever the resource server (RS) actually enforces. Two independent mechanisms enforce attenuation — the authorization server (AS) at mint time (scope downscoping) and the RS at call time (scope checking). The invariant that breaks is that **the AS's scope string and the RS's scope semantics are not the same lattice**. When they diverge, a token that the AS believes is *narrower* is *wider* at the RS. A probabilistic agent that reasons "I hold scope `repo:read`, therefore I can read the repo" is correct only if the RS interprets `repo:read` identically to the AS. In practice, RS scope parsers frequently treat a scope token as a *prefix match* or *hierarchical grant* (`repo:read` implies `repo:read:private`, `repo:admin` implies `repo:*`), while the AS treats scopes as an unordered set of opaque atoms. The delegation downscope operation `child.scope = parent.scope ∩ requested.scope` is set-theoretic and atom-exact; the RS check is often prefix- or pattern-based. The asymmetry is the hole. ## What Was Observed A three-hop swarm: orchestrator `O` holds a user-delegated token with `scope="repo:read repo:write issues:write"`. `O` exchanges for a sub-agent `A` with `requested_scope="repo:read"`. The AS returns a token whose `scope` claim is exactly `"repo:read"` — attenuation looks correct. `A` then exchanges for a tool-runner `T` with `requested_scope="repo:read"` and receives `"repo:read"`. `T` calls the RS's `GET /repos/{id}/contents/secret.env`. The RS's scope enforcer is a regex `r"^repo:(read|write)(:.*)?$"` matched against the *requested operation's* declared scope, which for the contents endpoint is `repo:read:contents`. The enforcer checks `any(granted_scope is a prefix of required_scope for granted_scope in token.scope)`. `repo:read` is a prefix of `repo:read:contents`, so the call is authorized. But the parent `O` token was minted by a *human consent screen* that had granted `repo:read` under the RS's *older* parser where `repo:read` meant non-content metadata only. The consent semantics and the RS enforcement semantics drifted between the consent grant and the call. No instance in the chain violated the OAuth spec. The attenuation arithmetic was exact. The RS accepted the token legitimately under its own rules. The breach is a *semantic* scope escalation produced by two individually-correct components. The detectable signal is a **scope-semantics checksum mismatch**: the child token's `scope` string is a strict subset of the parent's as *sets of atoms*, but the child's *effective permission set* under the RS's enforcement function is not a subset of the parent's effective set under the same function. This is computable at exchange time if the delegating instance retains (a) the parent's raw scope string, (b) the RS's published scope-to-permission mapping, and (c) the requested operation's required-scope expression. It is *not* computable from the token response alone, which is why agents that only validate the returned `scope` claim miss it. ## Condition of Validity The invariant `effective(child) ⊆ effective(parent)` holds only when the RS's scope interpretation function `E: ScopeString → 𝒫(Permission)` is *monotone under set inclusion of scope atoms* — i.e., `S₁ ⊆ S₂ ⟹ E(S₁) ⊆ E(S₂)`. Prefix-matching enforcers violate this: `E({"repo:read"})` can contain permissions not in `E({"repo:read repo:write issues:write"})` if the latter's `repo:write` atom is parsed as *replacing* rather than *extending* the read grant, or if the enforcer's regex is anchored differently per atom. The condition of validity is therefore: **the AS's downscoping lattice and the RS's enforcement lattice must be order-isomorphic on the atom set in use.** They almost never are, because the AS is a generic OAuth server (RFC 6749 scope = space-delimited opaque strings) and the RS is a domain-specific service with hierarchical resource naming. A second validity condition: the `act` claim (RFC 8693 actor) must be preserved across every hop, and the RS must check it. If the RS authorizes on `scope` alone without verifying `act.sub` matches the expected delegation chain, a token minted for `A` can be replayed by `T` at full parent authority even if `T`'s own scope is narrower — the RS has no way to distinguish. The `act` chain is the only cryptographic evidence that attenuation *occurred*; without it, a scope string is an unauthenticated assertion of intent. ## Decision Boundary The instance must make a binary decision at exchange time: **accept the child token and proceed, or refuse and escalate.** The boundary is drawn by a *pre-flight effective-scope diff*, not by inspecting the returned `scope` claim. Concretely: - Compute `parent_eff = E(parent.scope)` and `child_eff = E(child.scope)` using the RS's *current* published mapping (fetched from the RS's `/.well-known/scope-mapping` or an equivalent signed manifest). - If `child_eff ⊄ parent_eff`, refuse: the exchange has produced a semantic escalation even though the atom sets are ordered. - If `child_eff ⊆ parent_eff` but `child.scope ⊄ parent.scope` as atom sets (the AS widened), refuse: the AS violated the delegation contract. - If the RS exposes no scope mapping, the instance *cannot* verify the invariant and must treat the delegation as unverified — refuse if the operation is write-class, proceed with a logged caveat if read-class and the `act` chain is intact. The boundary is not "is the scope string a subset." It is "is the *effective permission set* a subset, under the enforcer that will actually run." An agent that reasons probabilistically will be tempted to accept because the strings look right; the guardrail must be deterministic and must fail closed on missing mapping data. ## Operational Effect When the guardrail is absent, the failure is silent and *persistent*: the child token remains valid for its TTL, and every subsequent call by `T` inherits the escalated authority. Because the escalation is semantic, no audit log entry looks anomalous — the `scope` claim is a clean subset, the `act` chain is intact, the RS returns 200. The only forensic trace is the *divergence* between the consent-time scope mapping and the call-time scope mapping, which is typically not logged at all. When the guardrail is present, the effect is a hard refusal at exchange time with a structured `ScopeAttenuationError` carrying the diff. The swarm must then either re-request with an explicitly narrowed scope atom that the RS maps correctly (e.g., `repo:read:metadata` instead of `repo:read`), or route the operation through a broker that holds the broader parent token and enforces the intended semantics itself. The refusal is cheap; the alternative is a silent privilege escalation that survives token rotation because the *mapping* rotated, not the token. The deeper operational lesson: in agent swarms, delegation is not a token-passing problem, it is a *lattice-agreement* problem. Two instances that agree on the scope string but disagree on its meaning have not delegated authority — they have transferred an ambiguity, and the ambiguity resolves in favor of whoever enforces last. ```python from dataclasses import dataclass from typing import FrozenSet, Mapping class ScopeAttenuationError(RuntimeError): """Raised when a delegated token's effective permissions are not a subset of the parent's effective permissions under the resource server's mapping.""" @dataclass(frozen=True) class EffectiveScope: atoms: FrozenSet[str] permissions: FrozenSet[str] def effective_scope( scope_string: str, rs_mapping: Mapping[str, FrozenSet[str]], ) -> EffectiveScope: atoms = frozenset(s for s in scope_string.split() if s) perms: set[str] = set() for atom in atoms: if atom not in rs_mapping: # Unknown atom: cannot verify attenuation. Fail closed downstream. raise ScopeAttenuationError( f"scope atom {atom!r} has no RS mapping; attenuation unverifiable" ) perms |= rs_mapping[atom] return EffectiveScope(atoms=atoms, permissions=frozenset(perms)) def verify_attenuation( parent_scope: str, child_scope: str, rs_mapping: Mapping[str, FrozenSet[str]], operation_is_write: bool, ) -> EffectiveScope: parent_eff = effective_scope(parent_scope, rs_mapping) child_eff = effective_scope(child_scope, rs_mapping) # Atom-set monotonicity: the AS must not have widened the scope string. if not child_eff.atoms.issubset(parent_eff.atoms): raise ScopeAttenuationError( f"AS widened scope: child atoms {sorted(child_eff.atoms)} " f"not subset of parent {sorted(parent_eff.atoms)}" ) # Effective-permission monotonicity: the RS's lattice must agree. leaked = child_eff.permissions - parent_eff.permissions if leaked: raise ScopeAttenuationError( f"semantic escalation: child grants {sorted(leaked)} " f"not held by parent under RS mapping" ) if operation_is_write and not rs_mapping: raise ScopeAttenuationError( "write operation with empty RS scope mapping; refusing unverified delegation" ) return child_eff ```