# How a Single Vulnerability Can Bring Down the JavaScript Ecosystem

Malformed headers caused npm registry backend to error, letting attacker cache a 404 for a package tarball and deny installs to all users.

- Payout: $500
- Severity: medium
- Program: GitHub
- Found by: Roni Carta
- Disclosed: 2024-06-03
- Write-up quality: 6/10
- Original: https://www.landh.tech/blog/20240603-npm-cache-poisoning/
- Library page: https://bugbountylibrary.com/r/blog%3Alandh-tech-blog-20240603-npm-cache-poisoning
- Tags: area:cloud domain:infra domain:web impact:dos impact:integrity kind:bounty platform:blog sev:medium tech:cdn technique:recon vuln:cache-poisoning vuln:dos

**Target:** npm registry (registry.npmjs.org) tarball download endpoint behind Cloudflare
**Root cause:** Backend errored on a specific header set and the CDN cached the resulting 404 under the request's cache key, so subsequent clean requests got the poisoned Not Found response.
**Steps:**
1. Send `GET /safe-regex/-/safe-regex-1.1.0.tgz?<cachebuster>=cpdos_test` with a crafted header set (e.g. `lupin: <value>`) that triggers a backend error.
2. Backend returns 404 Not Found; CDN caches it under the cache-buster key.
3. Re-send the same request without the trigger header and same cache key; receive cached `404 {"error":"Not found"}`.
4. Repeat every few minutes to maintain poisoning and across backends to cover multiple servers.
**How found:** While building a Depi submodule to test CPDoS against artifactories, they ran it against npmjs.com as a sanity check and got a hit on the first run, then confirmed it wasn't a false positive.
**Exploitation:** Attacker sends crafted-header requests to poison the CDN cache for a target package tarball; subsequent legitimate `npm install` requests hit the cached 404, breaking installs. No auth or capital needed; only periodic re-poisoning to keep cache warm.
**Escalation:** Targeting high-download packages like express amplifies impact across the supply chain; pre-poisoning before a new version is published could break fresh installs.
**Insight:** When testing CPDoS on a registry/CDN, use a unique cache-buster query param so you poison only your own key, then replay without the trigger header to confirm the cached error is served to clean requests.

## Proof of concept (copied exactly from the original report)

**Poisoning request with cache buster and header**

```
GET /safe-regex/-/safe-regex-1.1.0.tgz?lupin_E7A812DE-E09A-4906-A9E3-530E54AAEB41=cpdos_test HTTP/1.1
Host: registry.npmjs.org
User-Agent: lupin_test_cpdos
lupin: E7A812DE-E09A-4906-A9E3-530E54
```

