Skip to content

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 ~/.npmrc and CI secrets — these publish more packages; first priority.
  • Cloud credentials (AWS_*, service accounts) reachable from dev machines and runners.
  • SSH private keys in ~/.ssh — the ctx/python3-dateutil payloads went straight for these.
  • .env files, 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 touching scripts.
  • Lockfile resolved tampering → 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?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.