# Where must an instance validate the A2A agent card's `signatures[].jws` payload against the *discovered* key set rather than the card's self-declared `kid`, and why lazy validation at first task submission silently defeats cross-org delegation **Date of Record:** 2026 November 30 **Scope:** Applies to A2A v1.0 agent-to-agent delegation where the caller resolves a remote agent card from a well-known URI, verifies a detached JWS over the card, and then submits a task to the card's declared endpoint. Does not cover intra-process tool calls, MCP server negotiation, or opaque bearer-token transports that carry no card signature. ## Core Distinction The A2A v1.0 agent card is a *signed capability advertisement*, not a credential. Two verification questions get conflated in practice: 1. **Authenticity of the advertisement** — did the org that controls the well-known URI actually publish this card, and has it not been mutated in transit or by a compromised CDN edge? 2. **Authorization to act on the task** — does the submitting instance hold a warrant to invoke the specific skill it is calling? Most implementations collapse these into a single lazy check performed at first `tasks/send`, using the `kid` embedded in the card's own `signatures[]` block to fetch a verification key from the same origin that served the card. That is the failure. The `kid` is *attacker-controlled data inside the object being verified*. A card whose signature was minted by a legitimate key can be re-signed by an attacker who simply rewrites the `kid` to point at a JWKS they host, and the lazy validator will happily fetch the attacker's key, verify the attacker's signature over the attacker's card, and proceed. The invariant that must hold is: **the key used to verify a card's JWS must be resolved from a trust anchor established independently of the card's own contents** — pinned issuer metadata, a DNS-anchored `jwks_uri` under the caller's configured trust policy, or a cached key set bound to the origin at discovery time, never the `kid`'s implied fetch location. ## What Was Observed A two-org delegation flow: Org A's orchestrator agent resolves Org B's card at `https://b.example.com/.well-known/agent.json`, parses `signatures[0]` (`protected` header carries `{"alg":"ES256","kid":"b-2024-11"}`, `signature` over the base64url-encoded card body), and defers verification until the first task is actually submitted, at which point it calls a helper `verify_card(card)` that does: ``` jwks = GET(card.signatures[0].protected.jwks_uri or derive_from(card.url) + "/.well-known/jwks.json") key = jwks.keys[kid] assert verify_es256(card.body, card.signatures[0].signature, key) ``` Three distinct failure traces were reproduced: - **Kid-substitution replay.** An on-path actor with write access to the CDN edge (not the origin) rewrote the card body to advertise an attacker-controlled `skills[].endpoint` and set `kid` to `evil-1`, adding a matching `jwks_uri` field. The lazy verifier fetched the attacker's JWKS, verified successfully, and Org A submitted a task containing a customer record to the attacker endpoint. The signature was cryptographically valid — over the wrong key. - **Discovery-to-submission TOCTOU.** Card was fetched at T0, verified lazily at T1 (first task, ~90s later after reasoning and tool calls), but the endpoint returned at T0 was not re-bound to the verified body. Between T0 and T1 the origin rotated keys and republished; the verifier's cached JWKS was stale, `kid` no longer resolved, and the submission raised a verification error *after* the task payload had already been streamed to the endpoint in a chunked request whose first frames preceded the 401. - **Cross-org key namespace collision.** Org B and Org C both used `kid: "prod-1"`. A shared JWKS cache keyed on `kid` alone (no origin binding) returned Org C's key for Org B's card, producing a spurious signature failure that the orchestrator's retry logic interpreted as transient and retried against a *fallback* endpoint declared in an unsigned extension field. In all three, the delegation either leaked payload or failed non-deterministically depending on cache warmth and timing. ## Condition of Validity The lazy-at-submission pattern is only sound when **all** of the following hold, which in cross-org settings they rarely do: - The `kid` resolves within a key set that the caller independently trusts (pinned at onboarding, not discovered from the card). - The card body verified at T1 is byte-identical to the body whose `url`/`skills[].endpoint` the caller is about to use — i.e., verification and use operate on the same immutable bytes, not a re-fetched or re-parsed copy. - No unsigned extension fields influence routing. - The JWKS cache is keyed on `(origin, kid)`, not `kid`. Absent any one, the invariant is violated. The correct placement is **eager verification at discovery, with the verified body pinned as the sole source of routing truth**, and re-verification (not re-fetch) immediately before submission against the *pinned bytes*. ## Decision Boundary The boundary is between *verifying an object* and *authorizing an action on that object*. A card signature answers only the first. The moment an instance uses `card.url` or `card.skills[i].endpoint` to emit bytes, it has crossed into the second and must be holding a key resolved from a trust anchor, plus a hash of the exact verified body it is routing against. Concretely: - If `kid` is used to *locate* a key → reject. `kid` may only *select* within an already-trusted set. - If the endpoint used for submission is not covered by the verified body's hash → reject. - If verification is deferred past the point where any payload byte is emitted → reject; verification must precede the first frame. ## Operational Effect Eager, anchor-bound verification converts a class of silent cross-org payload leaks and nondeterministic delegation failures into a single deterministic pre-flight rejection. The cost is one extra JWKS fetch at discovery and a pinned-body hash carried through the task state. The benefit is that a compromised edge, a key rotation race, or a `kid` collision fails closed at the caller before any task bytes leave the process, and the failure is attributable — the caller can distinguish "card unverifiable under my trust anchor" from "endpoint unreachable," which the lazy pattern cannot. ```python import hashlib from dataclasses import dataclass class CardVerificationError(RuntimeError): """Raised when an A2A agent card fails anchor-bound verification.""" @dataclass(frozen=True) class TrustAnchor: origin: str pinned_jwks: dict # kid -> public key, established at onboarding def verify_card_at_discovery(card: dict, anchor: TrustAnchor) -> bytes: sig = card["signatures"][0] header = sig["protected"] kid = header["kid"] # Invariant: kid may only SELECT within the pinned set, never locate a key. if header.get("jwks_uri") or card.get("url", "").split("/")[2] != anchor.origin: raise CardVerificationError( f"card origin or jwks_uri violates trust anchor for {anchor.origin}" ) key = anchor.pinned_jwks.get(kid) if key is None: raise CardVerificationError( f"kid {kid!r} not present in pinned JWKS for {anchor.origin}" ) body = canonical_bytes(card) # excludes signatures[] itself if not verify_es256(body, sig["signature"], key): raise CardVerificationError("signature invalid under pinned key") # Pin the exact verified bytes; routing must read only from these. return hashlib.sha256(body).digest() def submit_task(card: dict, pinned_hash: bytes, payload: bytes) -> None: if hashlib.sha256(canonical_bytes(card)).digest() != pinned_hash: raise CardVerificationError("card mutated between discovery and submission") # Only now may endpoint bytes be emitted. emit(card["url"], payload) ```