Application Security

Software Supply-Chain Attacks: Why Your Dependencies Can Become Your Biggest Risk

Two weeks ago, a researcher showed he could run code inside Apple, Microsoft, PayPal and dozens of other companies simply by publishing packages with the right names. Dependency confusion joins typosquatting and maintainer takeover as ways attackers abuse the open-source packages every application depends on. Here is how the attacks work and how to defend against them.

By EthicalHat Research · · 3 min read
Infographic: Three ways attackers poison your dependencies

On 9 February, security researcher Alex Birsan published a write-up titled Dependency Confusion. He described how he had executed code inside the networks of more than 35 organisations, including Apple, Microsoft, PayPal, Shopify, Netflix, Tesla and Uber, without phishing anyone or exploiting a single server vulnerability. He simply published packages to public registries with the same names as those companies' internal packages. Their build systems downloaded and ran them.

He did it ethically, through bug bounty programmes, and was paid more than $130,000 in rewards. Attackers have already begun copying the technique.

Your application is mostly other people's code

A typical Node.js, Python, Java or .NET application depends on dozens of direct dependencies and hundreds of transitive ones. By volume, most of the code you ship was written by someone else, installed automatically by a package manager and trusted implicitly.

That trust is what supply-chain attacks exploit.

Dependency confusion

Many companies use private packages with names like acme-billing-utils, installed from an internal registry. Package managers can be configured to look in both the internal registry and a public one such as npm or PyPI. In some configurations, if a package with the same name exists publicly with a higher version number, the package manager installs the public one.

sequenceDiagram
  participant B as Build server
  participant I as Internal registry
  participant P as Public registry
  Note over P: Attacker publishes acme-billing-utils@99.0.0
  B->>I: acme-billing-utils?
  I-->>B: 1.4.2
  B->>P: acme-billing-utils?
  P-->>B: 99.0.0
  B->>B: installs 99.0.0 (higher version) and runs its install script

Internal package names leak in many ways: package.json files in public repositories, JavaScript bundles served to browsers, error messages and job adverts.

Typosquatting

Attackers register names that are one typo away from popular packages (crossenv instead of cross-env, urlib3 instead of urllib3) and wait for developers to mistype. Registries remove these regularly, and new ones keep appearing.

Compromised maintainers and malicious updates

When an attacker gains control of a legitimate package, through stolen credentials, a transferred project or a malicious new maintainer, every user who updates receives the attacker's code.

  • In 2018, the popular npm package event-stream was handed to a new maintainer, who added a dependency containing code targeting a specific cryptocurrency wallet application.
  • Also in 2018, a compromised maintainer account was used to publish a version of eslint-scope that tried to steal npm credentials.

Install scripts: code that runs before you look

npm packages can run scripts on install (preinstall, postinstall), and Python packages can run code in setup.py. That means a malicious package executes during the build, often with access to CI secrets, before any test or review.

Defences

1. Use scoped or namespaced internal packages. On npm, publish internal packages under an organisation scope (@acme/billing-utils) that you own publicly, so nobody else can publish under it.

2. Route all installs through a private registry proxy that serves internal packages and proxies approved public ones, and configure it so internal names can never resolve publicly.

ini
# .npmrc: internal scope from the private registry, everything else via the proxy
@acme:registry=https://npm.internal.acme.example/
registry=https://npm-proxy.internal.acme.example/

For Python, avoid --extra-index-url for internal packages, which can let pip consider both indexes. Point pip at a single internal index that proxies PyPI, or pin exact versions with hashes.

bash
# Require every package to match a known hash from the lock file
pip install --require-hashes -r requirements.txt

3. Commit lock files and verify integrity. package-lock.json, yarn.lock, poetry.lock and hash-pinned requirements ensure builds install exactly what was reviewed.

4. Control install scripts. Where practical, install with scripts disabled (npm ci --ignore-scripts) and allow-list the packages that genuinely need them.

5. Review new dependencies. Before adding a package, check its maintainers, popularity, activity and whether a smaller or standard-library alternative would do.

6. Monitor continuously. Software composition analysis tools flag known-vulnerable and known-malicious packages; alerts on unexpected new dependencies catch surprises.

7. Limit what builds can reach. Keep secrets out of dependency installation steps, and restrict network egress from build agents.

The bottom line

Every dependency is a relationship of trust, and attackers are finding creative ways to abuse it. Dependency confusion showed that even the world's most sophisticated engineering organisations had gaps. Scoped names, a single controlled registry, lock files, restricted install scripts and deliberate review of new packages close most of them.

Our secure code review and application security testing services include dependency and build configuration reviews to find exactly these gaps.

EthicalHat Research

The EthicalHat research team: penetration testers, SOC analysts and engineers writing about security, software engineering and AI.

Want an expert opinion on your own systems?

Email info@ethicalhat.com or call +1-844-838-4422. Our security engineers are happy to talk it through.