nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

[Bug] fetch_url SSRF guard does not block IPv4 addresses embedded in IPv6 forms (IPv4-compatible, NAT64, 6to4)

Open addyCooks opened this issue 1 month ago • 4 comments

Summary

assertPublicHttpUrl blocks ::1, link-local, unique-local and ::ffff: mapped addresses, but not other IPv6 spellings that embed a private IPv4 address. I could not reach loopback with them on my machine, so this is a gap in the guard and not a proven exploit.

Steps to reproduce

Call assertPublicHttpUrl with each URL below.

Expected behaviour

Each throws Cannot fetch from internal/private network address.

Actual behaviour

http://[::127.0.0.1]/       (host [::7f00:1])        ALLOWED
http://[64:ff9b::7f00:1]/                            ALLOWED
http://[2002:7f00:1::]/                              ALLOWED
http://[::ffff:0:7f00:1]/                            ALLOWED
http://[::ffff:127.0.0.1]/                           blocked

IPv4 192.0.0.0/24, 198.18.0.0/15, multicast and 255.255.255.255 are also allowed. A spec expecting a throw for http://[::127.0.0.1]/ fails with Function returned: undefined. A live test against a local listener on Windows gave ENETUNREACH for all four allowed forms, while [::ffff:127.0.0.1] connected. Whether they reach internal hosts depends on the network (for example a NAT64 gateway), which I could not test.

Environment

Windows 11, Node v22.22.3, Nanocoder 1.31.0 (main at 948a4e74)

Suggested fix

  • source/tools/fetch-url-guard.ts:64 (isBlockedIpv6): decode the embedded IPv4 for ::/96, 64:ff9b::/96, 2002::/16 and ::ffff:0:0/96, and run it through isPrivateOrLocalIpv4.
  • Add the missing IPv4 ranges to isPrivateOrLocalIpv4.
  • Earlier work: #734, #1089, #1662. DNS rebinding is a documented known gap and out of scope here.

addyCooks avatar Nov 02 '26 16:11 addyCooks

I'd like to take this one. Plan: in isBlockedIpv6 (source/tools/fetch-url-guard.ts), decode the IPv4 embedded in ::/96, 64:ff9b::/96, 2002::/16 and ::ffff:0:0/96 and run it through isPrivateOrLocalIpv4; add 192.0.0.0/24, 198.18.0.0/15, multicast and 255.255.255.255 to the IPv4 check; and add specs for each URL in your table that fail before the change. I'm on Windows 11 and will run pnpm test:all before opening the PR.

NishilRathod avatar Nov 03 '26 06:11 NishilRathod

Hi @addyCooks / team, I'd like to work on this issue!

I have implemented and validated the fix in PR #1959 with complete unit test coverage in fetch-url-guard.spec.ts (handling ::/96, 64:ff9b::/96, 2002::/16, ::ffff:0:0/96, and remaining non-public IPv4 ranges), typechecks (tsc --noEmit), and a patch changeset.

Could you please assign this issue to me? Thanks!

dhruvil-codes avatar Nov 04 '26 17:11 dhruvil-codes

Hey @dhruvil-codes , thanks for offering! @NishilRathod asked first for this issue, so this one goes to them.
Feel free to grab another open issue in the meantime!

addyCooks avatar Nov 05 '26 07:11 addyCooks

@NishilRathod, go for it!

addyCooks avatar Nov 05 '26 07:11 addyCooks