Malicious npm Package Exfiltrated Environment Variables at Build Time

A typosquatted npm package installed via a developer's local npm install exfiltrated AWS credentials from CI environment variables.

Overview

A one-word typo pulled in a typosquatted npm package whose install script sent CI's AWS keys to an attacker, who then swapped the site's JavaScript bundle for 6 hours.

What happened

Setting up a new project, a platform developer typed npm install lodash-utils instead of lodash. The package had been published to npm 3 weeks earlier. A typosquatted package like this one is named to be mistaken for a popular one. The developer also added it to the project's package.json without noticing it was not lodash. From there the incident ran in six steps.

  • The typo installed lodash-utils.
  • The package was added to package.json.
  • CI cloned the project and ran npm install.
  • The package's postinstall script sent CI's AWS keys out.
  • The attacker served a malicious CDN bundle for 6 hours.
  • Finally, the team rotated the keys.

Key concepts

  • Typosquatting
  • Postinstall script attack
  • Lock file integrity
  • OIDC for CI credentials

Interview questions

  • How do you protect CI/CD pipelines from malicious npm packages?

Sign up free to read the full topic

More War Stories topics

Start free on Cariara · Coding problems · System design studio