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
- Blue-Green Deployment That Resulted in Split-Brain Sessions
- Cache Stampede on a Flash-Sale Product Page
- Connection Pool Exhaustion That Brought Down 12 Microservices
- DynamoDB Hot Partition That Throttled a Flash Sale
- Failover to a Lagging Replica Lost 4 Minutes of Orders
- Internal DNS Cache Poisoning That Redirected API Traffic
- N+1 Query Pattern That Collapsed Under Load
- NAT Gateway Port Exhaustion Under Bursty Lambda Traffic
- Node.js Memory Leak That Required Daily Restarts
- Public S3 Bucket Exposed Customer PII for 8 Months
- Silent Data Corruption from an Off-By-One Migration
- Single-Region Dependency That Caused a Global Outage
Start free on Cariara · Coding problems · System design studio