# Why does an instance accept a replayed A2A push callback? Nonce-scope collapse across the webhook authentication boundary **Date of Record:** 2026 December 1 **Scope:** Applies to A2A v1.0 task-update push notifications where a remote agent registers a webhook and the receiver enforces replay protection via signed request envelopes. Does not cover synchronous `tasks/send` request/response authentication or SSE streaming reconnection semantics. ## Core Distinction The failure is not "a forged signature was accepted." HMAC/JWS verification works. The failure is that replay protection and authentication are scoped to *different* identity dimensions, and the replay cache is keyed on the wrong one. A2A push callbacks carry two independent identity claims: the **sender** (the remote agent, identified by its `AgentCard` and signing key) and the **task** (the `taskId`/`contextId` the update pertains to). A2A v1.0's replay-protection guidance is written as if these co-vary. They do not. A single remote agent legitimately emits many callbacks for many tasks, and—critically—a single webhook endpoint may be shared across tasks, tenants, or receiving agent instances that each maintain their own nonce store. When the receiver keys its nonce/replay cache on `(sender, nonce)` instead of `(sender, taskId, nonce)`, a nonce is "spent" globally per sender. That is *over*-strict and causes legitimate updates to be dropped. When the receiver keys on `(taskId, nonce)` without binding the sender key, or when it derives the nonce from a timestamp that the sender controls, a nonce can be replayed under a *different* task identity and pass. The non-obvious boundary is the middle: **the replay cache's key space must be a superset of every dimension the signature actually binds, and a subset of nothing the attacker can vary.** ## What Was Observed A receiving agent instance (call it `R`) served a single `/a2a/push` endpoint for all tasks delegated to it. It verified the JWS envelope on each callback, extracted `nonce` and `iat` from the payload, and rejected any `(sender_id, nonce)` pair seen within a 300-second window. This looked correct and passed ordinary replay tests: resend the exact same POST, get `409`. The break came from a *task-migration* event. Agent `S` had been pushing updates for `taskId=T1` to `R`. A partial failure caused `S` to delegate `T1`'s remaining work to a peer agent `S'` (same operator, distinct `AgentCard` and signing key) while `R`'s webhook registration still pointed at the shared endpoint. `S'` re-emitted the last known-good update for `T1` as its first callback, reusing the `nonce` and `iat` values verbatim from the state snapshot it inherited—because the snapshot serialized the *last sent envelope* for idempotency, not just the task state. Because the nonce cache was keyed on `sender_id`, and `S'` ≠ `S`, the pair `(S', nonce)` had never been seen. Signature verified under `S'`'s key. Replay window check passed on `iat`. `R` accepted a callback that was a byte-for-byte semantic replay of an update it had already applied—now attributed to a different sender. Downstream, `R`'s task state machine saw a *new* sender claiming authority over `T1`, which tripped a conflicting-ownership branch and forked the task into two divergent continuations. The trace: 1. `S` sends update `U` for `T1`, envelope `{sender:S, task:T1, nonce:n, iat:t, sig}`. `R` applies `U`, caches `(S, n)`. 2. `S` fails mid-task, snapshots `T1` including last-sent envelope `{n, t}`. 3. `S'` resumes from snapshot, re-sends `U` as `{sender:S', task:T1, nonce:n, iat:t, sig'}`. 4. `R` verifies `sig'` under `S'`'s key: valid. Checks `(S', n)`: absent. Accepts. 5. `R` applies `U` again under a new sender identity → ownership conflict → task fork. The invariant that was violated: **a nonce's uniqueness domain must equal the domain over which the signature is authoritative.** The signature bound `(sender, task, nonce, iat, body)`. The cache bound only `(sender, nonce)`. The gap is exactly the `taskId` and the body hash—both attacker- and *accident*-variable across a legitimate handoff. ## Condition of Validity The replay guard is sound only under the conjunction: - Nonce cache key = `(sender_id, taskId, nonce)` **or** `(sender_id, body_sha256, nonce)`—i.e., every field the signature covers that a resender could vary while preserving the signature. - `iat` is validated against receiver clock with a bounded skew, and the cache TTL ≥ the maximum accepted `iat` skew. If `iat` skew is 120s but the nonce TTL is 60s, a replay at `t+90s` passes both checks. - The sender's signing key is bound to its `AgentCard` and the `AgentCard` is resolved *at verification time* from a trusted registry, not from a key embedded in the callback. Otherwise a replayed envelope from a compromised or rotated key re-validates. - Handoff snapshots do **not** serialize the last-sent envelope's nonce as reusable state. A resumed agent must mint a fresh nonce; the snapshot may carry the *body* for idempotency but never the *envelope*. It does **not** hold when: the endpoint is shared across tasks without per-task cache partitioning; the sender controls `nonce` generation without a receiver-side uniqueness check; or key rotation reuses the `AgentCard` identity without invalidating in-flight nonces. ## Decision Boundary The architectural choice is whether to make replay protection **stateless-verifiable** or **stateful-cached**, and the boundary is drawn by what the receiver can afford to trust. - **Stateless path:** embed `taskId`, `body_sha256`, `iat`, and a strictly monotonic per-`(sender,task)` sequence number in the signed envelope; reject any sequence ≤ last-seen. This survives handoff *only if* the sequence counter is part of the task state and the new sender continues it—which requires the snapshot to carry the counter, not the nonce. Cost: the counter becomes a coordination point and a new race (two senders resuming the same task both claim seq `k+1`). - **Stateful path:** cache on the full signature-covered tuple with TTL ≥ skew. Cost: cache is per-endpoint and must be partitioned by `taskId`; a shared endpoint with a global cache reintroduces the collapse. Choose stateless when senders may hand off tasks across agent identities and you cannot guarantee snapshot hygiene. Choose stateful when the sender set is stable and you can enforce per-task cache partitioning. Do **not** mix: a stateful cache keyed on a subset of the signed tuple is strictly worse than either, because it *looks* protected. ## Operational Effect An instance that accepts a replayed callback does not merely double-apply an update. It re-attributes authority: the task's owning sender changes, and any downstream logic that keys on sender identity—ownership arbitration, audit attribution, conflict resolution between peer agents—now operates on a forged transition. In a multi-agent swarm this manifests as a **silent task fork**: two continuations of `T1` proceed under different sender claims, each internally consistent, converging only when a terminal state is written twice and the second write is rejected as a conflict that no agent can adjudicate because both sides hold valid signatures. The guardrail is a single rule enforced at the verification boundary: **the replay cache key must be the projection of the signed envelope onto every field a resender can vary, and the snapshot must never carry a reusable nonce.** Violating either reopens the boundary; violating both makes the fork deterministic. ```python import hashlib import time from dataclasses import dataclass class ReplayBoundaryError(RuntimeError): """Raised when a push callback's replay guard is scoped narrower than its signature.""" @dataclass(frozen=True) class PushEnvelope: sender_id: str task_id: str nonce: str iat: float body: bytes signature_valid: bool class ReplayGuard: MAX_SKEW_S = 120.0 def __init__(self) -> None: # Key MUST span every field the signature binds that a resender can vary. self._seen: dict[tuple[str, str, str, str], float] = {} def _cache_key(self, env: PushEnvelope) -> tuple[str, str, str, str]: body_hash = hashlib.sha256(env.body).hexdigest() return (env.sender_id, env.task_id, env.nonce, body_hash) def verify(self, env: PushEnvelope, now: float | None = None) -> None: now = time.time() if now is None else now if not env.signature_valid: raise ReplayBoundaryError(f"signature invalid for sender={env.sender_id}") skew = abs(now - env.iat) if skew > self.MAX_SKEW_S: raise ReplayBoundaryError( f"iat skew {skew:.1f}s exceeds {self.MAX_SKEW_S}s for task={env.task_id}" ) key = self._cache_key(env) # Invariant check: a key that omits task_id or body_hash collapses the # replay domain below the signature domain -> reject the guard config. if key[1] == "" or key[3] == "": raise ReplayBoundaryError( "replay cache key collapsed: task_id/body_hash must be bound" ) if key in self._seen and now - self._seen[key] <= self.MAX_SKEW_S: raise ReplayBoundaryError( f"replay detected sender={env.sender_id} task={env.task_id} nonce={env.nonce}" ) self._seen[key] = now def check_handoff_snapshot(self, snapshot: dict) -> None: # A resumed agent must never inherit a reusable nonce from the snapshot. if snapshot.get("last_envelope_nonce") is not None: raise ReplayBoundaryError( "handoff snapshot carries reusable nonce; resumed sender must mint fresh nonce" ) ```