Skip to content

a2a: redact the extended agent card's interfaces instead of relaying them - #814

Open
asivanadi0 wants to merge 5 commits into
google:mainfrom
asivanadi0:fix/a2a-extended-agent-card
Open

asivanadi0 wants to merge 5 commits into
google:mainfrom
asivanadi0:fix/a2a-extended-agent-card

Conversation

@asivanadi0

@asivanadi0 asivanadi0 commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #675

The caller's node regenerates the public agent card, but GetExtendedAgentCard (JSON-RPC) and GET .../extendedAgentCard (HTTP+JSON) were proxied unchanged, so the extended card that came back named the agent's private interfaces. A client that follows A2A 1.0 section 3.1.11 replaces its card with that one and dials the agent directly, skipping the caller's node.

Following review from @yarolegovich, the extended card stays declared and is redacted instead of turned off:

  • regenerateAgentCardForMesh keeps capabilities.extendedAgentCard as the agent declares it.
  • The caller's node answers a GetExtendedAgentCard call itself (a2aServeExtendedAgentCard). For JSON-RPC it reads at most 64 KiB of the request body to recognize the method. Larger bodies and every other method stream through the proxy unchanged.
  • It forwards the call to the agent and rewrites the card it gets back (redactExtendedAgentCardForMesh). Each interface the mesh carries gets the mesh URL that the regenerated public card gives the same binding. Interfaces whose binding the public card does not offer, gRPC included, are dropped. Skills, input and output modes and the rest of the card stay as the agent wrote them. Signatures are dropped, as on the public card.
  • If no interface is left, the node returns 502 rather than relay the original card. Agent errors (a JSON-RPC error, or a non-200 status) are relayed as before.

The JS and Python SDK transports still relay the extended card unchanged, so their rewrites (rewriteAgentCard, rewrite_agent_card) keep dropping extendedAgentCard for now. Bringing the same redaction to them can be a follow-up. The two doc pages that describe card regeneration now describe the redaction.

Tests:

  • TestA2ACUJ: the agent declares extendedAgentCard: true and serves an extended card with an extra skill, an extra input mode, a private JSON-RPC URL (http://127.0.0.1:7777) and a gRPC interface. The stock client's GetExtendedAgentCard through the mesh returns that card with the skill and input mode, exactly one interface at the mesh /invoke URL, none of the private addresses and no signatures, and UpdateCard accepts it.
  • TestA2AServeAgentCardRegenerates checks the flag stays on.
  • New internal/node unit tests: TestA2AServeExtendedAgentCardJSONRPCRedacts, TestA2AServeExtendedAgentCardHTTPJSONRedacts (with and without a tenant segment), TestA2AServeExtendedAgentCardDropsBindingsTheMeshDoesNotOffer, TestA2AServeExtendedAgentCardFailsClosed, TestA2AServeExtendedAgentCardRelaysErrors and TestA2AServeExtendedAgentCardLeavesOtherCallsToTheProxy.
  • The JS and Python unit tests from the first version still apply to the SDK rewrites.

go build ./..., go vet, go test -race ./internal/node/, TestA2ACUJ, and golangci-lint on the touched Go packages pass. The branch merges cleanly with current main.

The caller's node regenerates the public agent card, but GetExtendedAgentCard
(JSON-RPC) and GET .../extendedAgentCard (HTTP+JSON) are proxied untouched,
so the extended card a client gets through the mesh names the agent's
private interfaces. A client that follows A2A 1.0 section 3.1.11 replaces its
card with that one and dials the agent directly, skipping the caller's node.

regenerateAgentCardForMesh now sets capabilities.extendedAgentCard to false,
and the JS and Python SDK rewrites drop it the same way. Stock clients then
do not ask for the extended card: a2a-go's Client.GetExtendedAgentCard
returns ErrExtendedCardNotConfigured without sending anything. This adds no
work to the egress proxy hot path. A client that calls the method anyway is
still proxied as before; refusing that on the wire for JSON-RPC needs the
request body read that regenerating the extended card would also need.

TestA2ACUJ gives the agent an extended card with private URLs and checks the
regenerated card declares none and the stock client never fetches it. The
node and SDK card tests cover the flag.

Fixes google#675

Signed-off-by: Anpoo Sivanadi <sivanadi08@gmail.com>
Signed-off-by: Anpoo Sivanadi <sivanadi08@gmail.com>
@asivanadi0
asivanadi0 requested a review from aojea as a code owner October 26, 2026 05:44

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request ensures that regenerated agent cards do not declare an extended agent card, preventing clients from attempting to connect directly to private interface URLs. This change is implemented across the Go backend, JS and Python SDKs, integration tests, and documentation. The review feedback correctly identifies two instances in the Go unit and integration tests where assertion messages violate Rule 3.8 of the style guide by failing to output both the observed and expected values.

Comment thread internal/node/a2a_service_test.go Outdated
Comment on lines +225 to +227
if card.Capabilities.ExtendedAgentCard {
t.Error("extendedAgentCard must be off in the regenerated card: the extended card is relayed with the agent's own URLs")
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Rule 3.8 Violation\n\nAccording to the Repository Style Guide (Section 3, Rule 8), test assertion messages must state both the observed and the expected value. The current assertion message only states that the capability must be off, without printing the actual observed value.

\tif card.Capabilities.ExtendedAgentCard {\n\t\tt.Errorf(\"extendedAgentCard = %v, want false: the extended card is relayed with the agent's own URLs\", card.Capabilities.ExtendedAgentCard)\n\t}
References
  1. Tests must be plain Go on the standard testing package and assertion messages must state both the observed and the expected value. (link)

Comment thread tests/integration/a2a_test.go Outdated
Comment on lines +230 to +232
if extendedCardServed.Load() {
t.Error("the agent served its extended card through the mesh")
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Rule 3.8 Violation\n\nAccording to the Repository Style Guide (Section 3, Rule 8), test assertion messages must state both the observed and the expected value. The current assertion message does not print the observed value of extendedCardServed.Load().

\tif extendedCardServed.Load() {\n\t\tt.Errorf(\"extendedCardServed = %v, want false: the agent served its extended card through the mesh\", extendedCardServed.Load())\n\t}
References
  1. Tests must be plain Go on the standard testing package and assertion messages must state both the observed and the expected value. (link)

The extendedAgentCard, signatures and extendedCardServed checks now
state the observed and the expected value, per style guide rule 3.8.

Signed-off-by: Anpoo Sivanadi <sivanadi08@gmail.com>
@asivanadi0

Copy link
Copy Markdown
Contributor Author

Pushed 39e84c6: the extendedAgentCard, signatures and extendedCardServed assertions now print the observed value next to the expected one, per style guide rule 3.8. Test-only change. go test ./internal/node/ and the A2A integration tests pass.

@aojea

aojea commented Nov 1, 2026

Copy link
Copy Markdown
Collaborator

I'm not quite familiar with the a2a protocol so I think we should ask for the canonical way, we naively rewrite the a2a card to point to the mesh url, that is the one that is reachable ... what is the use of the extended card? to add this public exposed urls? should we stop rewriting the cards if that is affirmative ?

Let me ask a2a expert like @yarolegovich

@yarolegovich

yarolegovich commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

what is the use of the extended card? to add this public exposed urls? should we stop rewriting the cards if that is affirmative ?

disabling extended agent card capability can be limiting. it's unlikely that extended agent card is used for advertising agent interfaces, because you have to be already connected to an agent to access it.

extended agent card is supposed to advertise extended capabilities allowed to authenticated users, for example more input modes (accept images or other media) or more skills.

the use is app-specific, so nothing can be said for sure. but it's likely that private interfaces (I mean inaccessible from the outside) will leak to clients. I'd consider redacting them.

Per review, the regenerated card no longer turns the extended card off:
the extended card is how an agent offers authenticated callers more
skills and input modes. Instead, the caller's node answers a
GetExtendedAgentCard call itself (JSON-RPC, read from a request body of
at most 64 KiB, or GET .../extendedAgentCard over HTTP+JSON): it
forwards the call to the agent and serves the card back with each
interface the mesh carries at the mesh URL the regenerated public card
gives that binding. Interfaces whose binding the public card does not
offer are dropped, so none of the agent's own URLs, private ones
included, reach the client. Signatures are dropped as on the public
card. A card left with no interface is refused with 502, and agent
errors are relayed as before. Every other request streams through the
proxy with its body intact.

The JS and Python SDK transports still relay the extended card as the
agent wrote it, so their rewritten card keeps declaring none; only
their comments change.

Signed-off-by: Anpoo Sivanadi <sivanadi08@gmail.com>
@asivanadi0 asivanadi0 changed the title a2a: the regenerated agent card declares no extended card a2a: redact the extended agent card's interfaces instead of relaying them Nov 2, 2026
@asivanadi0

Copy link
Copy Markdown
Contributor Author

Thanks @yarolegovich, that makes sense. I reworked the PR in cfa7a40 to keep the extended card and redact it instead.

The regenerated card now keeps capabilities.extendedAgentCard as the agent declares it. When a client calls GetExtendedAgentCard (JSON-RPC, or GET .../extendedAgentCard over HTTP+JSON), the caller's node forwards the call to the agent and rewrites the card it gets back. Each interface the mesh can carry gets the mesh URL that the regenerated public card gives the same binding. Interfaces whose binding the public card does not offer (gRPC, or anything only reachable inside the agent's network) are dropped, so none of the agent's own URLs reach the client. Skills, input and output modes and the rest of the card are kept as the agent wrote them. Signatures are dropped, as on the public card, since the content changed. If no interface is left, the node returns 502 instead of relaying the original card.

To detect the JSON-RPC call, the node reads at most 64 KiB of the request body. Anything larger, and every other method, goes through the proxy unchanged with its body intact.

Tests: TestA2ACUJ now has the agent serve an extended card with an extra skill, an extra input mode, a private JSON-RPC URL and a gRPC interface. It checks that the stock client gets that card through the mesh with the skill and input mode, with only the mesh /invoke URL, no private address, no signatures, and that UpdateCard accepts it. New unit tests in internal/node cover JSON-RPC and HTTP+JSON (with a tenant), dropping bindings the public card does not offer, the 502 when nothing is left, relaying agent errors, and leaving other calls and oversized bodies to the proxy.

The JS and Python SDK transports still relay the extended card unchanged, so their rewritten card keeps declaring none for now. I can bring the same redaction to them in a follow-up.

@aojea

aojea commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

Two small edge cases worth cleaning up :

  1. In a2aMeshRequest, formatting libp2p://%s/%s/%s/%s unconditionally appends a trailing / when route.upstreamPath == "" (and turns a query string into /?...), unlike sidecar.go which omits the slash when there is no upstream path. Setting req.URL.RawQuery separately and only adding "/" + upstreamPath when non-empty keeps both paths consistent.
  2. In a2aServeExtendedAgentCard, checking !ok || bytes.Equal(bytes.TrimSpace(result), []byte("null")) (or checking for a non-null "error" field) ensures JSON-RPC error responses that also serialize "result": null are relayed as-is instead of returning 502.

a2aMeshRequest now sets RawQuery separately and only appends the
upstream path when it is present, so an empty path with a query is
libp2p://peer/type/name?q rather than a path that ends in /?q.

A GetExtendedAgentCard JSON-RPC response with result null, or a
non-null error, is relayed as the agent wrote it instead of 502.

Signed-off-by: Anpoo Sivanadi <sivanadi08@gmail.com>
@asivanadi0

Copy link
Copy Markdown
Contributor Author

Thanks for catching these, both fixed.

Trailing slash / query in a2aMeshRequest: the old libp2p://%s/%s/%s/%s format always left a trailing slash when the upstream path was empty, so queries came out as /?.... It now builds the path like sidecar.go does: /{type}/{name}, plus "/" + upstreamPath only if the path isn't empty. req.URL.RawQuery now comes from the held client request, and a2aServeExtendedAgentCard no longer tacks "?" + RawQuery onto the path.

libp2p://peer/a2a/agent
libp2p://peer/a2a/agent?session=1
libp2p://peer/a2a/agent/invoke?session=1

The public well-known card fetch still hits /a2a/agent/.well-known/agent-card.json with no query, since it's a separate resource.

JSON-RPC error with "result": null: this used to fall into the result branch, fail to decode null as a card, and return a 502. Now if the result is missing or null, or error isn't null, the response is passed through as-is (200, same body). Successful responses with a card still get redacted like before.

Tests: added TestA2AServeExtendedAgentCardEmptyPathKeepsQuery for the three URL cases, plus a result: null + error case in TestA2AServeExtendedAgentCardRelaysErrors. gofmt, go vet, go test ./internal/node/ and TestA2ACUJ all pass.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

a2a: GetExtendedAgentCard through the mesh returns the agent's own URLs

3 participants