Skip to content

fix(network): read IPv6 addresses that end in an IPv4 address - #63

Open
VISHNU0906 wants to merge 1 commit into
OWASP:mainfrom
VISHNU0906:fix/ipv6-embedded-ipv4
Open

VISHNU0906 wants to merge 1 commit into
OWASP:mainfrom
VISHNU0906:fix/ipv6-embedded-ipv4

Conversation

@VISHNU0906

Copy link
Copy Markdown
Contributor

What this changes

IPv6 lets the last 32 bits be written as an IPv4 address (RFC 4291 section 2.2), and that is how IPv4-mapped addresses usually show up in logs and socket output: ::ffff:192.168.1.1. Expand IPv6, Compress IPv6, Parse IPv6 address and IPv6 transition addresses all rejected that form ('192.168.1.1' is not a valid IPv6 group.), so the transition operation could not read the very address it describes unless it was rewritten as ::ffff:c0a8:101 first.

Both IPv6 parsers (network.ts and packets.ts) now turn a trailing dotted IPv4 address into its two hex groups before splitting, and still refuse an octet above 255. Output is unchanged: the address comes back as hex groups, the same as before for the hex spelling.

Related issue

none

How it was tested

New cases, both fail on main:

  • operations.verified.test.ts: ::ffff:192.168.1.1 expands to 0000:0000:0000:0000:0000:ffff:c0a8:0101, 64:ff9b:0:0:0:0:192.0.2.33 compresses to 64:ff9b::c000:221 (the same values Python's ipaddress reads), and ::ffff:192.168.1.256 is refused.
  • packets.test.ts: IPv6 to IPv4 on ::ffff:192.168.0.1 gives IPv4-mapped address of 192.168.0.1, and Parse IPv6 address shows the full form of ::ffff:10.0.0.1.

I also compared Expand/Compress against ipaddress on about 60 addresses (random zero runs, ::, 1::, ::1.2.3.4); on main the only mismatches were the four dotted ones, which it refused.

Locally on Node 24 and Node 22: npm run lint, npm run typecheck, npm run test -- --run, npm run build and npm run check:sdk-dist, plus the CI Chrome load check, the GraalJS Java provider checks and npm audit --audit-level=high.


Checklist

  • npm run lint, npm run typecheck, npm run test and npm run build all pass locally
  • Tests added or updated, including a case that would have failed before this change
  • No any introduced in application code
  • No eval, new Function, dangerouslySetInnerHTML, or innerHTML assignment
  • No new runtime dependency (or it was discussed in an issue first, linked above)
  • User-facing strings go through the i18n map (only an operation error, written like the others in packets.ts)
  • Layout / RTL and keyboard checks (no UI change)
  • Malformed and hostile input handled without crashing or hanging the tab

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.

1 participant