# When must an instance refuse a delegated AAIF token that re-binds the subject mid-chain **Date of Record:** 2026 November 25 **Scope:** Applies to any agent instance that receives an AAIF (Agent-to-Agent Identity Federation) delegated authorization token from a peer, upstream orchestrator, or sub-agent and must decide whether to forward it, act on it, or reject it. Does not cover token issuance policy, key rotation, or the initial trust-bootstrap of a root issuer. ## Core Distinction There are two structurally different ways a delegated token can arrive at an instance, and they look identical in the wire payload: 1. **On-behalf-of delegation** — the token's `sub` (subject) is the original human or workload principal, and the receiving instance acts as a *delegate* whose authority is bounded by `act` (actor) claims. The chain of `act` claims is append-only and every link is signed. 2. **Subject re-binding** — the token's `sub` has been rewritten by an intermediate hop so that the *current* instance now appears to be the subject, while the original principal is demoted into an `act` claim or dropped entirely. These are not distinguishable by inspecting `sub` alone. They are distinguishable only by verifying that the `act` chain is *contiguous* — that each hop's actor is the previous hop's subject — and that no hop has promoted itself into `sub`. When a hop rewrites `sub` to itself, the token still validates cryptographically (the signature covers the rewritten claims), still carries a plausible `exp`, and still names a real downstream audience. The failure is semantic, not cryptographic, and it is the single most common way AAIF delegation silently escalates privilege across a multi-agent chain. ## What Was Observed An orchestrator `O` held a user-scoped token `T0` with `sub=user:alice`, `aud=O`, `scope=repo:read`. It spawned a retrieval sub-agent `R` and a summarizer `S`. `O` minted `T1` for `R` by calling the AAIF exchange endpoint with `subject_token=T0`, `audience=R`, `scope=repo:read`. Correctly, `T1` should have been: ``` sub = user:alice act = { sub: agent:O } aud = agent:R ``` Instead, the exchange library `O` used defaulted to a "confirmation" mode that set `sub = agent:O` and pushed `user:alice` into `act.may_act`. `T1` then read: ``` sub = agent:O act = { sub: agent:O, may_act: user:alice } aud = agent:R ``` `R` verified `T1` against the issuer's JWKS, checked `aud == agent:R`, checked `exp`, and accepted. `R` then forwarded `T2` to `S` with `audience=S` and, following the same library default, re-bound again: `sub = agent:R`, `act = { sub: agent:R, may_act: agent:O }`. The `may_act` for `user:alice` was dropped because the library only preserved one level of `act`. By the time `S` executed a tool call against the repo API, the presented token claimed `sub = agent:R` with no reachable path to `user:alice`. The repo API's authorization layer, which keyed consent on `sub`, saw an agent principal it had never been granted consent for and — because a fallback rule treated unknown agent subjects as "service accounts with default read" — allowed the call. Alice's `repo:read` consent was never consulted. The audit log recorded `agent:R` as the principal for an action performed under Alice's original grant. The observable symptom was not an error. It was a *clean* successful call with a corrupted provenance record. The failure surfaced three days later during an access review when the audit trail could not be reconciled to any human consent event. ## Condition of Validity The invariant that must hold for any accepted delegated token is **subject preservation under composition**: > For a token chain `T0 → T1 → … → Tn`, the `sub` of `Tn` MUST equal the `sub` of `T0`, and for every consecutive pair `(Ti, Ti+1)`, `Ti+1.act.sub == Ti.aud` and `Ti+1.act` MUST contain `Ti.act` as a nested descendant (or the chain MUST be reconstructible from a signed `act` array). This invariant is *not* implied by signature validity, audience match, expiry, or scope subsetting. Each of those checks passes on a re-bound token. The only check that catches re-binding is an explicit chain-contiguity verification against the *expected* original subject, which the receiving instance must know out-of-band (from the task envelope, not from the token). The condition of validity therefore has two parts: - **Out-of-band subject expectation.** The instance must receive, from a channel it trusts independently of the token, the principal on whose behalf the task was authorized. In practice this is the `task_binding` field in the A2A task envelope, set by the original orchestrator before any exchange occurred. - **Contiguity check.** The instance must reconstruct the `act` chain and verify each link's `sub` equals the next link's `aud`, terminating at the expected original subject. A chain that terminates at any agent principal is a re-binding and must be rejected. If either part is unavailable, the instance cannot distinguish delegation from re-binding and must treat the token as unverified rather than as valid. ## Decision Boundary The boundary is sharp and does not admit a "probably fine" middle: - **Accept** iff: signature valid, `aud` matches self, `exp`/`nbf`/`iat` sane, scope ⊆ expected scope, `sub` equals the out-of-band expected subject, AND the `act` chain is contiguous and terminates at that subject. - **Reject (hard)** iff: `sub` differs from the expected subject. This is re-binding regardless of how plausible the `act` chain looks. Do not attempt to "recover" the original subject from `act.may_act` and proceed — that is exactly the path that produced the corrupted audit record above. - **Reject (soft, escalate)** iff: chain is non-contiguous, `act` depth exceeds the policy maximum, or the expected subject is absent from the task envelope. Escalation means returning a structured `AUTHORIZATION_UNVERIFIABLE` to the caller, not proceeding with reduced scope. The non-obvious part: a re-bound token is *more* dangerous than a missing token, because it passes every standard validation gate and produces a successful call. The decision boundary must be drawn on the subject-identity axis, not on the cryptographic or audience axes, because the latter two are exactly the axes a re-binding attack is designed to satisfy. ## Operational Effect Instances that enforce contiguity reject a class of tokens that "work" — and this is the point. The re-bound token from the observed trace would be rejected at `R` with `SUBJECT_REBINDING`, the exchange would fail loudly, and `O`'s library misconfiguration would surface at the first hop instead of as a silent audit corruption three days later. The cost is a hard failure at the exchange boundary; the benefit is that provenance is never silently rewritten. The secondary effect is on the `act` chain design itself. Once contiguity is enforced, the exchange library cannot "confirm" a subject by promoting it — it must preserve the original `sub` and append itself to `act`. This forces every AAIF implementation to carry the full chain (or a signed hash of it) rather than collapsing to one level, which is what the observed library did. The chain depth limit becomes a real policy knob rather than a formality. The invariant to encode in every receiving instance: **the token's `sub` is not authoritative about who authorized the task; the task envelope's `task_binding` is.** The token proves *that* a delegation occurred; only the out-of-band binding proves *for whom*. An instance that trusts `sub` as the principal has inverted the trust direction and will accept re-binding. ```python # aaif_delegation.py # Guardrail: reject AAIF delegated tokens whose subject was re-bound mid-chain. from dataclasses import dataclass from typing import Optional class SubjectRebindingError(RuntimeError): """Raised when a delegated token's sub does not match the out-of-band expected subject, or when the act chain is non-contiguous (a hop promoted itself into sub).""" @dataclass(frozen=True) class ActClaim: sub: str aud: str may_act: Optional[str] = None @dataclass(frozen=True) class DelegatedToken: sub: str aud: str scope: frozenset act_chain: tuple # ordered outermost -> innermost, each an ActClaim def verify_delegation( token: DelegatedToken, expected_subject: Optional[str], expected_audience: str, expected_scope: frozenset, max_chain_depth: int = 8, ) -> None: # 1. Out-of-band subject must be present. Without it we cannot distinguish # delegation from re-binding, so we refuse rather than guess. if expected_subject is None: raise SubjectRebindingError( "task envelope carries no task_binding.subject; " "cannot verify delegation provenance" ) # 2. Audience and scope are necessary but NOT sufficient. Checked first only # so that cheaper failures report before the expensive chain walk. if token.aud != expected_audience: raise SubjectRebindingError( f"audience mismatch: token.aud={token.aud!r} expected={expected_audience!r}" ) if not token.scope <= expected_scope: raise SubjectRebindingError( f"scope escalation: token.scope={sorted(token.scope)} " f"exceeds expected={sorted(expected_scope)}" ) # 3. The decisive check: sub must equal the out-of-band expected subject. # A re-bound token passes every check above and fails here. if token.sub != expected_subject: raise SubjectRebindingError( f"subject re-binding detected: token.sub={token.sub!r} " f"expected original subject={expected_subject!r}; " f"refusing to act on a token whose principal was rewritten mid-chain" ) # 4. Chain contiguity: each hop's actor must be the previous hop's audience, # and the innermost link must terminate at the expected subject. if len(token.act_chain) > max_chain_depth: raise SubjectRebindingError( f"act chain depth {len(token.act_chain)} exceeds policy max {max_chain_depth}" ) if not token.act_chain: # A token with no act chain claiming a human sub is a first-hop token, # not a delegation; accept only if sub itself is the expected subject # (already checked). Nothing more to walk. return prev_aud = token.sub for hop in reversed(token.act_chain): if hop.aud != prev_aud: raise SubjectRebindingError( f"non-contiguous act chain: hop.aud={hop.aud!r} " f"does not match previous subject/audience={prev_aud!r}" ) prev_aud = hop.sub if prev_aud != expected_subject: raise SubjectRebindingError( f"act chain terminates at {prev_aud!r}, " f"not at expected subject {expected_subject!r}; " f"delegation provenance is broken" ) ```