In a modern JavaScript project, the code you wrote is a small slice of what runs. The rest is hundreds or thousands of packages in node_modules, each written by someone else. A supply chain attack abuses that trust: the attacker compromises a package you depend on, and the malicious code arrives with your next npm install.
Where the chain gets attacked
The most damaging route is hijacking a popular package. The attacker takes over a maintainer's npm account through phishing or a leaked password and publishes a malicious version, which flows into thousands of projects via ranges like ^4.1.0. In 2025 the maintainer of widely used packages such as chalk and debug fell for a phishing email and malicious versions were published; earlier incidents involved event-stream and ua-parser-js. Other routes are typosquatting, where a look-alike name catches a typo, and dependency confusion, where a public package shadows a company's internal one.
When malicious code runs
Install time is the dangerous moment. Packages can declare preinstall, install and postinstall scripts that run automatically on a developer laptop or CI server and can steal environment variables, .npmrc tokens, SSH and cloud keys. Other payloads hide in frontend bundles and run in every visitor's browser, for example swapping crypto wallet addresses or skimming payment forms.
Lock files and npm ci
Commit package-lock.json and use npm ci on servers and CI. It installs exactly what the lock file says and fails if it disagrees with package.json, so a version published today cannot reach you until you deliberately update.
npm ci
npm ci --ignore-scripts
echo "ignore-scripts=true" >> .npmrc
npm audit
npm audit signatures
Note that ignore-scripts can break packages that compile native code. If a native module needs its build script, run npm rebuild package-name for that one package instead of re-enabling scripts everywhere.
Vet new dependencies
npm view package-name
npm view package-name time --json
npm view package-name scripts
npm ls --all | less
Every new dependency imports someone else's code, so a few minutes of checking is worth it. Copy package names from official docs, check who maintains a package and how old it is, and prefer a few lines of your own code over a large dependency tree for a tiny task. Waiting a little before adopting brand-new versions helps too, since malicious releases are usually detected and pulled within hours or days; some package managers offer a setting for this, so check your tool's documentation.
A realistic scenario
A Tashkent delivery company built its customer panel in React and deployed it through CI that ran npm install without a committed lock file. One day a transitive dependency resolved to a freshly hijacked version whose postinstall script sent the CI environment, including the server SSH key and an SMS service token, to a remote host. The team rotated every key, committed the lock file, switched to npm ci --ignore-scripts and limited the deploy key to one folder on one server. They also changed the pipeline so that secrets are exposed only to the deployment step, not to the dependency installation step, which means a future malicious install script would find far less to steal.
If you publish packages
npm profile enable-2fa auth-and-writes
npm token list
If you maintain packages yourself, you are a link in someone else's chain. Require two-factor authentication for publishing, not just for login, keep tokens minimal and never commit them. You cannot remove supply chain risk entirely, but these habits shrink it considerably wherever your app runs, whether on a sayt.uz VPS or elsewhere.