667 points · by ManuelKiessling · 5y ago · 281 comments
It came with the actual title, although arguably not the correct one.
>"we received a report to our security bug bounty program of a vulnerability that would allow an attacker to publish new versions of any npm package using an account without proper authorization."
>"This vulnerability existed in the npm registry beyond the timeframe for which we have telemetry to determine whether it has ever been exploited maliciously. However, we can say with high confidence that this vulnerability has not been exploited maliciously during the timeframe for which we have available telemetry, which goes back to September 2020."
>Any version of any npm package published before September 2020 could have been tampered with by anyone aware of that exploit and no-one would be any the wiser. That is pretty bad news.
> Second, on November 2 we received a report to our security bug bounty program of a vulnerability that would allow an attacker to publish new versions of any npm package using an account without proper authorization.
They correctly authenticated the attacker and checked they were authorised to upload a new version of their own package, but a malicious payload allowed the attacker to then upload a new version of a completely unrelated package that they weren't authorised for. Ouch!
Yeah, this is what's going to keep me up tonight. Yikes.
I can't help but wonder if the root cause was HTTP request smuggling, or if changing package.json was enough.
How do we even mitigate against these types of supply-chain attacks, aside from disabling run-scripts, using lockfiles and carefully auditing the entire dependency tree on every module update?
I'm seriously considering moving to a workflow of installing dependencies in containers or VMs, auditing them there, and then perhaps commiting known safe snapshots of node_modules into my repos (YUCK). Horrible developer experience, but at least it'll help me sleep at night.
Don’t import thousands of modules from third parties just to write a simple web app. If you have 10 stable dependencies it’s no problem to vendor them and vet changes. If you have 10k you’ve entirely given up on any pretence of security.
The NodeJS team refuses to discuss NPM because it's a separate 3rd party. And yet.... this NodeJS Core module comes pre-installed as a global NPM package.
We're just getting started.
This module installs or even reinstalls any supported package manager when you execute a script with a name that would match any that they'd recognise. Opt-in for only a short period, and intending to expand beyond package manager installations.
Amidst all that's been going on, NPM (Nonstop Published Moments) is working on a feature that silently hijacks user commands and installs foreign software. The code found in those compromised packages operated in a similar manner and was labeled a critical severity vulnerability.
The following might actually make you cry.
Of these third party remote distributions it's downloading, the number of checksum, keys, or even build configurations that are being verified is 0.
The game that Microsoft is playing with their recent acquisitions here is quite clear, but there's too much collateral damage.
The reason packages are so big is the complexity for an interesting app is irreducible. People don't import thousands of modules for fun; they do it because simple software tends towards requiring complex underpinning. Consider the amount of operating system that underlies a simple "Hello, world!" GUI app. And since the browser-provided abstractions are trash for writing a web app, people swap them out with frameworks.
I'm working on a React app right now where I've imported about a dozen dependencies explicitly (half of which are TypeScript @type files, so closer to a half-dozen). The total size of my `node_modules` directory is closer to a couple hundred packages. It's 35MB of files. And no, I couldn't really leave any of them out to do the thing I want to do, unfortunately.
Is vendoring in a dependency just slowing things down? Slows down development and bakes existing attacks in longer.
Are there stable dependencies from reputable companies that do the things I want without me vetting 10k submodule imports?
1. Running those builds in VMs is a good idea.
2. Monitoring for weird behavior.
3. Restricting build scripts from touching anything outside of the build directory.
4. Pressuring organizations like npm to step up their security game.
It would be really nice if package repositories:
1. Produced a signed audit log
2. Supported signing keys for said audit log
3. Supported strong 2FA methods
4. Created tooling that didn't run build scripts with full system access
etc etc etc
I started working on a crates.io mirror and a `cargo sandbox [build|check|etc]` command that would allow crates to specify a permissions manifest for their build scripts, store the policy in a lockfile, and then warn you if a locked policy increased in scope. I'm too busy to finish it but it isn't very hard to do.
Signed audit logs seem like a good idea.
Now...how to get developers to avoid using NPM and Yarn altogether on sensitive projects...
I know HN is usually skeptical of anything cryptocurrency/blockchain related, and I am too. But as weird as it sounds, I think blockchain might actually be the solution here.
The problem with dependency auditing is it's a lot of work. And it's also duplicate work. What you'd really like to know is whether the dependency you're considering has already been audited by someone you can trust.
Ideally someone with skin in the game. Someone who stands to lose something if their audit is incorrect.
Imagine a DeFi app that lets people buy and sell insurance for any commit hash of any open source library. The insurance pays out if a vulnerability in that commit hash is found.
* As a library user, you want to buy insurance for every library you use. If you experience a security breach, the money you get from the insurance will help you deal with the aftermath.
* As an independent hacker, you can make passive income by auditing libraries and selling insurance for the ones that seem solid. If you identify a security flaw, buy up insurance for that library, then publicize the flaw for a big payday.
* A distributed, anonymous marketplace is actually valuable here, because it encourages "insider trading" on the part of people who work for offensive cybersecurity orgs. Suppose Jane Hacker is working with a criminal org that's successfully penetrated a particular library. Suppose Jane wants to leave her life of crime behind. All she has to do is buy up insurance for the library that was penetrated and then anonymously disclose the vulnerability.
* Even if you never trade on the insurance marketplace yourself, you can get a general idea of how risky a library is by checking how much its insurance costs. (Insurance might be subject to price manipulation by offensive cybersecurity orgs, but independent hackers would be incentivized to identify and correct such price manipulation.)
The fact that there is actual value here should give the creator a huge advantage over other "Web 3.0" crypto junk.
[0]: https://portswigger.net/daily-swig/smuggling-hidden-backdoor...
Maybe I'm just incredibly cynical from my experiences with the intersection of the JS ecosystem and security, but...
...I'd bet dimes to dollars it's the latter (just changing the package.json). My guess is they authenticate but don't actually scope the authentication properly, and no one noticed because no one thought to look.
Of course, as we've seen in the past decade, there's so much inertia behind the JavaScript ecosystem that none of this is going to fundamentally change. It'll just take another decade or so for the ecosystem to reinvent all of the wheels and catch up to the rest of the space.
And at that point it will probably be considered stuffy and "enterprise" and the new hotness unburdened from such concerns will repeat the cycle again.
Which of the public package systems are the state of the art that should be replicated?
I have had people tell me in discussions online, also entirely seriously, that running a package manager to install a dependency while developing is inherently dangerous and anyone who does it outside of a disposable sandboxed VM deserves everything they get. If the packages are inexplicably allowed to do arbitrary things with privileged access to the local system without warning at installation time then clearly the first part is correct, but victim-blaming hardly seems like a useful reaction to that danger.
Don't trust the package distribution system - use public key crypto.
Like that you can have anything trying to upload but fail the signature check.
and yet a security incident where it was possible to publish any npm package without authentication is nine paragraphs down, and isn't alluded to at all in the page or section titles. I'm not sure that's entirely in the best spirit of transparency.
The result is that instead of a dependency tree of consisting of a few packages or a few dozen, you end up with an unmanageable number like 1700 coming from who knows how many authors.
Nowadays tree shaking means that having a large package with lots of smaller function should work better, especially since adding an import incurs its own overhead, but a lot of older packages are stuck on the small packages model.
The best answer I can provide is to nuke your entire software supply chain from orbit and start over with something new that doesn't require you to depend on potentially hundreds of arbitrary 3rd parties. Factor into this all of your tooling and infrastructure vendors as well.
You might not like our particular brand of medicine, but we are finding massive success in these supply chain matters with a pure Microsoft stack: .NET core/5/6, GitHub, Azure, VS2022, Server 2019, et. al. We also technically use SQLite, but no one has ever attempted to probe us on that vendor, and it is incorporated well enough into the Microsoft death star (Microsoft.Data.Sqlite) to pass as yet another defensive armament at this point. We avoided shitty javascript web stacks by using technologies like Blazor, or just hand-rolling a little vanilla javascript when required (the horror, i know).
The reason we like this path is that we now require virtually zero additional third party dependencies for building our B2B products. .NET6 covers nearly 100% of the functions we require. On top of this we have 1-2 convenience nugets like Dapper (StackOverflow, et. al.), but everything else is System.* or Microsoft.*. The only other 3rd party items we consume into the codebase come from vendors of our customers as part of our integration stack - typically in the form of WCF contracts or other codegen items. Now, we do hedge for the inevitable Microsoft framework churn by not getting too deep into certain pools like AspNetCore. For example, we have rolled all of our own authentication, logging & tracing middleware, since this is the area they seem most hellbent on changing over time.
Certainly, Microsoft has, can, and will drop the ball, but they also have a very long track record available to build [dis]trust upon. For us, we went with the trust path. If our customers run us through the due diligence gauntlet (and they will - we're in the banking industry), we can produce a snarky ~1 item list of vendors that makes life much easier for everyone involved. No one has ever given us a hard time for doing business with Microsoft. Typically, everyone we work with is also to some degree. Is this bad? Maybe. I am ambivalent about the whole thing because of how much energy they have apparently put into the open source side of things. I have actually been able to contribute to their process on GitHub and watch it come out the other side into a final release I could use to correct a problem we were having.
While it seems like a lot of work, IMHO, the tradeoff of using an ecosystem with such a massive attack surface (NPM) is simply a pill we couldn't swallow. For those of us building systems that actually NEED to be secured, the "convenience" of using NPM isn't worth being kept up at night thinking about all the ways your app could be fubar'd.
1)How much JS/CSS are we talking about for heavily interactive pages? Do you not even use light weight libraries like knockoutjs or backbonejs?
2)Have you gone down the Blazor route yet?
3)What kind of system yall are working on that requires this much security? I've worked for a very information sensitive department of one of the top International banks where it was all sorts of npm galore.
We also built our own animation library to handle things like graceful entry and exit transitions (e.g. when an item is deleted, it asynchronously swipes or fades out of view). All of this was done in vanilla JS/CSS. The only external library we used was a sub-1000 line library for toasting messages in the UI. We heavily extended this library and, hopefully, improved upon the original design. We also wrote our own CSS utility library. It's bare bones but it is exactly what we need.
2) We considered Blazor but went with MVC instead. Better suited to our skill set and definitely a bit more optimized when compared to Blazor (at least it was when we started our project).
3) We are building an internal-facing financial management system. We are heavy handed with our security approach but we have the time and the budget to be. We are in a unique situation where we have a lot of time in which to complete our project, so we can be really careful about building what we need. Also, since our application is internal, we completely bypass common user issues like browser compatibility (everyone uses the same browser) and complicated server infrastructure (we have sub 200 employees). It's a pretty fun project tbh.
Your post seems a bit strange given that Microsoft is the company that let any package owner publish any other NPM package.
Even though Microsoft is ultimately responsible for NPM on the org chart, I still dont mind the entire ordeal from my current perspective. No one ever said we had to use 100% of Microsoft's product offerings. The nuance is in selective adoption and careful negotiation of roadmaps.
I will signal my displeasure with Microsoft's acquisition of the NPM ecosystem by simply disregarding it's existence and never electing the node workload at VS install time. That's all it really takes to entirely opt-out for us. I don't hold any principled grudges against an organization larger than most municipalities. There are a lot of stakeholders involved here.
You've also become 100% dependent on a sole source.
> Microsoft has, can, and will drop the ball, but they also have a very long track record available to build [dis]trust upon.
This.
We’ve had far more security issues with the .net toolset than we have had with Python which is far more open. Most of them have been developer mistakes, because the update process for .Net is far less intuitive than it is for Python. So my developers haven’t always been on point with updates, getting caught in the act when our network team closed old TLS versions or similar.
But the biggest issues have been with libraries abandoned by Microsoft. Like when they wanted to move the world into Azure runbooks and this no longer needed their library for Windows Server Orchestrtion runbooks. Or the half finished libraries like everything involving on prem AD.
By comparison we’ve had absolutely no issues with Python. So I think this is more of a NPM issue than anything.
Being able to directly inject C# services into the razor components is one of the most productive transitions we experienced. All of our JSON APIs got sent to the trashcan and we now have way more time to focus on more important stuff. Also, little things like subscribing to CLR events from components really make you feel empowered to move mountains. Some of our Blazor dashboards have absolutely incredible UX and it took almost nothing to make it happen because of how close you can get the backend to the HTML. You definitely have to change how you think about certain problems, but once you find a few patterns for handling edge cases (e.g. large file download/upload), you are set forever.
Our custom blazor javascript interop source file is still under 200 lines of code. Every other bit of js is provided by the framework. I would say we certainly got the benefit we were going for wrt minimzing javascript source in the codebase.
When I was reading this, I thought the time frame would likely have been on a time scale of hours (or even minutes),
> exposed between October 21 13:12:10Z UTC and October 29 15:51:00Z UTC
But it's actually more than one week. Do we consider one week as "brief"?
I'm guilty of this: my latest Nuxt project has 47,000 dependencies. yarn audit helps, but can i even trust that since it is retroactive?
Otherwise I can't fathom how it's possible for a project to have 47000 dependencies. I mean, my main Linux machine has all kinds of old garbage installed and still the package manager only lists 2000 packages.
I haven't touched JavaScript since the late 90s, so I dunno what the hell's going on there, but in my C++ projects I typically have 10-20 dependencies (counting modularized Boost as one). They're either built by a custom script which includes the SHA256 of the tarballs it expects, or by a particular pinned commit of vcpkg which likewise uses SHA512 to verify its downloads.
I generally only update these when I need a new feature or bug fix, which means I'm unlikely to get bitten by any temporary security compromise.
If the "particular checkout of vcpkg" type of approach is impossible with other package managers, that's unfortunate.
Well you're in for a surprise: the entire web is built on JavaScript for one thing. And that is build on frameworks which are built on ... other frameworks, which are built on a ginormous repository typically accessed by npm/yarn.
npm modules aren't the same as boost. Boost is written and scrutinized by some of the best C++ minds on the planet.
npm modules are written by anyone. they are all open source, but so many are in use that i doubt they get the scrutiny they deserve. at one point there was a package just to left-align things and a bug in it broke thousands of services.
but that's the landscape the modern web is built on, for better or for worse.
Can I come live with you? It's sad that I'm only half joking.
Still some people argue if this deserves its own CVE.
Though this does give them a shortcut.No need to bribe some aging, disenchanted nerd to sell their soul when you can just impersonate them.
Don't get me wrong, everyone has security flaws and zero days, but I feel like npm has been mismanaged since its inception.
I'm glad I'm out of the web dev game, I would dread having to rely on this walking security disaster.
Phishing, bad 2FA, and vulnerabilities of the central repo upload path itself all go away with this simple tactic used by all sane package managers.
Someone PRed this exact same effective strategy to NPM in 2013, and it was refused even as -optional-.
https://github.com/npm/npm/pull/4016#issuecomment-76316744
NPM team members have ignorantly maintained that hashing packages is good enough. They insist on being a central authority for all packages with no method to strongly authenticate authors and this negligence has repeatedly endangered millions.
Meanwhile Debian and other community Linux distros maintain, sign, and distribute hundreds of popular NodeJS packages themselves now because they realize it would be negligent to risk having NPM in their supply chain.
You then have to manually add the public key for a given package to your package.json so it can verify a tarball came from the author/source you expect.
This won't solve problems where the author is malicious, but it helps other cases.
I'm sorry the NPM ecosystem doesn't do this already? Good god!
If I had to guess, the registry operator probably either sees this as friction to onboarding, or if they do support signatures, they'd probably rather sign it themselves.
These are both stupid. The author should be responsible for signing, the registry should never see the key, and the registry should require 2FA to log in and set the public key for a package for users to discover.
Just over a year.
The preceding sentence says they have no idea if it was exploited before the start of their logfiles:
"This vulnerability existed in the npm registry beyond the timeframe for which we have telemetry to determine whether it has ever been exploited maliciously."
So packages uploaded after September 2020 are probably fine.
Before that: ¯\_(ツ)_/¯
If NPM/Github were being responsible here, they would make package owners re-upload clean copies of anything which hasn't been touched since before the start of their audit logs.
I’m surprised more isn’t being said about this part. Any stale dependency is now untrustworthy and they all need a version bump to prove provenance. This is potentially something GitHub could protect against server-side for everybody or build into NPM. They know if a version was published before this date and can stop people from using them.
Unfortunately, the number of weekly downloads wouldn't give much indication of how many people were affected, since some of the downloads will be by bots or eager CI systems, and some organisations cache packages locally after the first download.
An attacker would have to get very lucky, exploiting this bug just up until the point when the logs started (which they had no way to predict), and to target only packages which have either never been updated since, or which were followed by a minor/major package update (not a patch).
The attacker might be monitoring their logs, selectively silencing version clashes. Heck, it's even possible they now have backdoor access to do whatever they want to any package.
I know it's cynical thinking, but this vulnerability was unbelievable and the way they're handling is definitely not reassuring, from my personal standpoint.
Also no distracting internet or Google and you had only the man pages to work off.
I really don’t like the culture of ”download any old shit off the internet, ram it in a container and throw it into production”. It keeps me awake. One day the whole thing will come crashing down and instantly spawn a costly magic enterprise solution which will cost a fortune just to mitigate that risk which doesn’t actually mitigate it all just allow the box to be ticked on a compliance form.
1. npm doesn't record the repo, branch, or commit so it doesn't know what to compare with.
2. Published content is usually a transformation of the repo content -compiled, minified, bundled. You would have to run the same transformation on the repo source and it would have to be a deterministic build.
npm could require that popular packages are published via GitHub actions, then it could strongly associate the published version with a source commit and the build that produced the artifact.
This has some downsides like tie in to the GitHub ecosystem. Maybe that could be offset with sponsored builds?
Certainly not a complete solution but a good first step.
There was an earlier project called "Trust But Verify"[1] which tried to detect discrepancies between published NPM packages and the corresponding (inferred) tag/commit in the source repository, but sadly it doesn't seem to have gained traction.
Interestingly, the "Gold" standard of the Core Infrastructure Initiative (CII) Best Practices guide[2] is to have a reproducible build, but it is only "SUGGESTED that projects identify each release within their version control system", so presumably packages are free to indicate which commit they are built from in an ad hoc out-of-band way, which may not be amenable to automated third-party checking.
[0] https://people.cs.vt.edu/nm8247/publications/icsme-camera-re...
[1] https://hackernoon.com/what-if-we-could-verify-npm-packages-...
[2] https://bestpractices.coreinfrastructure.org/en/criteria
GitHub really comes across looking like total garbage here with this blog post. Security issues shouldn’t be hidden like this. This is dishonest and irresponsible.
Unfortunately that includes the people who think their NIH wheel will be much better than the existing one. In fact, the Dunning-Kruger effect would suggest that people who don't know what they're doing are disproportionately likely to be in the latter group.
I have a similar story . At my old job, we had a web socket gateway that authenticated using JWTs , then hit an internal service to request REST resources. The issue was that it didn’t actually validate the requested REST resource URL; a malicious user could authenticate as themselves but request a resource for any other account.
I found it as I was getting up to speed on the code base, having recently switched teams. Funnily enough, nobody on the team really understood the vulnerability - the EM marked it low priority and wanted the team to work on other things. I had to essentially go directly to the security team and convince them it was a sev 1. I sometimes wonder if it’s easier to just report security issues as an outsider through the bug bounty program; internal reports don’t seem to get taken as seriously.
Looking at a Rails project I've got open, it has ~100 gems in the Gemfile, and 200 gem dependencies overall.
Compare that to one of the Typescript + React projects I work on, which has ~200 dependencies in package.json and 2300 packages in node_modules.
If you picked Node, common best practices need to be followed for production:
1) Thoroughly vet dependencies you bring in. Pin to exact patch versions in package.json. npm-shrinkwrap.
2) Add code in tree when possible (prefer StackOverflow snippets over npm).
3) Prefer light modules with fewer features. Always check their dependencies.
There will still be some vulnerabilities from time to time. But if you've been somewhat careful, most of them tend to happen among devDependencies, which is usually safe. To go further, cut out devDependencies too; for example use a shell script along with esbuild instead of bringing in a heavy-duty bundler.
Would 2FA have prevented that? If not then them loudly promoting 2FA before even mentioning this issue seems odd.
Maybe at some point, only large enterprise can afford to do proper development.
Before we start gatekeeping Free Software development with a "trusted developer" system, we need to make sure that this system supports pseudonymous identities, so that people don't have to dox themselves (even to their own government) to be able to make contributions.
content: The names of private packages were accidentally exposed for a little over a week. The flaw has been found and fixed.
> We determined that this vulnerability was due to inconsistent authorization checks and validation of data across several microservices that handle requests to the npm registry. In this architecture, the authorization service was properly validating user authorization to packages based on data passed in request URL paths. However, the service that performs underlying updates to the registry data determined which package to publish based on the contents of the uploaded package file.
The main article title is such corpspeak that it would go against the site guidelines to use it—that sort of corporate press release title is typically misleading, linkbait, or both.
https://hn.algolia.com/?dateRange=all&page=0&prefix=true&sor...
This is not “security issues”.
It was possible, for years, for anyone to upload anything for any package.
For a package manager, this is THE security issue, all caps.
Commitment to security = security was broken. It's similar to "we value your privacy" and or "announcements about the future of the project". Finest newspeak.
Can you elaborate on what Deno does that makes it more secure than NPM here? I'm guessing it doesn't rely on a centralised repo of any kind?
Some people say it's insecure because, well, if you get your modules from a compromised site it is.
However recent events have shown there's also plenty of danger with centralized repos as well.
The advantage to Deno's approach is it encourages using CDNs, which allow that code to load quicker especially if you're using edge functions or something like CloudFlare workers. It also requires you to be super explicit about where the code's coming from. The negative is that many people will download code from dodgy websites then complain later.
2. The Deno runtime runs with limited permissions by default, so you have to allow access to file system locations or network hosts explicitly
Now, the repository part is arguably not as big of an improvement (if at all). There’s a central repository for third party modules. One nice aspect is it just mirrors code, so you can see what you’re getting before downloading (and, in NPM’s case, running install scripts, if you forgot —-ignore-scripts).
Deno also suggests using CDNs, but they often just host NPM modules that have been transformed into ES modules. That seems worse than NPM, in my opinion.
They did.
I have high hopes for Deno.