I'm trying to figure out if all you need to "opt-out" of 99% of NPM supply chain attacks is to use
npm ci, not npm install, see #1213332. npm ci will never automatically update a package without your consent.However, I'm struggling to find sources for this. If that's actually the case, shouldn't it be all over the place as a reply? Not even this link from a security company mentions the importance of
npm ci (next to a lot of other very interesting attack vectors though).I have only found this comment on HN with the same confusion:
I'm a little confused on one of the excerpts from your article.Our package-lock.json specified the stable version 1.3.2 or newer, so it installed the latest version 1.3.3As far as I've always understood, the lockfile always specifies one single, locked version for each dependency, and even provides the URL to the tarball of that version. You can define "x version or newer" in the package.json file, but if it updates to a new patch version it's updating the lockfile with it. The npm docs suggest this is the case as well: https://arc.net/l/quote/cdigautxAnd with that, packages usually shouldn't be getting updated in your CI pipeline.Am I mistaken on how npm(/yarn/pnpm) lockfiles work?
The replies seem to agree with me: use
npm ci.So I think people just don't know about this?
However, to be honest, I knew about this but we were still using
npm install ourselves 😬
npm installauto-updates deps ifpackage-lock.jsonis complete. If you're usingpackage-lock.jsonand it's complete, neither should update deps.npm ciis just stricter afaict and ifpackage-lock.jsonis missing stuff it aborts.installand your lock file changes, you have a problem.npm installdid modify package-lock.json in the past for me.npm installand downloaded the malicious version were using an incomplete lock file?git checkout package-lock.json) and then wonders whynpm installchanges it again or ...?npm installchanges package-lock.json. I don't see it mentioning what happens if the lock file is incomplete.