The widely used npm library netmask has a networking vulnerability arising from how it parses IP addresses with a leading zero, leaving an estimated 278 million projects at risk.
Researchers Victor Viale, Sick Codes, Kelly Kaoudis, John Jackson, and Nick Sahler have disclosed a digital nasty, tracked as CVE-2021-28918, in the hugely widespread netmask npm package.
It’s a handy bit of code used for parsing and comparing IP addresses, and the flaw lies in how it handles mixed-format IP addresses. Namely, what it does when there is a leading zero.
As an example, the IPv4 address 127.0.0.1 is
localhost. However, pop 0127.0.0.1 into a browser and that 0127 gets treated as octal and changed to its decimal equivalent, which is 87. Thus 0127.0.0.1 is actually 184.108.40.206.
Unless one is using netmask, in which case the leading zero is simply stripped off and 0127 becomes 127, an address that, via netmask, looks like a private IP could be submitted, but is actually a public address (along with all the nefarious activity that might entail).
“Even worse, it goes the other way too!” exclaimed the researchers. Enter 0220.127.116.11 and, while a browser would treat it as an address in the 127 loopback range, netmask would again lose that leading zero and treat it as 18.104.22.168; a public rather than private address.
Trail of Bits security peeps emit tool to weaponize Python’s insecure pickle files to hopefully now get everyone’s attention
“For almost a decade,” the researchers went on, “netmask has been incorrectly reading octal input data as a string; just stripping the 0 at the front and using the rest of the data as legitimate.”
As for the vulnerability of those hundreds of thousands of projects, it depends on how netmask is being used.
The researchers estimated that the package is used in more than 278,000 projects and accounts for millions of downloads per week – although, to be fair, an awful lot of those will have been down to automated DevOps pipelines rather than actual humans clicking a button.
The node-netmask maintainer, Olivier Poitrey, was given kudos by the team for being “super responsive”. The first patch arrived mere days after the 17 March notification date.
Affected users, and there are likely to be a lot, should upgrade to version 2.0.0 of the library.
The incident is a reminder that blithely relying on popular components is no guarantee that one will be immune from vulnerabilities.
Ax Sharma, security researcher at Sonatype, said such users “may not realise that they could be potentially vulnerable to anti-Server-Side Request Forgery (SSRF) bypasses or remote file inclusion (RFI) should they be purely relying on netmask for parsing IP addresses, without adding their own proper input sanitisation and normalisation checks.
“This highlights the need for proper input hygiene and never trusting input no matter the source. In this case, for example, the fixes… applied to netmask now take into account that IP addresses can also be provided in octal or hexadecimal formats, something users of netmask could also have implemented on their end as an extra precaution.”
As the saying goes: Trust No One. ®
Is your business effected by Cyber Crime?
If a cyber crime or cyber attack happens to you, you need to respond quickly. Cyber crime in its several formats such as online identity theft, financial fraud, stalking, bullying, hacking, e-mail fraud, email spoofing, invoice fraud, email scams, banking scam, CEO fraud. Cyber fraud can lead to major disruption and financial disasters. Contact Digitpol’s hotlines or respond to us online.
Digitpol is available 24/7.
UK +44 20 8089 9944