Lesson 14 of 14 · 13m
When a Package Goes Bad
Scope with the SBOM, rotate what the install env held, rebuild clean, then fix the door it entered through.
The version you want is gone — now what
Monday morning: ua-parser-js is in your tree and versions 0.7.29/0.8.0/1.0.0 were just flagged as credential stealers. npm update does not fix this. The postinstall already ran — possibly on every developer laptop and every CI runner that installed during the window. Removal stops the bleeding; it doesn't retrieve what the script already read.
The ordering below is the difference between an incident and a shrug.
Step 1: Scope it — what installed, where, when
The SBOM is now the tool it's always been for: query pkg:npm/ua-parser-js across every version's SBOM to enumerate affected artifacts. No SBOM? grep -r 'ua-parser-js' **/package-lock.json across repos, npm ls ua-parser-js per service, and the CI logs answer "which builds ran the bad version." Egress logs matter too — the malicious package beaconing to its endpoint is evidence of the window.
Malware ≠ vuln, administratively. A backdoored version sometimes never gets a CVE; it shows up in GitHub advisories (GHSA), Socket/Snyk feeds, and the OSV database — osv-scanner and grype read OSV, so scan the lockfile, not just CVE feeds. Registry removal cuts both ways: once the bad version is yanked, new installs get "version not found" — but the artifacts already built during the window still contain it, which is why the SBOM per shipped version is the record that outlives the registry's cleanup.
Step 2: Rotate — everything the install could see
A postinstall script inherits the environment it ran in. Rotate in order of exposure breadth:
- npm/GitHub tokens in
~/.npmrcand CI secrets — these publish more packages; first priority. - Cloud credentials (
AWS_*, service accounts) reachable from dev machines and runners. - SSH private keys in
~/.ssh— thectx/python3-dateutilpayloads went straight for these. .envfiles, kubeconfigs, database URLs — whatever lives where installs run.
The Copay-targeting flatmap-stream payload stole wallet keys; the ua-parser-js payload stole credentials and mined. Assume read of everything in scope, not just what the writeup says the sample did.
Step 3: Rebuild — from a clean room
Delete node_modules, regenerate the lockfile on a known-good machine (not the possibly-infected one — it may hold the poisoned artifact and re-lock it), and npm ci --ignore-scripts back to a verified tree. Artifacts built during the exposure window are suspect: diff them, or rebuild them. If you shipped images during the window, the blast radius includes whatever the install env held at build time.
Step 4: Close the door it used
Post-incident question: how did it enter? Each answer has a fix from earlier lessons:
- Fresh dep nobody vetted → vetting gate + private registry quarantine.
- Auto-bumped version → cooldown (
minimumReleaseAge), diff review on bumps touchingscripts. - Lockfile
resolvedtampering →lockfile-lint, proxy-only installs. - Public name shadowing internal → scoped registry mapping + exclusion rules.
- Mutable CI refs → SHA pinning.
The wrong mental model
"Patch to the clean version and move on." Version-bumping past a malicious release is the response to a vulnerability — a bug fixed forward. Malware isn't fixed forward; it already ran. The unit of remediation isn't the version, it's the environment that executed it. Rotate what the environment held. Then find the door.
Write the runbook before you need it
The response above is four queries and a rotation checklist — none of it hard, all of it forgotten at 9 AM under pressure. Put it in a doc now: where SBOMs live, who rotates tokens, what the egress logs are called, which registry is the chokepoint. The incidents in this course all got found by someone pulling a thread — Freund's half-second sshd delay, Sparling's deprecation warning. The thread gets pulled faster when the map already exists.
Was this lesson helpful?
Keep reading
Related articles from the SudoSecurity blog.
Buying Time: Package Managers Are Adding Delay as a Security Control
Composer 2.11 shipped a cooldown that refuses to install a version until it has aged. vlt now holds npm publishes until their dependencies actually exist, because 22% of new npm versions land broken. And Ruby Central's reviewers threw out 90% of what an AI scanner flagged.
Your npm Install Just Ran Someone Else's Code: Why Dependency Security Has to Start Before CI
A pull request checkout, a poisoned GitHub Actions cache, and an OIDC token pulled straight out of runner memory. That's how 84 malicious versions of TanStack's packages hit npm in six minutes.
CVE-2025-62718: Critical Axios SSRF Vulnerability Explained
A critical SSRF flaw in Axios was used in a North Korean supply chain attack. Here's what it does and how to patch it today.
What is Supply Chain Security? Dependencies, SBOMs, and the Attack That Hit 2.6 Billion npm Downloads
Your application is only as secure as every package it depends on. In September 2025, attackers compromised 27 npm packages with 2.6 billion weekly downloads by phishing one maintainer.