Researchers
The netmask npm package incorrectly parsed IP addresses with leading zeros as decimal instead of octal, so an address like 0127.0.0.1 was treated as [redacted] rather than 87.0.0.1. An attacker could supply such addresses to bypass private-IP checks in applications using netmask, potentially leading to server-side request forgery or remote file inclusion.
sick.codes
Published on sick.codes
The following research outlines a vulnerability discovered in netmask npm package that is currently used by 278,722+ other projects. The vulnerability has been present for 9 years.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
The ip2long function in netmask used parseInt with base 10 on each octet, so it stripped leading zeros and treated octal-looking input as decimal, rather than parsing it as octal.
Impact
Applications that use netmask to classify IP addresses could be tricked into making requests to internal services (SSRF) or fetching remote files (RFI), or conversely into treating public addresses as private; the text notes that most of the 270,000 dependent projects are probably not vulnerable because it depends on how they use the package.
What the attacker needed
Application uses netmask to filter IPs; attacker can supply an IP address; no special account needed
The fix
The package was fixed by parsing leading-zero octets as octal, rejecting whitespace, and handling hexadecimal input correctly, with the maintainer releasing a patch.
How it was found
- Install the netmask package and create a block for a private range such as [redacted]/8.
- Call block.contains with an address that has a leading zero, such as 0127.0.0.1.
- Observe that netmask returns true (treating it as [redacted]) even though the real address is 87.0.0.1.
- Use such an address in an application that relies on netmask to filter private IPs, and see that the request goes to the unintended destination.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
An IP address is normally written in decimal, but some systems also accept a leading zero to mean the number is in octal (base 8). The netmask library did not handle that correctly, so it thought an address like 0127.0.0.1 was the same as [redacted] (localhost) when it actually points to [redacted] on the internet. If a program uses netmask to decide whether an address is private or public, an attacker can trick it into allowing requests to internal services or blocking legitimate ones.
What is SSRF?
The server can be made to fetch an address the attacker chooses, reaching internal services, cloud metadata or other customers' data.