JavaScript developers targeted by hundreds of malicious code libraries

Post content hidden for low score. Show…

Marlor_AU

Ars Tribunus Angusticlavius
8,057
Subscriptor
There are plenty of tools out there to protect against installing malicious packages (we use an amphibian-themed product), but it really seems like package managers could assist here by offering some basic functionality out-of-the-box.

If two packages are similarly-named, yet one has hundreds of thousands of installs over several years, and the other is brand-new, then a simple warning when installing is surely feasible. The logic for this probably wouldn't be onerous. Many package managers already offer suggestions for similarly-named packages when they don't find a match, and this could surely be leveraged to find possible typo-squatted package names.
 
Upvote
95 (100 / -5)
I've several times wondered if it wouldn't be a good idea to set far more restrictive rules on package naming in these repos. One could e.g. calculate a Levenshtein distance between the package one is attempting to upload and existing ones and if the distance is too close, refuse to allow that name -- there may be even better algorithms than that for calculating similarity and one could use a couple of different ones together, but I have only used Levenshtein in my own stuff.

Yes, this would mean devs would have to spend a few seconds more on coming up with names for their stuff and it'd probably also eventually lead to a tad longer package names, but it'd make it hard to perform these kinds of supply chain attacks and as such, I feel the tradeoff would be worth it.
 
Upvote
88 (92 / -4)
A supply chain attack is only as useful as the idiot that accepts everything.
You mean “every eager developer beaver who has mastered cut-and-paste from Stack and believes that now unlocks car, house, influence” and knows how to play on weak management or clients that they’re uncool if they don’t get the “business value” they “provide.”

< air quote muscle-sprain >

Same devs running their npm scripts ON bare metal production server hardware and move on before anyone notices how immediately-fire-able that should be.
 
Upvote
6 (15 / -9)

johnny.5

Ars Scholae Palatinae
733
Typo-squatting? UTF-8 invisible characters? Cyrillic anything?

It's time package maintainers explicitly allowed imports and that which they don't allow doesn't get imported. Period. A supply chain attack is only as useful as the idiot that accepts everything.
While I agree with the sentiment, I have to ask- have you looked at how many packages a typical JS application using NPM likely has installed? This is like saying all dependencies should be audited. That makes sense and sounds perfectly reasonable, until you factor in transient dependencies in these kinds of projects and it quickly becomes unreasonable in the sense that you will be forever delayed in even pushing out critical updates for first party dependencies you actually reference directly in your application. I would argue it's even impossible to maintain a project using NPM over a long period of time without some kind automation to keep up with these issues for you, which plenty of developers just won't have easy access to. The node ecosystem (at least, perhaps others) is simply a huge mess in this regard.
 
Upvote
53 (56 / -3)
Post content hidden for low score. Show…

jazzylarry

Ars Tribunus Angusticlavius
6,721
This is one reason why I'm wary of automated build systems that pull in 500 packages from a remote repository that I don't control.

Give me locally hosted libraries and (shakes cane, yells at cloud) get off my lawn!
always always always use your own vetted repo, or at least pull from a managed local repo, so that you don't get every version under the sun within your builds.
 
Upvote
19 (21 / -2)

DaveSimmons

Ars Legatus Legionis
11,176
Subscriptor
always always always use your own vetted repo, or at least pull from a managed local repo, so that you don't get every version under the sun within your builds.
That also saves you from Left-Pad incidents - https://en.wikipedia.org/wiki/Npm_left-pad_incident

If it's your company's repo with backups and good management of updates you don't have key libraries disappear, unexpected version mismatches, or end up accidentally using a typosquatted library.
 
Upvote
32 (34 / -2)

Faanchou

Ars Tribunus Angusticlavius
9,227
This is one reason why I'm wary of automated build systems that pull in 500 packages from a remote repository that I don't control.

Give me locally hosted libraries and (shakes cane, yells at cloud) get off my lawn!
Locally hosted, version pinned dependencies FTW.
 
Upvote
35 (37 / -2)

Faanchou

Ars Tribunus Angusticlavius
9,227
So I guess these repos need active vetting processes. Which won't be free to setup.
Considering that the attack vector involves bypassing the repos entirely, I don't see that being a salient point here. How do you handle people misspelling your name and getting your opinions from -prete-?
 
Upvote
4 (7 / -3)

Marlor_AU

Ars Tribunus Angusticlavius
8,057
Subscriptor
Locally hosted, version pinned dependencies FTW.
This can go too far, though. I did some work for a large company that had a strict policy that all packages and updates needed to go through a manual cyber-security and legal review before they could be added to the local repository. When dealing with packages and their dependencies (and dependencies of dependencies) this became a real headache.

Getting a package and all its dependencies approved could take months, and once a package was in the local repository, it was essentially considered "blessed" for all users worldwide, and the approval was never revisited.

This ultimately meant that developers never wanted to update to new versions. A simple package upgrade was a giant hassle, involving forms and reviews, and developers just wanted to get their job done. Over time, the local repositories fell further and further behind the master repositories. New packages often wouldn't work because the versions of their dependencies in the local repository were too old, and upgrading the dependencies would break some other outdated package. To resolve this, repositories ended up splintering per-project, and nobody knew what versions were actually being used across the business.

Even worse, the "once blessed, always blessed" philosophy meant that many of the package versions in the local repository had critical vulnerabilities that everybody conveniently ignored. The package had been vulnerability-free at the time of approval, so it was fine. Any vulnerabilities found after that review may as well not exist.

The company touted all this as evidence of its bullet-proof cyber-security posture, and boasted about its rigorous processes to stakeholders... all while forcing developers to use four year old packages with multiple vulnerabilities with a CVE score >7. But they'd been reviewed years ago, and found to be fine, so it's all good.

The company I now work for has a tool to deal with all this. It scans incoming packages on-demand, maintains the local repository, flags new vulnerabilities, catches typo-squatted packages... and isn't cheap. But it actually works. In fact, it kind of feels like cheating after dealing with the previous approach.
 
Last edited:
Upvote
78 (79 / -1)
It is basic hygiene to double-check packages on npmjs, and even copy-paste names instead of writting by hand. But we have no control over the sub-dependencies: that's the real worry.
We could even imaging attack implying changing package.json file of popular packages, adding a typo (or using one of these fancy UTF8 characters)
 
Upvote
17 (17 / 0)
Post content hidden for low score. Show…

Marlor_AU

Ars Tribunus Angusticlavius
8,057
Subscriptor
If a package included in the dependencies has a security update, you do "go through a manual cyber-security and legal review" required for it to meet the new, fixed position and then research all the changes needed for things depending on it needed to support the change. That's the baseline, not the end goal.

I have no idea what the rest of your message was supposed to be about given that. Are you running your codebase from github?

This was a very large enterprise, with hundreds of developers and dozens of disparate projects. All packages installed on the corporate network needed to go through review before they hit the network, and then they were available to all projects. There were many thousands of "approved" packages in the corporate repository, and for any updates to occur to those, it required developers to request that cyber do that review again (typically taking weeks or months).

So developers just never requested updates. It was too much hassle. They would just choose from what was approved and available, and if the package was five years old and still worked, that would do. Meanwhile, the cyber-security department never initiated these reviews themselves. So the repository just went stale, and any vulnerabilities discovered post-review were ignored.

An automated tool that manages the repository (as my current employer uses) doesn't suffer these issues. Packages are flagged the moment a new vulnerability is discovered, and new packages can be live-scanned at the time the developer requests them to ensure they aren't vulnerable and meet policy constraints.
 
Last edited:
Upvote
42 (43 / -1)

Starouscz

Ars Scholae Palatinae
946
Subscriptor
There are plenty of tools out there to protect against installing malicious packages (we use an amphibian-themed product), but it really seems like package managers could assist here by offering some basic functionality out-of-the-box.

If two packages are similarly-named, yet one has hundreds of thousands of installs over several years, and the other is brand-new, then a simple warning when installing is surely feasible. The logic for this probably wouldn't be onerous. Many package managers already offer suggestions for similarly-named packages when they don't find a match, and this could surely be leveraged to find possible typo-squatted package names.
Thats why any serious company should use repository proxy that has that functionality and setup sources of packages that ideally verify identity or require package authors to use mfa or other precautions. If something hits the fan it also gives you option to see where was the impact, since you store a docker images inside too.
 
Upvote
1 (2 / -1)

Emmanuel Deloget

Wise, Aged Ars Veteran
151
Subscriptor
While I agree with the sentiment, I have to ask- have you looked at how many packages a typical JS application using NPM likely has installed? This is like saying all dependencies should be audited. That makes sense and sounds perfectly reasonable, until you factor in transient dependencies in these kinds of projects and it quickly becomes unreasonable in the sense that you will be forever delayed in even pushing out critical updates for first party dependencies you actually reference directly in your application. I would argue it's even impossible to maintain a project using NPM over a long period of time without some kind automation to keep up with these issues for you, which plenty of developers just won't have easy access to. The node ecosystem (at least, perhaps others) is simply a huge mess in this regard.
I can only concur. For years we relied on a build system where nothing had to be downloaded from the intarweb during build, allowing us to set up a set of nodes deep within our infrastructure that was able to build 100+ different projects for multiple OS arch.

And then, we had to build this project using React. Now, I'm scared.
 
Upvote
14 (15 / -1)

bjn

Ars Praefectus
5,634
Subscriptor++
While I agree with the sentiment, I have to ask- have you looked at how many packages a typical JS application using NPM likely has installed? This is like saying all dependencies should be audited. That makes sense and sounds perfectly reasonable, until you factor in transient dependencies in these kinds of projects and it quickly becomes unreasonable in the sense that you will be forever delayed in even pushing out critical updates for first party dependencies you actually reference directly in your application. I would argue it's even impossible to maintain a project using NPM over a long period of time without some kind automation to keep up with these issues for you, which plenty of developers just won't have easy access to. The node ecosystem (at least, perhaps others) is simply a huge mess in this regard.
All dependencies should be audited. That the JS ecosystem has grown into a thing that makes this impossible is pretty damning. Including transient dependencies, the last major project I worked on had C++ with about 10 dependencies (manageable); python with about 100 dependencies (yuk); and JS/TS with multiple thousands (insane).
 
Upvote
40 (41 / -1)

passivesmoking

Ars Tribunus Angusticlavius
8,633
People keep banging on about "PHP is insecure!" but from where I'm sitting it sure looks a hell of a lot like Node and NPM is a far bigger problem than (especially) modern PHP.

At least PHP's preferred package manager namespaces package by developer, making attacks like this far more difficult.

Admittedly I might be biased because I absolutely loathe working on Javascript and Javascript-adjacent systems, and yes, I know a language is only as good as the developers writing code in it, but still.
 
Upvote
12 (18 / -6)

Deadmist

Smack-Fu Master, in training
7
All dependencies should be audited. That the JS ecosystem has grown into a thing that makes this impossible is pretty damning. Including transient dependencies, the last major project I worked on had C++ with about 10 dependencies (manageable); python with about 100 dependencies (yuk); and JS/TS with multiple thousands (insane).
I am wondering what the actual amount of code in those dependencies is.
A lot of npm packages are really small.
 
Upvote
12 (12 / 0)

PhilipStorry

Ars Scholae Palatinae
1,224
Subscriptor++
I'm a big fan of "batteries included". I think it's partly because I grew up with computers in the 1980s - the golden era of machines that had limited facilities, yet provided support for all of them in its standard library. (Even if that standard library was actually just extensions built into its BASIC interpreter.)

When I moved to an IBM PC and tried languages like C, I kind of fell out of love with programming a little. Suddenly doing everything you wanted to required so much more effort.

After a while there was then a move towards batteries included with languages/platforms like Python, Java and .NET. Each had a large, well maintained standard library. Suddenly programming felt a bit more like it did when I was a kid - 90% of what I wanted to do was already covered without me needing to jump through extra hoops.

Now to be clear I'm not saying that the late 80s and early 90s were somehow filled with inadequate languages. It's more that hardware and operating environments were dramatically outpacing what programming languages were giving us, unless you were willing to spend significant coin.

All this is to say that I do think a decent standard library is a virtue. And one that we should cherish and strive for.

I've never considered using node.js, but the left-pad incident was a major warning sign to me. The idea that basic features were being left out for others to fill the gaps just doesn't feel right, and these kinds of supply chain attacks are a big part of that unease.

The less we have to add in later and check, the better. And the checks we do can be better, as we're not overwhelmed by additional packages. But worse, if even the simple stuff requires additional packages, then people become blasé about them and that increases their likelihood of being successfully attacked.

Batteries included. You know it makes sense.
 
Upvote
22 (24 / -2)

Jeff S

Ars Legatus Legionis
11,961
Subscriptor++
I'm a big fan of "batteries included". I think it's partly because I grew up with computers in the 1980s - the golden era of machines that had limited facilities, yet provided support for all of them in its standard library. (Even if that standard library was actually just extensions built into its BASIC interpreter.)

When I moved to an IBM PC and tried languages like C, I kind of fell out of love with programming a little. Suddenly doing everything you wanted to required so much more effort.

After a while there was then a move towards batteries included with languages/platforms like Python, Java and .NET. Each had a large, well maintained standard library. Suddenly programming felt a bit more like it did when I was a kid - 90% of what I wanted to do was already covered without me needing to jump through extra hoops.

Now to be clear I'm not saying that the late 80s and early 90s were somehow filled with inadequate languages. It's more that hardware and operating environments were dramatically outpacing what programming languages were giving us, unless you were willing to spend significant coin.

All this is to say that I do think a decent standard library is a virtue. And one that we should cherish and strive for.

I've never considered using node.js, but the left-pad incident was a major warning sign to me. The idea that basic features were being left out for others to fill the gaps just doesn't feel right, and these kinds of supply chain attacks are a big part of that unease.

The less we have to add in later and check, the better. And the checks we do can be better, as we're not overwhelmed by additional packages. But worse, if even the simple stuff requires additional packages, then people become blasé about them and that increases their likelihood of being successfully attacked.

Batteries included. You know it makes sense.
The problems with "batteries" included is one, you can never include everything - people are always coming up with new things - new batteries if you will. Two, you then add significant bloat to programs for all the 'batteries' they don't use.

Java struggled with this - historically you need a full, hundreds of megabytes JRE even for the simplest of programs to run - although, more recently, they are making Java more modular - so you can download the core JVM and then add which modules you actually want to use.

Then the other problem is, sometimes the implementations included in a language leave something to be desired. For example, Java has long included implementations of XML parsers for various APIs, but some of the early Java parser implementations built into Java weren't very fast/optimized, so you started getting other implementations competing with the Java XML implementations. Also, then people created new APIs - new approaches to how to interact with XML data (e.g. early on you had SAX or DOM, then people wanted easier ways to work with XML than SAX, but that didn't required the entire document to be parsed into memory at once like DOM does, so they created STAX and Trax, new schema languages for validation (originally we had DTDs, then XSDs, then Schematron and Relax NG (not sure the order those arrived)), etc.

And XML is an example where a lot of apps have no need for XML functionality at all. So, why bloat up the runtime with XML functionality that's not being used by your app?

It's really impossible for any language to be all things to all people.

Better to have a clean core, and to add to it good libraries that implement what you need.

Just make sure you are adding the correct library and not a typo-squatter.
 
Last edited:
Upvote
3 (16 / -13)

Starouscz

Ars Scholae Palatinae
946
Subscriptor
Has the Apache Maven repos ever suffered a supply chain attack like this? Seems to me that maven automatic dependency downloading is pretty similar in concept to NPM, and yet, I don't think I've ever heard of an attack like this? Entirely possible I just missed it
There is a lot more security control and institutional knowledge. It helps that for maven you can control the ownership by package prefixes - nobody can just release package in prefix like org.apache and large package repositories like sonatype mandated things like MFA for developers and TLS for users long time ago. There are good design decisions like when you release a a package with version you cannot change it afterwards. There were some attacks but I believe the overal architekture is more robust.
 
Upvote
17 (18 / -1)
I am wondering what the actual amount of code in those dependencies is.
A lot of npm packages are really small.
Micro-libraries are all the rage with frontend devs these days.

I mean, why write your own left or right trim function? There’s one right there in npm, surely it’s better tested than anything a dev can do themselves, and look, it only has 15 transitives, perfect!!!
 
Upvote
18 (21 / -3)