Lesson 5 of 12 · 20m
Supply Chain Attacks: Trusting Code You Didn't Write
event-stream, ua-parser-js, and the xz backdoor — how dependencies get weaponized and what actually verifies them.
npm install does not just download code — it runs the package's postinstall scripts as you, on your machine, with your credentials in scope. Drop a JAR into a plugins directory and the host calls Class.forName(name, true, loader) on whatever it finds. Every dependency is code you chose to execute without reading; the supply chain is the trust path between its author and your runtime, and attackers spend real effort compromising the path rather than your code.
The wrong mental model: "my risk lives in the code I wrote; dependencies are vetted by the ecosystem." Nobody vets. You inherit the security posture of every maintainer in your tree — often hundreds of strangers — plus the integrity of the artifacts between their laptop and your deploy.
How it actually gets breached
The friendly hand-off. In 2018 the maintainer of event-stream — a package with ~2 million weekly downloads — gave the repo to a stranger who offered to help. The new maintainer added flatmap-stream, which shipped a payload aimed at one company's bitcoin wallet. Nobody was "hacked" in the technical sense; trust was transferred, then cashed in. The same month, nobody audits volunteer burnout.
The account takeover. In October 2021 ua-parser-js, coa, and rc — tens of millions of weekly downloads combined — had malicious releases pushed by attackers using maintainer credentials harvested from reused passwords and phishing. Cryptominers and credential stealers ran in preinstall. In 2022, ctx and php's composer equivalent were hijacked more quietly: the maintainer's email domain had expired, so the attacker registered it and requested a password reset.
The release that isn't the repo. The xz-utils backdoor (CVE-2024-3094, disclosed March 29, 2024) is the one to study. Over roughly two years, the persona "Jia Tan" earned commit rights to xz — a library in sshd's dependency chain on most Linux distros — then shipped versions 5.6.0 and 5.6.1 with the payload hidden in binary "test files" and an extraction script present only in the release tarballs, not in git. At build time it hooked RSA_public_decrypt via an IFUNC resolver and gave the attacker a remote key into OpenSSH. It was caught because Andres Freund benchmarked an unexplained 500ms lag in ssh logins. If your assurance model is "I can read the git history," xz is the counterexample: the artifact you install is not the artifact you reviewed.
The upstream build. SolarWinds Orion (December 2020): the build system itself was compromised, so ~18,000 organizations received a signed malicious update — the signature verified perfectly because the attacker never touched the binaries downstream of signing.
What actually helps, in order of leverage
Pin and verify what you install. npm ci (not npm install) installs exactly the lockfile — package-lock.json records SHA-512 integrity hashes; pip install --require-hashes does the same job in Python. Then you are diffing one file on every upgrade, which is where a buried dependency swap shows up.
Constrain lifecycle scripts. npm install --ignore-scripts kills install-time code execution. It will break native builds like esbuild/sharp — carve a short allowlist deliberately, per package, not globally.
Check provenance. npm publish --provenance (GA since April 2023) and sigstore/cosign let you verify which build produced an artifact, not just that a signature exists. Scorecard via OpenSSF and deps.dev give you maintainer-health data — commit cadence, two-factor, number of maintainers — before you adopt a package.
Vet on the way in, diff on the way up. A new dependency is a supply-chain commitment; the lockfile diff on an upgrade is the cheapest code review in your stack. npm audit catches known CVEs and is worth running, but it is a known-vuln check — it says nothing about a freshly backdoored release.
Try this
In a real project, npm ci --ignore-scripts, note what breaks, and write down the minimal script allowlist. Then npm audit signatures (verifies registry signatures) and pull deps.dev on your three least-known transitive deps — check maintainer count and publish recency. In Java land, diff a dependency upgrade's JAR contents before shipping it.
Field notes
- Lockfiles only protect what they record — a
npm installthat regenerates them on every build discards the guarantee. Freeze the lockfile in CI. - Vendoring critical dependencies moves the problem, not removes it: you now own the update cadence, and a vendored copy nobody updates is a future CVE with your name on it.
- Every runtime plugin or theme ecosystem is a supply chain too — the fractureiser incident (June 2023) spread through Minecraft mod/plugin repositories and stole session tokens off infected hosts. The pattern doesn't care what ecosystem you live in.
Was this lesson helpful?
Keep reading
Related articles from the SudoSecurity blog.
LAPSUS$: How Teenagers Breached Microsoft and Okta
Claire Tills, senior research engineer at Tenable, describes the methods of the hacking group Lapsus$ as bold, illogical and poorly thought out. The criminals attacked renowned companies such as Microsoft, Samsung, Nvidia, Vodafone, Ubisoft and Okta. They stole data and sometimes used ransomware…
A Fake GTA 6 ISO Didn’t Install a Game. It Installed a Wiper.
A fake GTA 6 ISO used a believable installer error to cover remote-access malware, browser-data theft, and destructive file wiping. The “License not found” message wasn’t the crack failing. It was there so the victim would stop looking.
Hacktivism, 2021 to Today: From Steel Mills to Power Grids
Part 1 ended on a 70-gigabyte breach in 2021. Since then, hacktivists derailed trains, dumped molten steel on camera, and reached grids in three countries.
What is Social Engineering? The Attacks That Bypass Every Technical Control
Phishing, vishing, pretexting, physical infiltration — here's how every technique works, how attackers use them in production breaches, and how to actually defend against them.