A serious vulnerability existed in the Netmask npm package that could allow server-side request forgery. Currently, the Netmask npm package backs over 278,000 open source projects. Hence, the vulnerability that remained undetected for 9 years posed a risk to thousands of projects.
Netmask npm Package Vulnerability
Multiple security researchers have recently shed light on a serious vulnerability affecting the Netmask npm package. Netmask has garnered a huge user base as it parses IPv4 CIDR blocks.
Despite being popular, the package had a serious security vulnerability that remained unnoticed for 9 years. Given the user base in hundreds of millions globally, malicious exploitation of the flaw could have triggered devastating results. Though, the impact of the exploitation mainly depended on how a project used the package.
Sharing the details in a post, Sick Codes revealed how multiple researchers contacted them for an SSRF vulnerability in the package. These researchers include?John Jackson,?Nick Sahler, Victor Viale, and Kelly Kaoudis.
Briefly, the vulnerability existed because of the improper interpretation of the first octet of the IP address when expressed in octal format. Instead of evaluating it by first converting it to the decimal format, the Netmask simply considered the octal format as the decimal one and stripped the leading zeros.
As Sick Codes explained,
The problem is, private-ip thinks 0127 is 127 because it is not evaluating the first octet, which is in octal format, as the true decimal value 87.
private-ip thinks?0127.0.0.1?is?localhost, but it’s really?18.104.22.168.
Even worse, it goes the other way too!
While this issue doesn’t sound dangerous at first, the researchers explained how an adversary could exploit this glitch.
If your browser recognizes octal literals, but a nodejs application does not, users can submit all kinds of malevolent URLs that seem internal, but really go to remote files.
On the other hand, users can ALSO submit URLs that seem public, but they’re actually very private!
Hence, exploiting the bug could result in server-side request forgery to remote file inclusion by an attacker.
The Netmask npm package vulnerability has received the CVE ID CVE-2021-28918. The researchers found this vulnerability on March 16, 2021, that they reported to the vendors on March 17, 2021.
As observed, the bug affected Netmask v1.1.0 and below. Hence, the vendors deployed a fix with v.2.0.
However, another researcher RyotaK?discovered a bypass for the fix in v.2.0. Thus, the vendors had to rewrite the patch that they eventually released with v.2.0.1. The bypass has received the CVE ID CVE-2021-29418.
Since the patched version is now available, all users must ensure they update to the latest package version.