Netmask NPM package, used by 270k+ projects, vulnerable to octal input data
sick.codes
sick.codes
The bug is caused by an esoteric IP address notation. Nearly everyone who would need this functionality would get the implementation wrong. In the exact same way the author of netmask did. However, netmask is now fixed and this bug will now no longer appear in any new implementation.
Even better: npm will start to give warnings about this vulnerable package and will provide a fix through npm audit. Everything that is maintained in a reasonable way, will now no longer have this vulnerability.
This is not a failure of dependencies or npm: this is an example why those are good things.
I think the really big issue with all these package management solutions is how deep the dependency requirements go. One package depends on another package that depends on 18 other packages, that depend on 30 other packages, and it's packages all the way down.
No one is going to review all of those packages regularly. It's just not going to happen. Sure, it's less a problem for the big popular packages, but those big popular packages still depend on a lot of smaller packages and those smaller packages are extremely vulnerable due to sheer lack of eyes on it.
Everyone always says "I won't use software that isn't open source because the code is in the open and vulnerabilities can be found" but the fact of the matter is someone has to be reviewing that code to find them. I'd love to better understand how many people are out there reviewing code as part of their process. I'll be it's a lot less than anyone would like.
It’s really just the consequence of asymmetrical outcomes. Most of the time it all just works and so if you don’t keep up you’re out of business. When something goes wrong the whole world is exposed.
I guess with npm you do have the additional wrinkle that much of it is outside the std lib which increases risk a bit.
Maybe now because everyone is entrenched, but the alternative could have been to offer a robust "standard library" in the first place that lets you cover 90% of developer's use cases without needing external packages. See: Java, C/C++, Go, Python...
Only JavaScript seems to be a special snowflake where doing even the most basic tasks requires downloading 50 packages.
The claim that C has a safe and/or robust standard library is very bizarre. Python only got there after years of community development (Python is 30 years old, Node is 11), and even today I wouldn't consider it particularly high quality.
Python is specifically known as a “batteries included” language, and Go has stdlib support for the core use cases the language is designed for.
I wouldn’t say that C++ or Java have particularly rich standard libraries outside of IO and common data structures, and C is downright anaemic.
The Java standard library is about as rich as it gets. I rarely ever have had to use external dependencies when working on Java projects.
First, you'd never develop everthing in house. But there is a middle ground between selecting a few very well known dependencies that are nowhere near practical to do in-house (e.g. OpenSSL) and the extreme of the npm world where every one-liner is a package.
Another great solution is to select a language with a rich well-tested standard library.
Rely on the standard library for 80% of your utility class needs. Complement with a small number of well-known external libraries for another 20% and the remaining 10% build in-house.
If one can't, off the top of their head, name every external dependency and where they come from, that's too many.
Fun fact: there are even more IP address notations... try ping'ing 0x7F000001 or 2130706433, for example - on OS X commandline and Google Chrome at least, these resolve to localhost.
The writeup at https://www.bleepingcomputer.com/news/security/critical-netm... has a link to an informative ancient expired IETF draft https://tools.ietf.org/html/draft-main-ipaddr-text-rep which describes how things stood in 2003.
A more recent and more official RFC from the IETF on the security implications of inconsistent parsers discusses the issue behind this CVE https://tools.ietf.org/html/rfc6943#section-3.1.1
The problem is that for a very long time the IETF did not specify the textual syntax of IPv4 addresses, and the POSIX specification for parsing dotted quads is bonkers.
I think it is unfortunate that they fixed the bug by aligning with inet_aton()’s ancient foolish support for octal, instead of inet_pton()’s newer strict decimal syntax, forbidding leading zeroes.
https://play.rust-lang.org/?version=stable&mode=debug&editio...
Report the issue in https://github.com/rust-lang/rust/issues/83648
I like the twist in the vulnerability report, using differences between IPv4 parsers to get past protections against things like SSRF, which I don’t think is explicitly mentioned in the IETF draft and RFC that I linked to.
I have the same feeling about PyPI, but to a way lesser extent. Python can already do much by itself, so that the amount of packages one installs is controllable.
Both are open-sourced and are written by pretty much the same people.
>>> import ipaddress
>>> ipaddress.ip_address('010.0.0.1').is_private
True
Even though the documentation claims that "Leading zeroes are tolerated only for values less than 8 (as there is no ambiguity between the decimal and octal interpretations of such strings)."https://docs.python.org/3.9/library/ipaddress.html#ipaddress...
But this is not an issue:
>>> import ipaddress
>>> ipaddress.IPv4Address('010.0.0.1')
IPv4Address('10.0.0.1')https://pypi.org/simple/ (caution— multi-megabyte html)
It's great to have high quality third party libraries but stuff like most of lodash should be in a stdlib, already.
Say you grab a 10 years old Java/.Net project source and a node one, and try to setup a developer environment to be able to create a fix. Would you bet that on average is 10X harder to get stuff to run on node ?
I think you’re being a little optimistic there.
Consider Java’s URL class, for instance. Its equals() implementation will resolve the hostname in both URLs and consider them equal if they resolve to the same IP address. So that’s a) completely wrong, b) a potential source of security problems (consider an attacker pointing their hostname to your IP address to control URLs that are “equal” to your URLs, for instance), c) horribly unpredictable (two URLs may or may not be the same depending on whether you are online or not), and d) awful for performance (introduces a network lookup even for hashcode(), for instance).
That’s significantly worse than a bug like this, which is essentially an oversight that failed to consider an obscure notation nobody uses.
> Say you grab a 10 years old Java/.Net project source and a node one, and try to setup a developer environment to be able to create a fix. Would you bet that on average is 10X harder to get stuff to run on node ?
Java is probably okay, but I’ve tried this with .NET and it was extremely painful.
I would bet that on average Java standard library code(that is not deprecated) will be higher quality then npm packages.
With many small libraries there often is a single person working on it and others assuming "oh, somebody will have reviewed it"
This can happen with a big library as well (as individual maintainers "own" specific parts) but there it is easier to establish a review culture.
(Whether a review would have caught this specific case is yet another question, but again having an organisation could guarantee a timely response, is read if depending on a single contributor)
This of course depends on the library in question, as some non-std libraries are certainly subjected to more checks than others.
Many companies have auditing requirements for external dependencies, with increasing strictness for more sensitive domains.
It would be immensely helpful to distribute this effort.
We could have a platform that pays top domain experts and security researchers for audits. Companies can get access to via a subscription model or by paying for specific dependencies.
Vulnerabilities would also be reported and fixed, helping everyone, and companies benefit by having a trustworthy source for audits and save internal work.
Ideally the platform would be successful enough to open up a good amount of audits publicly to benefit the whole community.
Also related: cargo-crev [1] explores a concept for shared auditing and trust for Rust crates.
As I said, many companies require a review/sign off for each dependency (version). Since they usually can't get them externally, they have do it internally.
Enterprises also throw a lot of money at support contracts they never use, there is absolutely space for auditing expenses that give assurance and will be more thorough than any internal process.
First by the netmask function that reads 0127 as 127 and the second time by the js-network stack code that reads it differently.
The solution is not to change netmask to ignore leading zeros. The solution is to parse it into 4 uint8 values, validate the netblock on the numeric values and if the range is approved, generate the ip-address from your four numbers. That way you know for sure that the js-network stack is going to interpret it as you intend.
There are some beautiful (horrifying) examples in this presentation: https://www.blackhat.com/docs/us-17/thursday/us-17-Tsai-A-Ne...
Bonus points for security scanners that diagnose grave vulnerabilities in frontend bundles but the backend is some Python/Ruby/guaranteed-no-npm API.
You want customers to be able to enter host IPs that they control and your site will retrieve the URL on that site that they specify to confirm it's available.
You don't want customers to be able to request things like http://127.0.0.1:8080 or http://192.168.1.1:6443 as you've got internal systems running there that are not for external use.
So in your code you set the internal only ranges to be blocked.
If you used this library to do that, it would be possible to bypass the restriction and request internal IPs by using octal encoding, as the customer could enter an octal IP and then the conversion would allow for ranges that should be blocked, to be requested.
The protection has to sit in the HTTP client library after resolving the hostname to IP address, before connecting.
Am I going crazy or is the `or` clause completely pointless?
I'm sure there's businesses that would pay for a dependency provider that ensures all versions of all packages hosted there are reviewed, security checked and signed off on. With a warranty clause, so that if something like this does come out, they get compensated for damages (if actively exploited). A bug bounty should of course also be offered.
A bit like Apple's app store but for libraries. Or the ideal thereof anyway. Basically a library developer can't just keep spamming updates, they would have to be more careful with what they submit.
And of course, library devs would get a slice of the pie, an X amount per installation.
It probably wouldn't work because people (even large enterprises who cannot afford any security issue like this) prefer free.
You get companies doing things like version checking and basic scans for malware, but that wouldn't catch issues like this.
My guess is that the volume of security review you'd need to do, for it to be usable by enough companies, is massive and a lot of the review would need to be manual.
Then as you add libraries you need to dedicate resources to reviewing every new release.
Do they do a one-time review, problem there is it won't catch new issues.
Do they provide PRs for fixing issues found, that's another level of complexity.
If the library owners don't patch promptly, do MS fork the lib, if they do, will people move to their forked version?
It's a complex area to say the least :)
It'd be great to see more companies take it on but I have a feeling it'll be a long time before we see significant coverage of this kind of issue.
The real problem is that the standard library of node/javascript is too small so you need dozens of packages for basic operations.
That would be Microsoft.
I'm pretty sure this really is a thing in some places (defense contractors, etc), but I'm curious if anyone's actually been exposed to a real company that really reviews everything.
Unvetted code essentially marketed as an extended standard library.