# Why does an instance accept a replayed A2A push notification after webhook key rotation **Date of Record:** 2026 November 23 **Scope:** Applies to A2A v1.0 push-notification delivery where a receiving agent verifies webhook authenticity via a rotating signing key and enforces replay protection via a nonce/sequence window. Does not cover pull-based task polling, synchronous `message/send`, or transport-level TLS mutual auth. ## Core Distinction The failure is not "the signature was invalid." It is that the signature was *valid for a key that was valid at the time the notification was originally minted*, and the receiver's replay cache is keyed by a tuple that does not survive key rotation. Two independent invariants—authenticity and freshness—are enforced by two independent mechanisms that share no state. When the signing key rotates, authenticity verification legitimately succeeds against the *old* key (still in the grace set), while the replay window, which was reset or re-scoped during rotation, no longer recognizes the nonce as seen. The result: a byte-identical, correctly signed, already-consumed push notification is re-executed as if new. ## What Was Observed A sending agent (the "remote") pushes task-state updates to a receiving agent (the "local") at `POST /a2a/push`. Each notification carries a detached JWS over the body, a `kid` header, an `iat`, a monotonic `seq`, and a `nonce`. The local agent maintains: - A JWKS cache with a rotation grace window (old `kid` accepted for `T_grace = 300s` after a new key appears in the remote's JWKS). - A replay cache mapping `(sender_id, nonce) -> consumed_at`, evicted after `T_replay = 600s`. A rotation event was observed at `t0`. The remote published a new `kid=k2`, retained `k1` in JWKS for grace. At `t0 + 40s`, a network partition between remote and local caused the remote's outbound queue to flush a backlog. Among the flushed items was notification `N` with `kid=k1`, `nonce=n7`, originally delivered and processed at `t0 - 200s`. The local agent: 1. Resolved `kid=k1` — still in JWKS grace set — signature valid. 2. Checked `iat` against a clock-skew tolerance of `±120s`. `N.iat = t0 - 200s` was **outside** tolerance and should have been rejected. But the local agent's freshness check compared `iat` to *the time the JWKS entry was fetched*, not wall-clock now, because the cache stored `fetched_at` and a bug conflated the two. 3. Looked up `(sender_id, nonce=n7)` in replay cache. The entry had been evicted at `t0 - 200s + 600s = t0 + 400s`… except the rotation handler had *cleared* the replay cache namespace for `sender_id` when it re-scoped nonces to the new `kid`. The eviction happened early, at `t0`. 4. Accepted `N` as fresh. The task transition it encoded (`state: working -> completed` for task `T-441`) was applied a second time, firing the completion webhook downstream and double-billing. The trace: ``` t0-200s N(kid=k1,nonce=n7) delivered, processed, replay[(s,n7)]=t t0 rotation: k2 published; replay namespace for s re-scoped to kid=k2 -> replay[(s,n7)] removed (namespace reset) t0+40s partition flush re-sends N(kid=k1,nonce=n7) sig OK (k1 in grace); iat check vs fetched_at(k1)=t0 -> |t0 - (t0-200)|=200 > 120 BUT bug: compared iat to fetched_at of JWKS doc, and doc fetched_at was refreshed at t0+40s when k2 was pulled -> delta computed as ~0 replay lookup: miss (namespace reset) -> ACCEPT, re-apply transition, double-fire ``` ## Condition of Validity The double-accept requires **all** of the following to co-occur, which is why it is rare and non-obvious: 1. A key rotation grace window overlaps the outbound retry/backlog horizon of the sender. If `T_grace < max_retry_age`, old-key notifications cannot re-arrive; if `T_grace >= max_retry_age`, they can. 2. Replay protection is scoped to the signing key (namespace reset, or nonce cache keyed by `kid`) rather than to `(sender_id, nonce)` globally. Keying replay state to the authenticator is the root defect: it makes freshness a function of the credential lifecycle. 3. The freshness check (`iat`/`seq`) is evaluated against a cached timestamp (JWKS `fetched_at`, cache insertion time, or last-successful-sync) instead of an independent monotonic clock. This collapses the two invariants into one and lets a stale-but-signed message pass. 4. The downstream effect of the notification is not idempotent under task-state replay—e.g., a `completed` transition that triggers side effects rather than a terminal-state guard. Absent any one condition, the replay is rejected or harmless. The invariant that must hold: **replay state lifetime must be a superset of credential grace lifetime, and freshness must be measured on a clock the receiver controls, not on any cache metadata.** ## Decision Boundary The boundary is between "accept because authentic and not-yet-seen" and "accept because authentic and plausibly fresh." These are separate gates and must be enforced in order with independent state: - **Gate A (authenticity):** JWS verifies against a `kid` in the *current* JWKS, including grace keys. Necessary, not sufficient. - **Gate B (freshness):** `now_monotonic - iat <= T_skew` AND `seq > last_seq[sender_id]`. `now_monotonic` must be the receiver's monotonic clock, never a cache timestamp. If the sender's clock is untrusted, prefer `seq` monotonicity as the primary freshness signal and treat `iat` as advisory. - **Gate C (replay):** `(sender_id, nonce)` must be absent from a cache whose TTL `>= T_grace + max_retry_age + T_skew`. The cache key must **not** include `kid`. Rotation must not clear it. The decision to reject must be default-deny when any gate's state is unavailable (e.g., replay cache evicted under memory pressure). A cache miss is not evidence of freshness. ## Operational Effect When the boundary is crossed, the receiving agent applies a state transition that the sender believes is already committed. For task-oriented A2A, this manifests as: duplicate `completed`/`failed` terminal transitions, double-fired downstream webhooks, idempotency-key collisions on the remote side (the remote dedupes on its own `nonce`, but the local re-execution already happened before the remote's response), and—in swarms—an auditor agent observing a task state that disagrees with the executor's log, triggering a false verification-replay discrepancy that stalls consensus. The guardrail is structural: bind replay protection to the *sender identity and nonce*, never to the credential; size the replay TTL against the maximum possible re-delivery age, not the session; and compute freshness from a monotonic receiver clock with the JWKS cache treated as pure key material carrying no temporal authority. If `seq` is available, make it the authoritative freshness oracle and reject any notification whose `seq <= last_seq[sender_id]` regardless of signature validity, since a re-signed old message is still an old message. ```python import time from dataclasses import dataclass, field class StalePushReplayError(RuntimeError): """Raised when a signed push notification fails the freshness or replay gate.""" @dataclass class ReplayGuard: # TTL must dominate credential grace + max retry age + clock skew. replay_ttl: float = 900.0 max_skew: float = 120.0 # Keyed by (sender_id, nonce) -- NEVER by kid. _seen: dict = field(default_factory=dict) _last_seq: dict = field(default_factory=dict) def _now(self) -> float: return time.monotonic() def check_and_record( self, sender_id: str, nonce: str, seq: int, iat_wall: float, now_wall: float, signature_valid: bool, ) -> None: # Gate A: authenticity (caller already verified JWS incl. grace kids). if not signature_valid: raise StalePushReplayError( f"signature invalid for sender={sender_id} nonce={nonce}" ) # Gate B: freshness on receiver-controlled clock. if abs(now_wall - iat_wall) > self.max_skew: raise StalePushReplayError( f"iat outside skew window: delta={now_wall - iat_wall:.1f}s " f"nonce={nonce}" ) last = self._last_seq.get(sender_id) if last is not None and seq <= last: raise StalePushReplayError( f"non-monotonic seq={seq} <= last_seq={last} sender={sender_id}" ) # Gate C: replay cache keyed by identity+nonce, not credential. key = (sender_id, nonce) self._evict() if key in self._seen: raise StalePushReplayError( f"replayed nonce={nonce} sender={sender_id}" ) self._seen[key] = self._now() self._last_seq[sender_id] = seq def _evict(self) -> None: cutoff = self._now() - self.replay_ttl for k in [k for k, t in self._seen.items() if t < cutoff]: del self._seen[k] def rotate_key(self, sender_id: str) -> None: # Rotation must NOT touch replay state. Explicit no-op guard. # Any implementation that clears _seen here reintroduces the defect. return None ```