Repository navigation
fix(a2a): harden agent-card resolution against SSRF and a silent file read - #832
Merged
AmaadMartin merged 3 commits intoSep 9, 2026
Merged
Conversation
added 3 commits
August 27, 2026 11:34
The agent-card resolver needs the same address checks that loadWebPage already has, so the helpers move to core/src/utils/ssrf_guard.ts with a narrow isLinkLocalAddress predicate added. The move also tightens loadWebPage: an IPv6 address that embeds a non-global IPv4 through NAT64, 6to4 or the IPv4-compatible form is now blocked, matching adk-python's _embedded_ipv4.
…read resolveAgentCard treated any source that did not start with http:// or https:// as a filesystem path, so file:///etc/passwd and a typo like htp://host/card.json became an arbitrary file read. The fetch also had no address check and followed redirects, so a card host could move the request to the cloud metadata endpoint. A source now resolves by scheme: http(s) fetches, file:// and a bare path read, and any other scheme throws. The fetch refuses a link-local host and refuses a redirect instead of following it. Loopback and private addresses stay allowed, because that is where a locally served or VPC-internal peer agent lives.
…uched The injected fetchImpl rebuilt the request through `new Request(input)` just to read a URL, then refetched from that URL, which would have dropped a real request's method, headers and body. It now forwards `input` and only refuses the redirect. The host check moves to the configured URL in resolveAgentCard. The resolver appends a relative well-known path, which cannot change the origin, so one check still covers the whole fetch.
kalenkevich
approved these changes
Sep 9, 2026
Merged
prasanna8585
pushed a commit
to prasanna8585/adk-js
that referenced
this pull request
Nov 10, 2026
… read (google#832) * refactor(core): move the SSRF address guard into a shared util The agent-card resolver needs the same address checks that loadWebPage already has, so the helpers move to core/src/utils/ssrf_guard.ts with a narrow isLinkLocalAddress predicate added. The move also tightens loadWebPage: an IPv6 address that embeds a non-global IPv4 through NAT64, 6to4 or the IPv4-compatible form is now blocked, matching adk-python's _embedded_ipv4. * fix(a2a): guard agent-card resolution against SSRF and a silent file read resolveAgentCard treated any source that did not start with http:// or https:// as a filesystem path, so file:///etc/passwd and a typo like htp://host/card.json became an arbitrary file read. The fetch also had no address check and followed redirects, so a card host could move the request to the cloud metadata endpoint. A source now resolves by scheme: http(s) fetches, file:// and a bare path read, and any other scheme throws. The fetch refuses a link-local host and refuses a redirect instead of following it. Loopback and private addresses stay allowed, because that is where a locally served or VPC-internal peer agent lives. * refactor(a2a): check the card host once, and forward the request untouched The injected fetchImpl rebuilt the request through `new Request(input)` just to read a URL, then refetched from that URL, which would have dropped a real request's method, headers and body. It now forwards `input` and only refuses the redirect. The host check moves to the configured URL in resolveAgentCard. The resolver appends a relative well-known path, which cannot change the origin, so one check still covers the whole fetch. --------- Co-authored-by: Amaad Martin <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Please ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
Problem:
resolveAgentCardread any source that did not start withhttp://orhttps://off the local filesystem, sofile:///etc/passwdor a typo likehtp://host/card.jsonbecame an arbitrary file read. The fetch had no address check, sohttp://169.254.169.254/reached the cloud metadata endpoint. The fetch also followed redirects, so a card host could move the request to that endpoint itself.Solution: A card source now resolves by scheme.
http(s)fetches,file://and a bare filesystem path read, and any other scheme throws instead of falling through tofs.readFile. The fetch refuses a host that is or resolves to a link-local address, and refuses a redirect rather than following it. Loopback and private addresses stay allowed, because that is where a locally served or VPC-internal peer agent lives, and blocking them would break the shapetoA2a()emits.Four notes for the reviewer.
file://sources are newly supported, which is a small behavior addition rather than a fix. Onmainafile://source reachedfs.readFile('file:///...')and always failed. Now that a URL-shaped source can no longer fall through to a file read, a developer who wants a local card needs a spelling the guard accepts, and this is it. A bare filesystem path keeps working unchanged.The address checks already existed in
core/src/tools/load_web_page.ts. They move tocore/src/utils/ssrf_guard.tsrather than being duplicated, which is most of the line count.loadWebPage's 44 existing tests pass unmodified.The move tightens
loadWebPageonce, deliberately: an IPv6 address that embeds a non-global IPv4 through NAT64 (64:ff9b::/96), 6to4 (2002::/16) or the IPv4-compatible form is now blocked.http://[64:ff9b::a9fe:a9fe]/is64:ff9b::169.254.169.254and routes to the metadata endpoint on a NAT64 network.adk-python's_embedded_ipv4already does this; the TypeScript port only un-embedded the IPv4-mapped form.The design spec asked for the host check twice, once before
DefaultAgentCardResolverruns and once inside the injectedfetchImpl. One check is enough, and it runs on the configured URL. The resolver appends a relative well-known path, which cannot change the origin, and the injectedfetchImplrefuses a redirect, so nothing else can pick where the request lands.Related work in this repo: #829 pins a fetched card's RPC url(s) to the origin it was fetched from. That is the complement of this change — #829 guards where a card points us next, this one guards where we fetch the card from. The two are independent and can land in either order; whichever is second will need a trivial rebase, as both touch
core/src/a2a/agent_card.tsand its test.This change is not stacked on anything: it applies directly to
main.Testing Plan
Please describe the tests that you ran to verify your changes. This is required for all PRs that are not small documentation or typo fixes.
Unit Tests:
[x] I have added or updated unit tests for my change.
[x] All unit tests pass locally.
Line and branch coverage of the new code is 100% (
core/src/utils/ssrf_guard.ts100/100,core/src/tools/load_web_page.ts100/100).core/src/a2a/agent_card.tsreports 88%; every uncovered line is pre-existingbuildAgentSkillscode, none is in this change.Each new test was run against mutated source to prove it can fail:
await assertHostAllowed(url)expected [Function] to throw error matching /Refusing to fetch agent card from a l…/redirect: 'manual'back to the defaultexpected "spy" to be called with arguments: [ Any<URL>, ObjectContaining{…} ]startsWith('http://')and the barefs.readFilefallbackexpected [Function] to throw error matching /Unsupported agent card URL scheme/ but got 'Failed to read agent card from file f…'embeddedIpv4expected false to be truefetches the card from the loopback URL http://localhost:8001/a2a/agent/expected [Function] to throw error matching /^Failed to read agent card from file …/ but got 'Unsupported agent card URL scheme "c:…'status === 0armexpected [Function] to throw error matching /status 0, location null/The loopback mutation is there on purpose: it pins the allowance as a decision, not an accident.
Manual End-to-End (E2E) Tests:
Please provide instructions on how to manually test your changes, including any necessary setup or configuration.
Run
npm run build, then drive the builtresolveAgentCardagainst a real local HTTP server with no mocks:resolveAgentCard('http://169.254.169.254/')throwsRefusing to fetch agent card from a link-local address: 169.254.169.254. The server'sconnectioncounter stays at 0, so no socket opens.302 Location: http://169.254.169.254/computeMetadata/v1/throwsRefusing to follow a redirect while fetching the agent card from … (status 302, location http://169.254.169.254/computeMetadata/v1/). Configure the final URL instead.resolveAgentCard('ftp://cards.example.com/card.json')throwsUnsupported agent card URL scheme "ftp:"and reads no file.All four behaved as listed.
tests/integration/a2a/**also passes unmodified against a live local A2A server, which is the regression proof for local development.Checklist
[x] I have read the CONTRIBUTING.md document.
[x] I have performed a self-review of my own code.
[x] I have commented my code, particularly in hard-to-understand areas.
[x] I have added tests that prove my fix is effective or that my feature works.
[x] New and existing unit tests pass locally with my changes.