Secrets

Supply chain attacks on npm and Composer: what protects your secrets

Updated: 26 October 2026

A modern application consists mostly of other people's code: hundreds of packages from npm, Packagist (Composer), PyPI or other registries. If one of them is compromised, the malicious code runs with exactly the permissions of your application – on the developer machine, in the CI pipeline and on the server.

How a supply chain attack works

An attacker gets malicious code into a package that other projects depend on. The usual routes:

  • Taken-over account: a maintainer's account is taken over through a reused password, phishing or a stolen token, and a new version with malicious code is published.
  • Handed-over project: a package changes owner; the new maintainer adds malicious code or a malicious dependency.
  • Confusion: packages with similar names (typosquatting) or with the same name as internal packages in a public registry (dependency confusion).
  • Compromised tools: a script or action that runs in the pipeline is modified.

The malicious code often runs during installation already: npm executes install scripts (preinstall, postinstall), Composer has scripts and plugins that run during composer install. At the latest, every included library runs along when the application starts.

What malicious code looks for first: credentials

Secrets are the easiest target because they immediately grant further access. Typical patterns:

  • Reading environment variables – in Node with process.env, in PHP with getenv() or $_ENV – and sending them to a foreign server.
  • Searching files: .env, .npmrc with registry tokens, Composer's auth.json, ~/.ssh, cloud credentials in ~/.aws or ~/.config.
  • Grabbing CI secrets: in a pipeline, deploy keys and registry tokens are often available as environment variables – for every step, including npm install.
  • Spreading: with stolen registry tokens, the malicious code publishes new versions of further packages.

Known examples

  • event-stream (2018): a new maintainer of the widely used npm package added a dependency with hidden malicious code aimed at a specific Bitcoin wallet application.
  • ua-parser-js (2021): through a taken-over account, versions were published that downloaded malware during installation, including a program that steals credentials.
  • Codecov Bash Uploader (2021): a modified uploader that ran in many CI pipelines sent the pipelines' environment variables – including credentials – to the attackers.
  • Shai-Hulud (2025): a self-spreading worm in npm packages searched developer machines and pipelines for tokens and secrets and published them.

The pattern is the same every time: wherever secrets are reachable in plaintext, the malicious code takes them along. The same principle applies to Composer and other package managers, because there, too, third-party code runs with the project's permissions.

What helps

1. Check and pin dependencies

  • Commit lockfiles (package-lock.json, composer.lock) and install exactly these versions in CI with npm ci or composer install.
  • Check for known vulnerabilities regularly: npm audit, composer audit.
  • Allow install scripts only where needed (npm ci --ignore-scripts; for Composer --no-scripts and explicitly allowed plugins).
  • Add new dependencies deliberately: who maintains the package, how many dependencies does it pull in?

2. Minimize permissions

The build step needs no production credentials, the test run no deploy key. Give every step only what it needs, and separate environments: with stages, production has its own file in Secrets with its own authorized people – a test token cannot reach production values at all.

3. No long-lived plaintext keys on the server

A .env that permanently sits on the server is just one file among many for any malicious code in the process. With Secrets, only the encrypted secrets.enc is there; it is decrypted into the process environment only at startup:

secrets-tool remote pull shop-backend
Invoke-Expression (secrets-tool load)   # PowerShell
eval "$(secrets-tool export | sed 's/^/export /')"   # Bash

This does not replace checking your packages – code inside the same process still sees its environment. But it removes the plaintext copies on disk, in backups and in images, and it limits what an attacker gains from a single file access. For Docker hosts, secrets-tool hostenv writes env files with mode 600 without any value appearing in a command line.

4. One token per pipeline and per server

In Secrets, every pipeline and every server gets its own API token under My access → API tokens. If a project falls victim to a compromised package, you revoke exactly that token; the others keep running. See Connect the CLI directly.

5. Rotation

A value that was once reachable in plaintext must be considered known. After an incident, removing the package is not enough: database passwords, API keys and registry tokens have to be replaced. With Secrets you change the value once (secrets-tool set DB_PASSWORD prompts for the new value without echoing it), and every server picks it up on the next remote pull.

6. Check repositories

secrets-tool check finds plaintext values, private keys and tokens (among others from GitHub, GitLab, AWS, Slack and Stripe) in the repository, and with --verlauf also in older commits. In CI it runs as secrets-tool check --json --offline and fails with exit code 1 on errors:

secrets-tool check --hook        # before every commit
secrets-tool check --verlauf     # also old versions in all branches

More under Check a repository.

In short

  1. Lockfiles, audits and as few install scripts as possible.
  2. Every step and every environment only gets the secrets it needs.
  3. No plaintext on disk, in images or in backups – values only at runtime.
  4. Separate, individually revocable tokens per pipeline and server.
  5. After an incident, rotate – don't just clean up.

How to use Secrets in pipelines is shown in Secrets in CI/CD and deployment. Get the program under Download.