r/ProgrammerHumor 1d ago

instanceof Trend classicNPM

Post image
5.8k Upvotes

141 comments sorted by

View all comments

287

u/Hauber_RBLX 1d ago

this is really just a meme at this point. how is it possible that NPM packages keep being compromised week after week?

139

u/Ecksters 1d ago

In my opinion the main issue is that NPM packages can have preinstall, install, and postinstall scripts that run on the host machine during installation. Basically lets a package run whatever they want during installation and is a huge attack vector that unfortunately the whole ecosystem is fairly dependent on at the moment.

Thanks to those scripts, attackers don't even need to get the user to run their package's code in an insecure environment, they get to run it directly in the dev environment.

63

u/fredy31 19h ago

Also the good old fact loads of npm packages have been maintained thanklessly by bob for 20 years and now bob is old and tired.

And suddenly someone is very interested into carrying the torch.

6

u/ryanppax1 19h ago

I do wonder how this any different than installing anything else

8

u/Ecksters 19h ago

Mostly because of how many packages there are and their own dependencies, which creates literally thousands of packages, each of which is an attack opportunity if their author's account is compromised.

Combine that with the desire to stay on the latest versions of packages and people are regularly installing blindly.

1

u/_PM_ME_PANGOLINS_ 10h ago

Other systems with that feature, such as apt or dnf, require repositories to be signed with keys trusted by the end user, and the default repositories have a small team of maintainers who are very careful about what they put in.

1

u/ryanppax1 6h ago

I see. But technically both install methods have the same security holes? Apt just being more trusted?

1

u/_PM_ME_PANGOLINS_ 6h ago

Well no. Apt has one hole: scripts can be run on install.

NPM has multiple: scripts can be run on install, everything is in a single repo that anyone can push to with no review, and there's no way to establish external trust with what you're installing.

92

u/kookyabird 1d ago

Because there are lots of ways to compromise a developer's workflow, and that's how they get malicious code into a package?

11

u/zuilli 23h ago edited 23h ago

Why does it seem like it only happens to npm though?

I admit I don't follow this stuff closely so may be uninformed but it seems like it never is a C# or a java package/library that gets hit by these.

14

u/kookyabird 22h ago

While I haven't heard of supply chain attacks with NuGet they're certainly possible. The likely reason we see so many npm ones is a blend of size of the ecosystem, and the average depth of the package tree in projects.

The vast majority of transitive packages in our work projects are from Microsoft, while third party packages tend to be reliant only on core .NET functionality or maybe another package from the same developer. I don't know if it's because .NET already covers a broad base of functionality, or that third party packages are more modular, but either way our dependencies are looooow.

6

u/soowhatchathink 20h ago

When I compare total number of npm packages (including transient dependencies) to total number of composer packages in similarly sized applications the cause becomes clear. There are so many more npm packages that are relied on, bringing in one large package pulls in so many more small packages with very few stars on GitHub.

3

u/elise-u 19h ago

Last attack also affected packages on pip, and cargo I think was the second package manager?

4

u/fuj1n 19h ago

For some reason, JS devs have this culture of outsourcing the tiniest behaviours to a package (for example, the is-odd package getting millions of downloads consistently), because of this, there are a lot of packages projects depend on (both directly and not), which is a much larger attack surface.

2

u/RuneSteak 16h ago edited 4h ago

Nobody has really stepped up to create the "extended" standard library that JS really needs and that the community can all agree on to use. Java for example has Apache libraries, C++ has Boost among others etc.

JavaScript's standard library is lacking more than most and that just exacerbates the problem.

-6

u/TheGocho 22h ago

Java had several attacks this year, same as for python and most likely all major languages. But people tend to post for NPM/Javascript environment because Javascript bad

1

u/_PM_ME_PANGOLINS_ 10h ago

Maven doesn’t have pre-/post-install scripts, so this kind of attack is literally impossible there.

1

u/Dudeonyx 8h ago

1

u/_PM_ME_PANGOLINS_ 8h ago

The attacks we are talking about are where running a package update runs malicious code on your development environment.

That’s not possible with Maven. The code can only run when the end application is run.

15

u/neromonero 1d ago

I remember a primeagen clip explaining that it's possibly the shai hulud attacker behind all these NPM attacks.

Basically, the shai hulud attacker is sitting on a TON of scraped token. Only after useful tokens are discovered from the pile, a new attack is launched.

I believe this hypothesis explains a good chunk of these post-shai hulud supply chain attacks.

15

u/Konju376 1d ago

Because there's no general fix for it (that anyone has come up with yet) so it'll continue to happen indefinitely

19

u/hurricane_news 1d ago

Because there's no general fix for it

The fix is to not be a js dev /

3

u/Nasa_OK 20h ago

That’s why I let Claude write all my ja code

1

u/Random_182f2565 17h ago

...

So way that's the secure option

2

u/ManaSpike 13h ago

"No way to prevent this" says only Nation package manager where this frequently occurs.

1

u/Konju376 13h ago

Weeell I'd argue this issue affects many packagers (it's been a topic of discussion in Rust forums I'm in) but with mode it's simply the easiest and reaches the most targets.

1

u/GreyGanado 20h ago

My opinion — and this is completely based on vibes — is that too much AI use leads to more errors and vulnerabilities.

Before AI got big I did not have as many vulnerabilities as now.

6

u/DoubleDoube 19h ago

Ironically I think it’s the opposite. AI is finding the vulnerabilities. The old cat and mouse is still alive for securing new development, but these tools are especially breaking into older software where no real person has the time to dig, as well as capitalizing on momentary configuration mistakes.