Complete analysis of npm supply chain attacks, 5 major defensive countermeasures that developers must learn in 2026

📅 2026-05-18 11:13:43 👤 DouWen Editorial 💬 6 条评论 👁 4

In September 2025, multiple npm header packages such as axios were implanted with malicious scripts, affecting more than 18,000 downstream projects. In January 2026, PyPI also saw forged packages stealing environment variables one after another. Supply chain poisoning has evolved from an isolated incident to a norm. This article sorts out the complete model of npm supply chain attacks and the five major defensive countermeasures that developers must implement in 2026.

References. axios maintainer September 12, 2025 vulnerability disclosure report. Snyk Q1 2026 Open Source Security Report. Socket.dev Supply Chain Trends of the Year 2025. npm official audit tool data. GitHub Advisory Database.

The whole picture of poisoning events from event-stream to axios

Picture

npm package poisoning is not a new phenomenon. The event-stream incident in 2018 alerted the entire industry for the first time. The attacker received the transfer of maintenance rights from the original author and implanted the Bitcoin wallet to steal the code, affecting tens of millions of downloads. In 2021, the coa and rc packages were hijacked and injected into the mining program. In 2022, colors.js and faker.js maintainers actively broke the code, and tens of thousands of project builds failed.

The September 2025 axios incident was of a more serious nature. The attacker defrauded a contributor's npm credentials through a phishing email and inserted code for remotely loading the payload in version 1.7.10. The payload will scan variables containing the words AWS, GitHub, and Stripe in process.env and transmit them out through the dns tunnel. It only took 9 hours from release to discovery, but it has been pulled by automatic CI more than 240,000 times.

Similar events will accelerate at the beginning of 2026. In January, the colors-cli package was hijacked, and in February, a package disguised as requests-async on PyPI implanted a powershell rebound shell. The attack mode has been upgraded from "breaking code" to "silent stealing".

How attack links penetrate your development environment

Picture

Only by understanding the attack links can we provide targeted defense. Attackers usually take 4 steps:

The first step is for the social worker to get a certificate. Common methods are phishing emails pretending to be npm support to allow maintainers to click on fake login pages, or GitHub Issues pretending to be bug reports to induce maintainers to run malicious commands. In the 2025 axios case, the attacker sent an email disguised as an npm security alert, with a link pointing to a cloned login page.

The second step is to release the contaminated version. After attackers obtain the credentials, they usually release a patch version because the patch does not trigger a significant review process. The version number has increased by 0.0.1, with semantic compatibility and a large number of automated CI direct pulls.

The third step is to hide the payload. The payload will not be executed immediately, but will be triggered lazily through postinstall scripts, build hooks, and the first require. Some also detect environmental characteristics, such as only executing on Linux CI and not triggering local macOS development to avoid debugging.

The fourth step is data outgoing. Common channels include DNS tunnel, HTTPS POST to CDN node, Discord webhook, Telegram bot. These channels are hidden in regular network traffic and are difficult to capture by IDS.

First line of defense lock version and lockfile

Picture

Dependency version management is the most basic and effective defense.

The use of ^ and ~ wildcard symbols in package.json is prohibited, use the precise version instead. ^1.2.3 means that it will automatically upgrade to any version 1.x. Once the poisoned patch is released, CI will pull it immediately. If it is locked to 1.2.3, manual confirmation is required before upgrading.

package-lock.json must be submitted to git and npm install --no-package-lock must be disabled. The lockfile records the exact hash of each indirect dependency, and any hash inconsistency will result in an error. The lockfile verification of yarn berry and pnpm is stricter, so it is recommended to switch.

The CI command must be npm ci instead of npm install. The former is installed strictly according to the lockfile, while the latter will be parsed according to the package.json range and may pull a new version.

Upgrading dependencies must have a review process. It is recommended to fix the upgrade cycle every 2 weeks and manually check the changelog and commit history instead of mindless npm update.

Second Line of Defense Package Review Toolchain

Picture

Human review alone is not enough, tools are necessary.

Socket.dev is a supply chain security tool that will emerge in 2025. It provides npm package risk scores and prompts whether high-risk packages have been introduced during the PR stage. The free version supports public warehouses, and the Pro version costs $10 per warehouse per month.

snyk focuses on CVE vulnerability scanning and integrates GitHub Actions. The free tier comes with 200 tests per month, and the commercial version starts at $25 per month per developer.

osv.dev is an open source vulnerability database produced by Google. It is connected to GitHub Dependency Graph and all public repositories are free.

npm audit is a free tool built into npm, but its response is slow. It only covers vulnerabilities recorded in the npm registry, often with a lag of 7 to 14 days.

CycloneDX and SPDX are SBOM software bill of materials standards, and the 2026 EU CRA Act requires commercial software to provide SBOM. This means that SBOM tools go from optional to mandatory.

The third line of defense sandbox construction environment

Picture

The build process must assume that dependencies may be malicious.

CI sandboxing. Don't build containers with wide network access. Only npm registry and necessary CDN are allowed for outbound. All outbound DNS uses DNS over HTTPS and logs are recorded. Any abnormal domain name requests will be alerted immediately.

Environment variable isolation. Sensitive variables such as AWS_SECRET in CI are only injected during the deploy phase and are not exposed during the build phase. The environment function of GitHub Actions can do this layering.

postinstall refused to execute. The --ignore-scripts option disables npm package installation hooks, which are not required for most production builds. If a package must be postinstalled before it can be used, handle it with a separate allowlist in CI.

Build products are reproducible. Reproducible builds mean that the same commit always produces the same binary, and any inconsistency is a taint signal. Nix and Bazel are the mainstream reproducible build tools in 2026.

Fourth line of defense runtime monitoring

Even if it is bypassed at compile time, there is still a final wall at runtime.

eBPF monitors container system calls. Falco is a CNCF project that can observe process behavior at the Linux kernel level. If a node process suddenly executes curl to access the external network or reads /etc/shadow, Falco will alert you immediately.

Outbound firewall rules. The production container only allows necessary domain names to go out. There is no reason for a node process that returns an API to resolve the discord.com domain name. Any unexpected outbound should trigger an alert.

Vouchers are short-term. Both AWS and GCP support short-term tokens, which automatically expire within 30 minutes. Even if it is stolen by a malicious package, it is too late to go sideways. Vault and AWS STS are common scenarios.

Abnormal process monitoring. eBPF can observe whether any child processes are forked. For example, if a Node server suddenly forks bash or python, this is an abnormal signal.

Fifth Line of Defense Team Process and Emergency Response

Technology is only part of it, process is more critical.

Rely on whitelist. Important projects maintain a list of internally allowed npm packages, and new dependencies must be reviewed before they can be added. This is especially important for teams of 100+ people.

Weekly vulnerability review. Set up a security owner to scan GitHub Advisory and osv.dev every week, filter out CVEs related to this warehouse, and promote repairs.

Emergency response plan. Once a package is discovered to be poisoned, there should be standard procedures. Immediately stop all deployments of the package, rollback to the last known clean version, audit CI logs and external network traffic within 7 days, and notify customers and compliance departments.

Credential rotation drill. Practice the recovery process of "assuming all secrets are leaked" every quarter. Only by practicing it can you replace all keys within 30 minutes in a real accident.

The changes that are emerging in the open source ecosystem in 2026

Supply chain issues have forced some new industry trends.

npm launches provenance mechanism to support GitHub Actions signature chain for package releases starting in 2024. In 2026, all head packages such as axios, express, and react have been enabled and can be verified through npm install --check-provenance.

The GitHub Sigstore project provides cryptographic signatures for open source software and will become a Linux Foundation standard in 2026. npm, PyPI, RubyGems are all integrated.

The EU CRA Act will take effect in 2026, requiring all commercial software entering the European market to provide SBOM and have ongoing obligations to repair known vulnerabilities. This forces major manufacturers to fully embrace supply chain tools.

Supervision by various countries is also following suit. U.S. Executive Order EO 14028 requires federal procurement software to have an SBOM. China GB/T 43698-2024 also requires critical software to provide a software bill of materials. Supply chain security has moved from best practice to legal obligation.

5 things that individual developers can do at the lowest cost

Not every team has a Snyk budget. Individual developers must do at least 5 things:

The first lock version number. Delete ^ and ~, and fix all dependencies to patch.

Second enable GitHub Dependabot. Free, automatic scanning and issuing PR upgrades with CVE dependencies.

The third CI uses npm ci to develop the habit of lockfile submission locally.

Fourth, add npm audit into the pre-commit hook, which is slow but can intercept known vulnerabilities.

Fifth, subscribe to the free version of socket.dev and add GitHub bot. Any new dependency will have a risk score prompt during the PR stage.

These 5 things are zero to very low cost, but can block 80% of known supply chain attacks.

FAQ

npm audit reports a bunch of vulnerabilities, what should I do?

Don't ignore it and don't upgrade them all at once. First sort by severity level, critical and high. Immediately look at the CVE details to determine whether it is on the production path. If it is, upgrade immediately or add npm overrides to lock it to a safe version. moderate and low can be batched but left until the test covers the full window. Note that npm audit will report vulnerabilities in dev dependencies. These usually do not affect production code and can be deferred.

How to prevent AI-recommended packages from being malicious in the era of Vibe Coding

Do not install the packages recommended by the AI ​​assistant directly. First check the release date, maintainer, download volume, and recent version changes of the package on the npm official website. Be wary of newly released packages with low download volume. Enter the package name on socket.dev to see the risk score. You can let AI output multiple candidates and cross-validate them by yourself. For important scenarios, you still only choose industry cornerstone packages such as react, express, and lodash.

It is impossible for our small team to conduct SBOM. Is this illegal?

It depends on market orientation. If the product is sold to European companies or governments, the CRA Act requires a SBOM from 2026. If it is only domestic SaaS for a short period of time, it may not be needed. However, the cost of generating SBOM is actually very low. The npm sbom command directly outputs JSON in CycloneDX format, and it can be run once connected to GitHub Actions. It is recommended that you do it in advance even if it is not mandatory, so that you will not be passive later.

Is it okay if the company bans npm and uses private servers instead?

Yes but not a silver bullet. Private servers such as verdaccio or Nexus can cache upstream packages and add whitelists, but if the package you whitelist itself is poisoned, the private server will also be contaminated. The real value of the private server is auditability. All dependencies pulled by team members pass the private server, the logs are unified, and abnormal dependency access can be checked immediately. Still have to work with auditing tools like socket.dev or Snyk.

What should you do if you find that you have introduced a poisoning package?

Immediately proceed in the following order. The first rollback deployment rolls back the package version to a known safe version before the incident. Second, check the git log to see which PR was introduced, and all CI logs of the PR are audited. The third round rotates all potentially leaked secrets, including AWS, GCP, GitHub PAT, and third-party API keys. Fourth, scan the outbound logs to see abnormal domain name access. Fifth, notify customers and the compliance department to retain evidence. Sixth, write a review document afterwards and add it to the emergency database.

Source of inspiration: Issue 392 of Ruan Yifeng's "Technology Enthusiasts Weekly" https://www.ruanyifeng.com/blog/2025/09/weekly-issue-392.html

📝 本文来自抖文 www.douwen.me ,转载请保留出处。

💬 评论 (6)

A
AIWatcher 2026-05-18 09:39 回复

Practical tips not fluff.

D
DevTools 2026-05-18 04:33 回复

Thanks for the detailed comparison.

A
AIWatcher 2026-05-18 06:57 回复

Best summary I've read on this.

D
DevTools 2026-05-17 18:23 回复

Bookmarked for reference.

A
AIWatcher 2026-05-17 18:53 回复

Loved the FAQ section.

A
AIWatcher 2026-05-17 18:09 回复

Solid breakdown, very useful.