NPM and PyPI Supply Chain Attacks

NPM and PyPI supply chain attacks inject malicious code into widely used libraries, hitting every downstream project automatically.

SECURITY5 min readBy AlgoSys Editorial TeamPublished Apr 24, 2026Updated Jun 26, 2026
Contents

A supply chain attack does not target a running application: it targets how the application is built. The attacker injects malicious code into a popular library, and from there it spreads automatically as hundreds of projects pull in the compromised package. In the NPM registry (the package repository for JavaScript) and PyPI (the same for Python), these attacks are especially dangerous because the goal is almost always the same: steal credentials, plant malware, or disrupt services. Cryptocurrency projects are in a zone of heightened risk precisely because they are built almost entirely on open-source libraries while private keys and real money are at stake.

The Lazarus Group has been linked to a number of such attacks, and its activity illustrates how sophisticated these threats have become. The Wormhole bridge incident in 2022 was primarily a bridge exploit, but it served as a vivid reminder of how tightly development tools and potential attack vectors are intertwined. Vigilance here is not a one-time measure but an ongoing habit, because the threats keep evolving.

The main danger of a compromised package lies in its reach. One infected package pulls in all downstream projects and their users, and the goal almost always comes down to unauthorized access: to sensitive data, private keys, or financial assets. This is why defenses must be built in advance, not assembled on the fly after a breach.

MECHANICS

First, the attacker gains control of a popular package. This most often happens through social engineering (manipulating people rather than code) or by taking over a maintainer's abandoned account that nobody has monitored for a long time. Malicious code is then added to the package source, disguised as an ordinary, legitimate update. It may execute immediately during installation or later, when the project calls a specific function.

To make the practical picture clearer, here is a typical scenario broken down step by step:

  1. A malicious dependency enters the project's package.json (for NPM) or setup.py (for PyPI), most often disguised as an innocuous version bump.
  2. The developer runs npm install or pip install, and the compromised package is downloaded and executed on their machine.
  3. The malicious payload exfiltrates (silently uploads) environment variables and API keys, and in the worst case attempts to take over the developer's workstation itself.

A separate category of attacks targets not the package itself but the publishing process. This includes typosquatting, where a package is given a name nearly indistinguishable from a legitimate one (for example, differing by a single letter) to catch a typo during installation, and exploiting vulnerabilities in version control systems. The logic is always the same: trick a developer into including foreign code in their application.

RED FLAGS

Attention needs to be maintained at several levels simultaneously, from maintainer reputation to what happens during the build. On reputation: check who changed the package recently and whether there is any unusual activity or a sudden change of ownership. On download integrity: verify the package's cryptographic hashes before installation to confirm the file has not been substituted. Build behavior itself is also informative: monitor logs for unexpected network requests or the execution of external scripts, and be suspicious if a dependency update suddenly changes file sizes or code complexity without any apparent reason.

Automation sits on top of manual checks. Run dependencies through static analysis tools that search for suspicious code patterns, and where possible verify confirmed package authorship and security attestations. Finally, make sure your CI/CD pipeline automatically checks every new and updated dependency so that a compromised update cannot slip past human review.

To condense this into a handy reference, here are the main indicators and exactly what to examine for each:

Indicator What to look for
Maintainer history Unusual activity, sudden change of account ownership
Download integrity Matching cryptographic hashes of the package
Build behavior Unexpected network requests, foreign scripts in the logs
Update contents Sudden growth in file size or code complexity
Authorship and attestations Confirmed authorship, security attestations
CI/CD checks Automated scan of every new dependency

PROTECTION

The foundation of protection is solid dependency management. Pin specific, audited versions of libraries rather than floating ranges, so that an update cannot arrive unnoticed. Regularly audit dependencies and their sources, looking for any unauthorized changes. Automate the search for known vulnerabilities using scanning tools such as Snyk, Dependabot, or Trivy.

Discipline within the team is equally important. Apply strict code review to all code without exception, including dependency updates and internal libraries. For critical components, use code signing and verification: this guarantees the code has not been substituted in transit. And be sure to train your developers, because a team that understands how supply chain attacks work itself becomes a layer of defense.

For the most sensitive dependencies it may be worth moving away from public registries. Private package registries and internal mirrors give you more control over what actually enters the project and provide an additional layer of vetting. Maintain a comprehensive inventory of all dependencies and their associated risks so you always know exactly what is installed when you need to know.

AFTERMATH

The first actions must be immediate and decisive. Isolate affected systems and revoke all compromised credentials and API keys. Halt deployments and development on potentially infected codebases to avoid spreading the problem further. Then activate your incident response plan: assess the scope of the breach and pinpoint exactly which malicious payload was triggered.

External communication comes next. Report the incident to the relevant registry (NPM, PyPI) and specialist security platforms. Notify affected users and partners with clear instructions on what to do. For forensic analysis and recovery assistance, it is worth engaging a specialized incident response firm.

The final stage is investigation and returning to normal operations. Cooperate with law enforcement and share technical information to assist the investigation. Restore systems only from trusted backups, re-auditing all critical code and dependencies. And strengthen monitoring and security controls so the same door does not open again.

FAQ

What is a supply chain attack on NPM and PyPI?

This is an attack where an adversary injects malicious code not into the application itself but into a popular library it depends on. When a developer installs or updates a compromised package from the NPM or PyPI registry, the malicious code enters their project automatically. The danger lies in the scale: one compromised package affects every project that uses it.

What is typosquatting and why is it dangerous?

Typosquatting happens when an attacker publishes a package with a name nearly identical to a legitimate one, counting on a typo during installation. The developer accidentally installs the fake instead of the real package and pulls malicious code into their project. Protection comes from carefully checking the package name before installing and pinning verified versions.

Why are crypto projects especially vulnerable to these attacks?

Crypto projects are built almost entirely on open-source libraries, meaning they depend on third-party code more heavily than most. At the same time, private keys and real financial assets are at stake, and the malicious payload is specifically aimed at stealing credentials, keys, and money. The combination of many dependencies and high-value assets makes them a priority target.

What tools help find malicious dependencies?

Snyk, Dependabot, and Trivy can be integrated directly into the CI/CD pipeline to scan for known vulnerabilities. It is also worth using static analysis tools that search for suspicious patterns in code and verifying the cryptographic hashes of packages before installation. The more checks are automated in the build, the less chance a compromised update slips through.

What is the very first thing to do if a dependency turns out to be compromised?

First, isolate the affected systems and revoke all compromised credentials and API keys. Halt deployments and development on the infected codebases to prevent the problem from spreading further, and activate your incident response plan to assess the scope. After that, report to the registry (NPM or PyPI), notify users, and if needed engage a forensic firm.

How can you reduce the risk of a supply chain attack in advance?

Pin specific, audited versions of libraries instead of floating ranges, audit your dependencies regularly, and apply strict code review to all code including package updates. For critical components use code signing and verification, and for the most sensitive dependencies consider private registries and internal mirrors. Also train your team: a developer who understands how these attacks work becomes a security layer in their own right.

Put this to work in the terminal

Live charts, derivatives, on-chain and macro data, free.

Open terminal →