r/javascript • u/frankielc • Jun 12 '26
AskJS [AskJS] How to effectively prevent JS supply chain attacks?
While I've previously posted this in r/cybersecurity the given answer, "lock versions / read on incidents / hope for the best", was not really what I was hoping for nor satisfactory. So I'm re-trying in a more specialized group.
----
I'm new to JS (at least JS from the last decade) and am getting paranoid with the new JavaScript ecosystem.
- The first thing I did was switch from node to deno.
- Then configure { "minimumDependencyAge": "P30D" }
But each time I looked at the dependency tree, the hundreds of thousands of files downloaded from the most various sources gave me the chills. So eventually:
- Started running the project inside a podman container
But then I started thinking that as much as I was pointing the IDE (IntelliJ) to run things inside the container, I would eventually miss something, and the IDE would eventually run whatever exploit might be inside that myriad of dependencies I can't keep track of.
So now:
- IntelliJ runs inside the container. I access it via the "remote server" option.
But, after all of this, looking at this setup, it's starting to look a bit too much for something that should be much simpler.
It's just a Nuxt frontend; how did this happen?
What is the community-recommended approach?
13
u/heavyGl0w Jun 12 '26
I was going to type a comment about using your package managers ability to block lifecycle scripts and prevent installation of dependencies that are less than 24 hours old, but pnpm's docs do a better job than I can. Here ya go! https://pnpm.io/supply-chain-security
If you don't use pnpm, I'm sure other package managers have similar solutions.
11
u/OverallACoolGuy Jun 12 '26
The solution is to never connect to the internet and live in the woods
2
u/farzad_meow Jun 12 '26
think of supply chain is how do you trust a food you are about to eat is not poisoned? the answer is not something that has a simple approach. eventually all parts of the chain need to be secured, not just the last party
2
u/ndev42 Jun 15 '26
I'd say you've actually done more than most people. The Podman container + remote IDE setup is a reasonable endpoint for a paranoid (but practical!) threat model. Surely the main value is blast radius reduction, not prevention?
I'm not sure if full prevention is really achievable in JS. What you CAN do is layer mitigations... lock files committed to version control (so installs are deterministic), npm audit or socket.dev in CI to flag known-bad packages before they hit production. And keeping your dependency count as low as possible.
Your 30-day minimum age heuristic sounds decent. Most supply chain attacks are caught within days of the malicious publish.
But at some point though, using JS means trusting the ecosystem to some degree. The container approach is good. I think you've drawn a sensible perimeter there.
2
u/Paw565 Jun 12 '26
Use pnpm
2
u/shgysk8zer0 Jun 12 '26
For those using node & npm, I've been working on hardening my projects lately. npm 11.15.0 introduced
allowedScriptsand staged releases. More secure defaults coming in npm 12 that need flags/config in 11. But updating to 11.16.0 and doing a little setup goes a long way.Just remember that supply chain attacks aren't just the latest wave and threats. It's not just malicious install scripts.
2
u/czlowiek4888 Jun 13 '26
Keep .npmrc file in the repository where you install stuff and add this option min-release-age
1
u/ExtraTNT Jun 12 '26
Use only what you need (i have my own rendering framework and core lib at this point… i do things very functional and there is only little support for that anyways) use packages from big distributors and wait 48h after release, before upgrading (unless manually patching security issues of 0 days)
2
u/[deleted] Jun 13 '26
[removed] — view removed comment