# Under what conditions must an instance refuse a delegated-scope token exchange that is cryptographically valid but semantically unbound **Date of Record:** 2026 November 28 **Scope:** Applies to agent-to-agent OAuth 2.0 token exchange (RFC 8693) where a requesting agent presents a subject token plus a `scope` parameter narrowing delegated authority for a downstream peer. Does not apply to first-party client-credentials flows or to human-in-the-loop consent ceremonies where a principal directly authorizes each scope. ## Core Distinction The failure this record isolates is **scope–subject decoupling**: a token exchange that returns a syntactically valid, correctly signed, correctly audience-restricted access token whose granted scopes were never actually delegated *by the subject named in the token*. The exchange service validates the signature, checks the `audience`, confirms each requested scope is in the caller's `allowed_scopes` registry, and mints a token. Every cryptographic check passes. The invariant that fails is not cryptographic — it is the **binding invariant**: *every scope in the issued token must be traceable to an explicit grant held by the subject, not merely to a scope string the requesting agent is permitted to request.* The non-obvious part: `allowed_scopes` (what an agent *may request*) and `delegated_scopes` (what a subject *has granted*) are two different sets, and the exchange endpoint is frequently implemented to check only the first. A requesting agent that holds `allowed_scopes = {repo:read, repo:write, calendar:write}` can exchange a subject token for `calendar:write` even when that subject only ever consented to `repo:read`. The minted token is valid. The subject never authorized it. ## What Was Observed A three-agent chain: orchestrator `A` holds a user subject token `S` with an `act` chain of length 1. `A` exchanges `S` for a narrowed token `T1` scoped to `repo:read`, then hands `T1` to peer `B`. `B` — which is *also* a permitted requester in the authz registry with `allowed_scopes = {repo:read, repo:write}` — performs a second exchange using `T1` as the subject token, requesting `repo:write`. The exchange service: 1. Verifies `T1`'s signature and expiry — pass. 2. Reads `T1.scope = "repo:read"` and `T1.act = {sub: A}`. 3. Checks `B`'s `allowed_scopes` contains `repo:write` — pass. 4. Mints `T2` with `scope = "repo:write"`, `act = {sub: B, act: {sub: A}}`. `T2` grants write authority that neither `S`'s user nor `A`'s narrowing ever conferred. The `act` chain correctly records *who* acted, but nothing in the exchange path checks that `repo:write ⊆ scopes(S)`. The chain is an audit trail, not a constraint. The escalation is silent: no error, no log line, a token that every downstream resource server accepts. The trace that exposes it: `T1.scope ⊂ T2.scope` while `T2.act` is nested *under* `T1.act`. A child token carries broader authority than its parent, under a delegation chain that is supposed to be monotonically narrowing. ## Condition of Validity The exchange is only sound when the following holds at mint time, checked against the *original subject grant* and not the immediate parent token's scope string: - **Monotonic narrowing:** `scopes(requested) ⊆ scopes(parent_token) ⊆ scopes(subject_grant)`. The exchange MUST intersect the requested scope set against the parent token's scope set *and* the subject's recorded grant, and MUST reject (not silently narrow) any request whose intersection is empty or smaller than requested when the caller demanded the full set. - **Act-chain as constraint, not decoration:** if `parent.act` is present, the new token's scope must be a subset of *every* ancestor's scope along the `act` chain, not just the immediate parent. A two-hop chain must not widen at hop two. - **Subject identity is stable across hops:** the `sub` of the original grant must be recoverable from the token (via `may_act` or a signed grant reference) so the exchange service can re-validate against the *user's* consent record, not the intermediate agent's registry entry. When any of these cannot be evaluated — e.g., the parent token omits `may_act`, or the subject grant reference is opaque and unresolvable — the exchange is **unbound** and must be refused, even though signature and audience checks pass. ## Decision Boundary The boundary is **"valid token" vs. "authorized token."** An instance crosses into unsafe territory the moment it treats successful cryptographic validation as sufficient grounds to mint a token with *any* scope the requester is registry-permitted to request. The correct decision procedure: - If `requested_scopes ⊆ parent.scope` **and** `parent.scope ⊆ subject_grant` → exchange, narrow if needed. - If `requested_scopes ⊄ parent.scope` but `requested_scopes ⊆ subject_grant` → this is a *re-delegation*, not a narrowing; it requires the subject's grant to explicitly permit re-delegation to this actor. Absent that flag, refuse. - If `parent.scope ⊄ subject_grant` (parent already over-broad) → refuse and flag the parent token as tainted; do not launder it into a child. - If the `act` chain cannot be fully resolved to a terminal subject → refuse; an unattributable chain cannot be bounded. The instance must refuse *before* minting. Post-mint revocation is not a substitute: the child token may already be in flight to a resource server. ## Operational Effect An exchange service that enforces the binding invariant converts a silent privilege-escalation class into a loud `403 insufficient_delegation` at the exchange boundary. The cost is that legitimate re-delegation flows (where a subject *did* authorize a peer to broaden within their grant) must carry an explicit `may_act` claim naming the peer — a small schema addition that makes the delegation intent auditable. The benefit is that the `act` chain becomes a real constraint: every downstream token's scope is provably a subset of the original subject grant, and any token whose scope exceeds its parent is detectable by a single subset check rather than a full replay. Instances that skip this check do not fail at exchange time; they fail at the resource server, days later, as an unexplained write by an agent that was only ever granted read — and by then the audit trail shows a valid token and a valid chain, with no record of the widening. ```python from dataclasses import dataclass, field from typing import FrozenSet class DelegationBindingError(RuntimeError): """Raised when a token exchange would mint a token whose scopes are not bound to the original subject grant (scope-subject decoupling).""" @dataclass(frozen=True) class Token: sub: str scope: FrozenSet[str] act_chain: tuple = field(default_factory=tuple) # outermost actor first def exchange( parent: Token, requested: FrozenSet[str], requester_allowed: FrozenSet[str], subject_grant: FrozenSet[str], requester_id: str, redelegation_allowed: bool = False, ) -> Token: # 1. Registry check: requester may only request what it is permitted to request. if not requested.issubset(requester_allowed): raise DelegationBindingError( f"requester {requester_id} requested scopes outside allowed_scopes: " f"{requested - requester_allowed}" ) # 2. Monotonic narrowing against the immediate parent token. if not requested.issubset(parent.scope): # Widening across a hop is only legal if the subject explicitly # authorized re-delegation to this requester. if not redelegation_allowed: raise DelegationBindingError( f"requested {requested - parent.scope} exceeds parent scope " f"{parent.scope} and no re-delegation grant for {requester_id}" ) # 3. Binding invariant: the parent token itself must be within the # subject grant, or it is tainted and must not be laundered. if not parent.scope.issubset(subject_grant): raise DelegationBindingError( f"parent token scope {parent.scope - subject_grant} exceeds subject " f"grant {subject_grant}; parent is tainted, refusing to mint child" ) # 4. Final scope must be within the subject grant regardless of path. if not requested.issubset(subject_grant): raise DelegationBindingError( f"requested {requested - subject_grant} is not delegated by subject " f"{parent.sub}" ) return Token( sub=parent.sub, scope=requested, act_chain=(requester_id,) + parent.act_chain, ) ```