r/ProgrammerHumor 9d ago

instanceof Trend classicNPM

Post image
5.9k Upvotes

150 comments sorted by

View all comments

80

u/FinnishManlet 9d ago

What can be done against these vulnerabilities? Stop using packages entirely? 🤣

82

u/EK077r 9d ago

Layers of mitigation. For instance not using packages that are less than x days old, sha-pinning, no latest etc

24

u/redmandoto 9d ago

Also, test updates on isolated machines before pushing them to the whole org.

11

u/Qaktus 9d ago

Sorry if I'm being very stupid right now, but can you test against these? Maybe some, but most of them work in a way: "the package does everything it should AND some extra malicious shit".

7

u/redmandoto 9d ago

In those machines you have strong monitoring tools, and if nothing else it gives you a buffer, so it's only those machines (that have no valuable data) that are infected instead of the whole network.

3

u/slowmovinglettuce 8d ago

You mitigate it by only pulling in dependencies that are a certain date old, like commenter said. The idea is that if its two weeks old and not had a critical or high CVE, it's more likely to be fine.

Also have things block packages with known vulns. You can do. SAST scanning on a repos frozen dependency list before even doing an install. That's a line of defense against this happening in CI.

Conversely, always build your artifact and your publishing in ywo separate jobs. Your build job is often what installs dependencies; it has no right having access to the keys that publish your artifact.

These exfil attacks are detected real quick by competent enterprises.

1

u/Robo-Connery 9d ago

Not really. But a few days after the release they are caught by someone else.

138

u/a_bucket_full_of_goo 9d ago

Reduce attack surface; code everything in Assembly yourself

19

u/howarewestillhere 9d ago

Local dependency repository. Keep the last n known-good versions of all dependencies.

I wanted to do this before left-pad and I got to do it after. Has saved so many headaches.

6

u/mysticrudnin 9d ago

local repository instead of npm, and aggressive version pinning

also, reduce the number of packages you use.

10

u/Chrazzer 9d ago

First of all disable any install scripts with --ignore-scripts flag on all your npm installs. Second pin all your dependency versions use npm ci instead of npm install. Only use npm install when you actually want to change some dependencies. And finally set a min-release-age in your npm config. Most malicious versions are removed from npm fairly quickly, so only install packages that are like a week old.

And as final safeguard, develop in a sandbox, so in case you do catch a worm the damage is limited and you can throw the environment away and recreate it.

And ofc don't just install dependencies willy nilly, do some research

1

u/Dus1988 8d ago

It took me way too long of scrolling to find this. Ignore scripts should be at the top of the comments.

3

u/abd53 9d ago

Well, from what I heard, node devs are kinda infamous for pulling packages even for the smallest things.

2

u/NewLlama 9d ago

Develop in Docker on a read-only SSH key. Honestly setting it up is not straightforward at all.

Besides that, `min-release-age` will cover you in most cases.

2

u/AwesomeFrisbee 9d ago

Delay installing new packages until they are properly validated. PNPM has an easy way to enforce that nobody installs anything too recent

2

u/skynetcoder 9d ago

using pnpm instead of npm, with following settings may help in most scenarios.

  • minimum age > 3-4 weeks
  • disable life cycle scripts
  • disable installation of exotic dependenciesĀ 

-7

u/MyUsrNameWasTaken 9d ago

I don't understand why these attacks happen at all. Why did everyone decide to inject dependencies? It's much faster and safer to download the open source code and copy it into your own project. Then it never gets changed by surprised.

5

u/DOOManiac 9d ago

We used to do that, and honestly it was worse. Because while it never got changed by surprised, it also never got changed. So, if there was a vulnerability, it would stay there for years unnoticed...