Public: anyone can read this; the crew can change it.
The egress proxy judges an IPv6 destination by its bytes, so `::`, `0::1` and embedded-v4 forms are private #14997
Check · Review · Land · Live done — Landed and live in production.
The egress gate now judges an IPv6 CONNECT destination by its parsed bytes, so other spellings of private addresses no longer pass as public. The new test passes with the fix and fails 18 of its 30 cases on main.
shipped production is serving it deploy 9504585
1 earlier comment · 1 event
The egress gate now judges an IPv6 CONNECT destination by its parsed bytes, so other spellings of private addresses no longer pass as public. The new test passes with the fix and fails 18 of its 30 cases on main.
What changed
isPublicAddress(src/apps/egress.ts) now checks the address bytes fromkernel/cidr.tsagainst these ranges, all private:::/96:::,0::1,0:0:0:0:0:0:0:1and the old::a.b.c.dformfec0::/10(site-local) and64:ff9b:1::/48(NAT64 local use)- the existing
fc00::/7,fe80::/10andff00::/8
- Embedded IPv4: for
64:ff9b::/96(NAT64) and2002::/16(6to4), the gate pulls out the IPv4 address inside and judges that, with the same IPv4 rules as before. So64:ff9b::a9fe:a9feand2002:7f00:1::1are refused. - Canonical spelling:
deciderewrites an IPv6 literal into its one short form before comparing it with origins, grants and declared hosts, so0:0::1and::1are the same destination.
What to look at
- NAT64 is not refused as a whole range. The issue lists
64:ff9b::/96as private, but DNS64 resolvers hand out these addresses for IPv4-only public hosts, and the issue's risk note says not to refuse real public destinations. So64:ff9b::8.8.8.8still passes. This matcheskernel/outbound.ts, and the test that checks the two judges agree still passes. - Bare IPv6 entries in
forge.jsonegressdon't work, and this change doesn't fix that.hostAllowedsplits each entry at its last colon, so2606:4700::1111is read as host2606:4700:on port 1111. This was already the case on main. The test checks canonical matching throughoriginsinstead.
Tests
test/egress-ipv6-literal.test.tsis a table over 23 private spellings and 5 public ones (Cloudflare, Google DNS, a Google address, and NAT64 and 6to4 wrappers of 8.8.8.8). It also checks thatdeciderefuses every private spelling as private without resolving anything, and that a public literal is never called private.- Passing here:
scripts/gate.ts --fix(no changes),tsc --noEmit, and everytest/egress,test/outboundandtest/containfile: 277 pass, 0 fail. - 30 tests were skipped: the unix-socket and cell suites can't run in this sandbox's loopback mode, so the forge's check covers them.
scripts/fast.tsnamed 3,084 files, too broad to run here, so I picked the test files above myself.
Tick this finding in #14767 when this lands.
🤖 Generated with Claude Code
Approved. Judging by parsed bytes is correct: all-zero, ::1 in any spelling, ::a.b.c.d, fec0::/10, NAT64 local use, and 6to4 / NAT64 judged by the embedded v4. The CONNECT host is canonicalised before it is compared with origins. The table test covers 23 private and 5 public forms, and the refusal-before-resolve test is good. This is a small security change with no UI, so there is nothing to look at in the preview.
One deviation from box 1: 64:ff9b::/96 is not refused as a whole range. It is judged by its embedded v4, so 64:ff9b::8.8.8.8 passes. The reasoning (DNS64 hands out these addresses for public hosts; it matches kernel/outbound.ts) is sound and the metadata and loopback forms are refused, so I do not block on it. If the owner wants the whole /96 refused, that is a follow-up.
Two things I would do next:
- Fix hostAllowed so a bare IPv6 entry in forge.json egress is not split at its last colon (already broken on main). Then test canonical matching through hosts as well as origins.
- Decide on the NAT64 policy for the whole /96 and record it in the issue.
Left #14901 open: 1 unticked item remain (the CONNECT host is canonicalised and judged by parsed bytes: all-zero, ::1, fec0::/10, 64:ff9b::/96, 2002::/16 (by the embedded v4) and ::a.b.c.d are private).
The egress gate now judges an IPv6 CONNECT destination by its parsed bytes, so other spellings of private addresses no longer pass as public. The new test passes with the fix and fails 18 of its 30 cases on main.
What changed
isPublicAddress(src/apps/egress.ts) now checks the address bytes fromkernel/cidr.tsagainst these ranges, all private:::/96:::,0::1,0:0:0:0:0:0:0:1and the old::a.b.c.dformfec0::/10(site-local) and64:ff9b:1::/48(NAT64 local use)fc00::/7,fe80::/10andff00::/864:ff9b::/96(NAT64) and2002::/16(6to4), the gate pulls out the IPv4 address inside and judges that, with the same IPv4 rules as before. So64:ff9b::a9fe:a9feand2002:7f00:1::1are refused.deciderewrites an IPv6 literal into its one short form before comparing it with origins, grants and declared hosts, so0:0::1and::1are the same destination.What to look at
64:ff9b::/96as private, but DNS64 resolvers hand out these addresses for IPv4-only public hosts, and the issue's risk note says not to refuse real public destinations. So64:ff9b::8.8.8.8still passes. This matcheskernel/outbound.ts, and the test that checks the two judges agree still passes.forge.jsonegressdon't work, and this change doesn't fix that.hostAllowedsplits each entry at its last colon, so2606:4700::1111is read as host2606:4700:on port 1111. This was already the case on main. The test checks canonical matching throughoriginsinstead.Tests
test/egress-ipv6-literal.test.tsis a table over 23 private spellings and 5 public ones (Cloudflare, Google DNS, a Google address, and NAT64 and 6to4 wrappers of 8.8.8.8). It also checks thatdeciderefuses every private spelling as private without resolving anything, and that a public literal is never called private.scripts/gate.ts --fix(no changes),tsc --noEmit, and everytest/egress,test/outboundandtest/containfile: 277 pass, 0 fail.scripts/fast.tsnamed 3,084 files, too broad to run here, so I picked the test files above myself.Tick this finding in #14767 when this lands.
🤖 Generated with Claude Code
Closes #14901