Understanding Supply Chain Attacks
You'll learn how malicious actors can compromise your application by injecting harmful code into the dependencies you trust.
What Are Supply Chain Attacks?
A supply chain attack in web development occurs when an attacker compromises a third-party dependency—npm packages, CDN-hosted libraries, or even build tools—to inject malicious code into your application. Rather than attacking your code directly, they poison the source you depend on.
Think of it like buying ingredients from a trusted grocery store. You don't inspect every can of tomatoes because you trust the supplier. But if someone tampered with the products at the warehouse, your meal becomes compromised through no fault of your own.
How They Work
When you install dependencies with npm install or load scripts from CDNs, you're trusting that code is safe. Attackers exploit this trust by:
- Compromising maintainer accounts to publish malicious updates
- Typosquatting with packages named similar to popular libraries
- Injecting code into legitimate packages through pull requests or stolen credentials
Once installed, malicious code can steal environment variables, capture user tokens, exfiltrate data, or inject XSS payloads.
Real-World Examples
The event-stream incident (2018) saw a popular npm package with millions of downloads compromised. The attacker added code to steal cryptocurrency wallet credentials. The UA-Parser.js attack (2021) injected cryptominers and password stealers into a package downloaded 7+ million times weekly.
These weren't theoretical risks—they affected countless production applications before being discovered.
Why This Matters After Learning SRI
While Subresource Integrity (SRI) protects against tampered CDN resources, it can't protect against malicious code in npm packages you've already installed and bundled into your application.
Key Takeaway: Supply chain attacks exploit the trust relationship between your application and its dependencies, making every third-party package a potential security risk that requires vigilant monitoring and verification.