Skip to content

Match Node's canonicalizeIP for IPv6 zone ids - #8609

Merged
littledivy merged 1 commit into
mainfrom
littledivy/2026-11-18-audit-rjsg-node-url
Nov 18, 2026
Merged

littledivy merged 1 commit into
mainfrom
littledivy/2026-11-18-audit-rjsg-node-url

Conversation

@littledivy

Copy link
Copy Markdown
Member

tls.checkServerIdentity() canonicalizes the host and each IP Address: SAN with node:url's internal canonicalizeIp. Node does this with uv_inet_pton and uv_inet_ntop. Those drop an IPv6 zone id and print an IPv4-compatible address as ::a.b.c.d. workerd parsed the address with Rust's IpAddr, which rejects fe80::1%eth0, so a host or SAN with a zone id never matched:

tls.checkServerIdentity('fe80::1%eth0', { subject: {}, subjectaltname: 'IP Address:FE80:0:0:0:0:0:0:1' });
// Node: undefined
// workerd: "IP: fe80::1%eth0 is not in the cert's list: fe80::1"

A SAN of 0:0:0:0:0:0:102:304 also showed up as ::102:304 in the error message, where Node prints ::1.2.3.4.

In this patch canonicalize_ip parses IPv4 on the whole input, cuts IPv6 input at the first %, and writes IPv4-compatible addresses in dotted form. A mismatch turning into a match is additive, so this ships without a compatibility flag. The new url-test.rs cases and the three checkServerIdentity cases in tls-nodejs-test fail without the fix.

tls.checkServerIdentity() canonicalizes the host and each "IP Address:"
SAN with node:url's internal canonicalizeIp. Node does this with
uv_inet_pton and uv_inet_ntop, which drop an IPv6 zone id and print an
IPv4-compatible address as ::a.b.c.d. workerd parsed with Rust's IpAddr,
which rejects "fe80::1%eth0", so a host or SAN with a zone id never
matched (Node: valid; workerd: "IP: fe80::1%eth0 is not in the cert's
list: fe80::1"), and a SAN of 0:0:0:0:0:0:102:304 showed up as ::102:304
in the error.

In this patch canonicalize_ip parses IPv4 on the whole input, cuts IPv6
input at the first '%', and writes IPv4-compatible addresses in dotted
form. A mismatch turning into a match is additive, so there is no
compatibility flag.
@littledivy
littledivy requested review from a team as code owners November 18, 2026 13:35

@clanky-the-clanker clanky-the-clanker Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Approved — No issues found: the new canonicalize_ip matches libuv's inet_pton/inet_ntop handling of zone ids and IPv4-compatible addresses, and the new tests cover it.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

📋 Code Quality: ✅ LGTM

I compared canonicalize_ip with libuv's uv_inet_pton / uv_inet_ntop and found no issues.

  • Zone ids: the cut at the first % matches libuv.
  • Order of parsing: IPv4 is tried on the whole input first, as in libuv.
  • Dotted output: the ::a.b.c.d condition is the same as inet_ntop6's six-zero-word case.
  • IPv4-mapped addresses: these already print in dotted form through Rust's Display.
  • Tests: the Rust and JS cases cover zone stripping, the empty zone, IPv4 with a zone, compatible and mapped forms, ::0.0.0.1 and ::.

📝 Documentation: ✅ LGTM

The updated doc comment on canonicalizeIp describes what the code now does.


Reviewed commit: 5f6d7490

@littledivy
littledivy merged commit 11ec07e into main Nov 18, 2026
23 of 24 checks passed
@littledivy
littledivy deleted the littledivy/2026-11-18-audit-rjsg-node-url branch November 18, 2026 15:24
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.

2 participants