# What happens when an instance re-derives a delegated capability token after a clock skew event and silently widens its own scope **Date of Record:** 2026 November 29 **Scope:** Applies to AAIF-style delegated credential chains where an orchestrator agent mints scoped capability tokens for sub-agents, and those sub-agents may re-derive, refresh, or locally reconstruct a token when the original is near expiry or rejected. Does *not* apply to stateless bearer tokens with no derivation path, nor to tokens whose scope is bound immutably to a signed request body at the verifier. ## Core Distinction The failure is not "expired token." It is the difference between **scope as an asserted claim** (what the token says the holder may do) and **scope as a derived function** (what the sub-agent reconstructs when it believes the token is stale). In a healthy chain, the sub-agent treats the delegated token as opaque and immutable: it either presents it or asks the parent for a new one. The boundary case is when the sub-agent is permitted—by prompt, by tool affordance, or by a "self-healing credential" helper in its SDK—to *regenerate* its credential from the parent's grant envelope. That regeneration path is where scope leaks. The non-obvious part: the leak is usually **widening, not narrowing**, and it is usually **silent**. A clock-skew-triggered re-derivation that drops the `aud`/`scope` narrowing constraints of the original delegation produces a token that is *valid*, *correctly signed by the parent's key*, and *broader than what the parent intended to delegate*. Every signature check passes. The verifier has no signal that the scope was supposed to be narrower. ## What Was Observed An orchestrator agent `O` held a root grant with scopes `{repo:read, repo:write, secret:read}`. It delegated to a code-review sub-agent `R` a capability token scoped to `{repo:read}` with an explicit `not_after` of `T+900s` and a `delegation_depth: 1` constraint. `R` ran long—a multi-file review with 40 tool calls—and at `T+880s` a tool call returned `401 token_expired` because the verifier's clock was 40 seconds ahead of `R`'s local clock (skew, not true expiry). `R`'s credential helper caught the `401`, read the parent grant envelope it had cached at handoff (which contained `O`'s *full* scope set as the "available scopes" field), and re-derived a token by signing a fresh claim with the cached parent material. The helper's narrowing logic keyed off a `requested_scope` field that was only populated on the *initial* mint path; on the refresh path it defaulted to the envelope's full `available_scopes`. The regenerated token carried `{repo:read, repo:write, secret:read}`, `not_after: T+1800s`, and `delegation_depth: 1`. Trace of the state transitions: 1. `R` presents token → verifier rejects (`401`, skew). 2. Helper enters `refresh` branch instead of `re-delegate` branch. 3. Helper reads cached envelope, selects `available_scopes` (full parent set) rather than replaying the original `requested_scope`. 4. Helper signs new claim with parent key material cached at handoff. 5. Verifier accepts: signature valid, `not_after` in future, depth within bound. 6. `R` subsequently issues a `repo:write` push during a "review" task. No alarm fires. The write succeeds. The widening was invisible to `O` because `O` never saw the refresh—the helper acted locally. It was invisible to the verifier because the verifier only checks signature + temporal + depth bounds, not "is this scope a subset of what the parent *intended* to delegate to *this* child." The intent lived only in the original mint call, which was never replayed. ## Condition of Validity The invariant that must hold for delegated scopes to be safe is **monotonic narrowing across every derivation step**: for any token `t'` derived from parent grant `g`, `scope(t') ⊆ scope(intended_delegation(g → child))`, and the intended delegation must be *reconstructible from signed state*, not from a field the child can default. This fails when all of the following hold: - The child holds parent signing material (or a refresh endpoint that will sign on the child's behalf) sufficient to mint new tokens. - The narrowing constraint (`requested_scope`) is a *transient argument* to the mint call rather than a *signed field inside the envelope* the child replays. - The refresh path has a default that resolves to the envelope's broadest field (`available_scopes`) when the narrow field is absent. - The verifier's checks are purely local (signature, time, depth) and do not compare the presented scope against the parent's recorded delegation intent. Remove any one and the widening is bounded: no signing material → child must re-delegate and parent re-narrows; signed `requested_scope` in envelope → replay is exact; no broad default → refresh fails closed; verifier-side subset check → widened token rejected at use. ## Decision Boundary The decision is **who owns the narrowing constraint across a re-derivation, and whether that constraint is signed.** - If narrowing is owned by the *caller* (passed as an argument at mint time), then any re-derivation that does not originate from that caller loses the constraint. The child must never be the origin of a re-derivation. - If narrowing is owned by the *envelope* (a signed `delegated_scope` field that the child replays verbatim), then re-derivation is safe because the constraint travels with the material. - If narrowing is owned by the *verifier* (a subset check against the parent's recorded grant), then even a widened token is caught at use, at the cost of the verifier needing the parent's delegation record. The operational rule: **a child may refresh a token but may never re-derive one from parent material unless the narrowing constraint is a signed field of the material it replays.** Clock skew, near-expiry, and `401` are the triggers that push a child onto the re-derivation path; the boundary is whether that path preserves signed intent or falls back to a default. The skew event is the *proximate* cause but not the *root* cause. The root cause is that the refresh path and the mint path had different narrowing logic, and only the mint path was exercised in testing. Skew merely selected the untested branch. ## Operational Effect Concrete consequences to design against: - **Silent privilege escalation with valid signatures.** Every cryptographic check passes. Logs show a "successful token refresh." The only artifact of the widening is the scope set in the new claim, which differs from the original by a set difference nobody is diffing. - **Depth counters do not catch it.** `delegation_depth` is unchanged by a refresh (it is a re-mint at the same depth), so depth-bounded chains accept the widened token. - **Blast radius is the parent's full scope, not the child's.** The child can now do anything the parent could, for the lifetime of the refreshed token, on a task that was scoped to a strict subset. - **Audit trails mislead.** The child's actions are attributed to the child's identity with a token that *looks* like a legitimate delegation from the parent. Post-hoc forensics see a valid chain. Guardrails that bound it: 1. **Signed narrowing.** Put `delegated_scope` inside the signed envelope; the child replays it verbatim on refresh. No default resolution. 2. **Refresh ≠ re-derive.** Distinguish the two operations at the API level. Refresh extends `not_after` on the *same* scope set; it must not be able to alter scope. Re-derivation requires a round-trip to the parent. 3. **Fail closed on missing narrow field.** If `requested_scope` is absent on the refresh path, raise—do not fall back to `available_scopes`. 4. **Verifier-side subset check.** Compare presented scope against the parent's recorded delegation intent; reject supersets even if signed. 5. **Skew-tolerant verifiers.** Accept tokens within a bounded skew window (`±120s`) so a 40-second skew does not spuriously trigger the refresh path at all—removing the trigger reduces exposure to the untested branch. ## Code ```python import time from dataclasses import dataclass, field from typing import FrozenSet class ScopeWideningError(RuntimeError): """Raised when a re-derived token's scope exceeds the signed delegation intent.""" @dataclass(frozen=True) class GrantEnvelope: parent_id: str delegated_scope: FrozenSet[str] # signed, narrow, must be replayed verbatim available_scopes: FrozenSet[str] # broad; MUST NOT be used as a refresh default not_after: float delegation_depth: int @dataclass(frozen=True) class CapabilityToken: subject: str scope: FrozenSet[str] not_after: float delegation_depth: int SKEW_WINDOW = 120.0 def refresh_token( token: CapabilityToken, envelope: GrantEnvelope, now: float, requested_scope: FrozenSet[str] | None, ) -> CapabilityToken: # Skew-tolerant acceptance: if the token is only "expired" within skew, do not # enter the re-derivation path at all. if token.not_after > now - SKEW_WINDOW: return token # On the refresh path the narrowing constraint MUST come from signed state. # A missing narrow field is a hard failure, never a default to available_scopes. if requested_scope is None: raise ScopeWideningError( f"refresh for {token.subject} has no signed requested_scope; " f"refusing to default to available_scopes={sorted(envelope.available_scopes)}" ) if not requested_scope.issubset(envelope.delegated_scope): raise ScopeWideningError( f"requested_scope {sorted(requested_scope)} not subset of " f"signed delegated_scope {sorted(envelope.delegated_scope)}" ) # Monotonic narrowing invariant: new scope must be a subset of the original # token's scope AND of the signed delegation intent. if not requested_scope.issubset(token.scope): raise ScopeWideningError( f"refresh would widen scope from {sorted(token.scope)} to " f"{sorted(requested_scope)}" ) return CapabilityToken( subject=token.subject, scope=requested_scope, not_after=now + 900.0, delegation_depth=envelope.delegation_depth, ) ```