Security

What Is a Supply Chain Attack? Software Examples and Defences

A supply chain attack compromises software you trust (a library, a build server, a package registry or an update channel) so that malicious code reaches you through your normal installs and updates. Instead of breaking into your systems directly, the attacker breaks into something upstream that you already let in.

The most useful single defence for application teams is to install only from a committed lockfile (for npm, npm ci), so nothing changes in your dependency tree without a reviewed commit.

Where a supply chain can be attacked

The SLSA framework (Supply-chain Levels for Software Artifacts) breaks the path from source code to installed package into stages and gives a real incident for each. This table follows its threats overview:

StageThreatReal example cited by SLSA
SourceUnauthorised change submitted to the repoSushiSwap: a contractor with repo access pushed a commit redirecting funds to themselves
SourceSource repository compromisedPHP: attackers compromised the self-hosted git server and injected commits
BuildBuild from source that doesn't match the repoWebmin: build infrastructure used modified source files
BuildBuild process compromisedSolarWinds: the build platform was compromised and an implant installed
DependenciesCompromised dependencyevent-stream: an innocent-looking dependency was added, then later updated with malicious code
DistributionModified package uploadedCodecov: leaked credentials used to upload a malicious artifact to a storage bucket
DistributionRegistry or mirror compromisedA researcher ran package mirrors that could have served malicious packages
ConsumptionLook-alike package installedBrowserify typosquatting: a malicious package with a near-identical name

The pattern is the same throughout: the victim never ran anything unusual. They pulled an update, ran a build, or installed a package with a familiar name.

SolarWinds Orion (2020): the build system

CISA's advisory AA20-352A describes how attackers added a malicious version of the file solarwinds.orion.core.businesslayer.dll to SolarWinds Orion. The backdoor, called SUNBURST, was present in Orion Platform versions 2019.4 HF5, 2020.2 RC1, 2020.2 RC2, 2020.2 and 2020.2 HF1. The detail that matters for defenders: the DLL was "signed by the legitimate SolarWinds code signing certificate". Customers who checked signatures, as they should, still installed the backdoor, because it was inserted before signing.

The xz backdoor (2024): a dependency deep in the stack

CVE-2024-3094, published by Red Hat on 2024-03-29, states: "Malicious code was discovered in the upstream tarballs of xz, starting with version 5.6.0." The record explains that "the liblzma build process extracts a prebuilt object file from a disguised test file existing in the source code", which then modifies functions in liblzma, a compression library that many other programs link against. Versions 5.6.0 and 5.6.1 were affected.

Two lessons from that record. First, the malicious part was in the release tarballs and hidden in test files, so reading the main source in the git repository was not enough to see it. Second, the target was a small, widely used library, which is exactly the kind of component nobody on an application team reviews.

Supply chain attacks in package registries

For most developers, the supply chain is npm, PyPI, crates.io or Maven Central. The common attack shapes there are:

  • Typosquatting: a malicious package named like a popular one.
  • Account takeover: an attacker gets a maintainer's credentials and publishes a malicious new version of a real package.
  • Delayed dependency swap: the event-stream pattern, where an innocent-looking dependency is added and later updated with malicious code.
  • Install scripts: npm runs preinstall/install/postinstall scripts from packages by default, so a malicious package can run code the moment it is installed, before you import it.
  • Hallucinated package names: AI coding assistants sometimes suggest packages that don't exist. A USENIX Security 2025 study generated 576,000 code samples with 16 models and found that on average at least 5.2% of packages suggested by commercial models and 21.7% by open-source models were hallucinated, with 205,474 unique made-up names. Anyone can register one of those names and wait. See how to review AI-generated code.

How to defend your own projects

1. Lock and pin your dependency tree

Commit the lockfile and install from it in CI:

npm ci

The npm docs say npm ci requires an existing package-lock.json, exits with an error instead of updating the lock if it disagrees with package.json, and "will never write to package.json or any of the package-locks". A new malicious release of a dependency can then only reach you through a commit that changes the lockfile, which someone can review. Setting save-exact=true in .npmrc makes npm install <pkg> record an exact version rather than a ^ range.

2. Turn off install scripts where you can

npm ci --ignore-scripts

With ignore-scripts, npm "does not run scripts specified in package.json files". Some packages need their install script (native modules that compile on install, for example), so test the build before making this the default. Explicit commands like npm test still run their own script.

3. Verify signatures and provenance

npm audit signatures

Real output from a small project, run with npm 10.9.2:

audited 41 packages in 1s

41 packages have verified registry signatures

On npm 9.8.1 the same command failed with EEXPIREDSIGNATUREKEY, reporting that a package's registry signature used a public key that "has expired 2025-01-29". Running it with a current npm (npx [email protected] audit signatures) passed. Keep npm up to date if you rely on this check.

Provenance goes further: packages published from GitHub Actions or GitLab CI/CD with npm publish --provenance carry a statement of which repository and build produced them, and npm audit signatures reports how many have verified attestations. The npm docs are careful about the limit: provenance shows where and how a package was built, not that its code is free of malware. It would have exposed a Codecov-style upload that bypassed the normal build. It would not have stopped SolarWinds, where the build itself was compromised.

4. Review new dependencies before adding them

  • Check the exact name on the registry page: download counts, repository link, publish history. A package first published last week with a name one letter off a famous one is a red flag.
  • Look at what it pulls in: npm view <pkg> dependencies before installing, npm ls --all after.
  • Ask whether you need it at all. Every dependency is code you are trusting to run with your permissions.

5. Watch for known vulnerabilities

npm audit, Dependabot and similar tools compare your lockfile to published advisories, which are usually keyed by CVE IDs. They catch known issues in honest packages and published malware once someone reports it. They cannot catch a malicious version on the day it is released, so they complement the steps above rather than replace them.

6. Limit what a compromised package could reach

Run builds with only the credentials they need, keep publishing tokens out of general CI jobs, and do not give build machines access to production secrets they don't use. This is the principle of least privilege applied to your pipeline: if a dependency does turn out to be malicious, it can only steal what that job could see.

If you think you installed a malicious package

Remove it and pin the last known-good version, then assume anything the install or build could read was exposed: rotate npm, cloud and CI tokens, SSH keys and any secrets in environment variables on affected machines and runners. Check the package's advisory or the registry's security notice for indicators, such as files or network destinations, and search your machines and logs for them. Rebuilding affected machines is safer than trying to clean them when the malicious code ran with your user's or the CI runner's permissions.

Frequently asked questions

What is the difference between a supply chain attack and a normal vulnerability?
A normal vulnerability is an accidental flaw that an attacker exploits from outside. In a supply chain attack the attacker deliberately inserts malicious code into a component, build system or update channel that the victim already trusts, so the victim installs the attack themselves through their normal update or build process.
Does a signed update mean it is safe?
No. A signature proves which key signed the file and that it hasn't changed since. In the SolarWinds case, the backdoored DLL was signed with SolarWinds' legitimate code-signing certificate because the attackers were inside the build process. Signatures stop tampering after the build, not compromise during it.
What is typosquatting?
Publishing a malicious package under a name that looks like a popular one, hoping someone mistypes it or copies the wrong name. SLSA lists the Browserify typosquatting case as an example. Check package names character by character before installing, especially names suggested by search results or AI assistants.
Is npm audit enough to protect against supply chain attacks?
No. npm audit reports dependencies with known, published vulnerabilities. A freshly published malicious package or a backdoored release has no advisory yet, so audit will not flag it. Combine audit with lockfiles, pinned versions, review of new dependencies and provenance checks.

Sources