1 How Dependency Confusion Attacks Work
Dependency confusion (also called namespace confusion) exploits how package managers resolve packages when both public and private registries are configured.
The attack scenario:
- Company uses an internal npm package:
@company/utils(private, version 1.0.0) - Attacker discovers the internal package name (from job listings, error messages, leaked configs)
- Attacker publishes
@company/utilsto the public npm registry at version 9.0.0 - When developers run
npm install, npm checks the public registry first - Version 9.0.0 > 1.0.0, so npm installs the ATTACKER'S version!
This vulnerability was demonstrated by Alex Birsan in 2021, who successfully compromised internal packages at Apple, Microsoft, PayPal, Tesla, and 30+ other companies.
Discovery methods:
- package.json files in public repos or CDN bundles
- Error messages revealing internal package names
- Job postings mentioning internal tool names