`parseIP` and browser `isIP` accept IPv4 zone suffixes and malformed IPv6 zones (`1.2.3.4%eth0`, `::1%`)

Aperta
#35 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
Mezza giornata
Idoneità per principianti
62/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
node.js, typescript
Ambito
networking

Direzione di ricerca

Start in src/parse.ts, where parseIP and parseIPv6 both run input.split("%")[0] before parsing. Run the repro.mjs script from the issue to compare the Node isIP with the browser build in lib/is-ip.js, which also needs the same fix. Done when %eth0 on IPv4, ::1%, and ::1%a%b return false or undefined in every build, matching node:net.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

parseIP and parseIPv6 strip everything from the first % without checking that the address is IPv6 or that the zone index is valid, causing invalid inputs to parse as IP bytes and causing the browser build of isIP to disagree with both the Node build and ipVersion.

npm install @chainsafe/[email protected]
node repro.mjs

repro.mjs:

import { isIP } from "@chainsafe/is-ip";
import { parseIP, parseIPv6 } from "@chainsafe/is-ip/parse";
import * as browser from "./node_modules/@chainsafe/is-ip/lib/is-ip.js";

console.log('node isIP("1.2.3.4%eth0"):', isIP("1.2.3.4%eth0"));
console.log('browser isIP("1.2.3.4%eth0"):', browser.isIP("1.2.3.4%eth0"));
console.log('browser ipVersion("1.2.3.4%eth0"):', browser.ipVersion("1.2.3.4%eth0"));
console.log('parseIP("1.2.3.4%eth0"):', parseIP("1.2.3.4%eth0"));

console.log('node isIP("::1%"):', isIP("::1%"));
console.log('browser isIP("::1%"):', browser.isIP("::1%"));
console.log('parseIPv6("::1%"):', parseIPv6("::1%"));
console.log('parseIPv6("::1%a%b"):', parseIPv6("::1%a%b"));

Actual output:

node isIP("1.2.3.4%eth0"): false
browser isIP("1.2.3.4%eth0"): true
browser ipVersion("1.2.3.4%eth0"): undefined
parseIP("1.2.3.4%eth0"): Uint8Array(4) [ 1, 2, 3, 4 ]
node isIP("::1%"): false
browser isIP("::1%"): true
parseIPv6("::1%"): Uint8Array(16) [
  0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0,
  0, 0, 0, 1
]
parseIPv6("::1%a%b"): Uint8Array(16) [
  0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0,
  0, 0, 0, 1
]

Expected: all of the above return false / undefined, matching node:net and RFC 4007 section 11.2 (zone indices apply only to IPv6 addresses, must be non-empty, and cannot contain %).

Versions: @chainsafe/[email protected] (npm latest) and master (57bbef6), Node.js v26.13.0.

In src/parse.ts, both parseIP and parseIPv6 run if (input.includes("%")) { input = input.split("%")[0]; } before parsing, which drops arbitrary %... suffixes on IPv4 inputs in parseIP and skips validating the zone suffix on IPv6 inputs.

Credit: https://ucsbplse.github.io/

Lingua principale
TypeScript
Stelle
3
Fork
2
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ChainSafe/is-ip

Tutte le issue di ChainSafe/is-ip

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.