Package Hijacking
Prerequisites
- Compromised npm maintainer credentials via phishing, credential stuffing, or token leakage
- Target package must have a significant number of downstream dependents to maximize blast radius
Attack Scenarios
Account Takeover and Trojanized Publish
An attacker compromises a maintainer's npm account and publishes a new patch version of a popular package containing a malicious dependency. Since most consumers use semver ranges like ^x.y.z, the malicious patch is automatically installed on the next npm install. In the March 2026 Axios attack, the attacker compromised the account of a primary maintainer (jasonsaayman), changed its registered email, and published two backdoored versions within a 39-minute window.
npm login --auth-type=legacy
# Using compromised credentials
npm publish
{
"name": "axios",
"version": "1.14.1",
"dependencies": {
"plain-crypto-js": "4.2.1"
}
}
{
"name": "plain-crypto-js",
"version": "4.2.1",
"scripts": {
"postinstall": "node scripts/postinstall.js"
}
}
// The postinstall script downloads and executes a platform-specific
// remote access trojan (RAT) for macOS, Windows, or Linux
Transitive Dependency Amplification
A package deep in the dependency tree is compromised. Because it is a transitive dependency of many popular frameworks, the malicious code reaches thousands of projects that never directly depend on the hijacked package and may not even be aware it exists in their dependency tree.
# Check a package's dependencies
npm view <package-name> --json | jq '.dependencies'
# To find who depends on a package, check:
# https://www.npmjs.com/browse/depended/<package-name>
# Or use npm.anvaka.com to visualize the dependency graph
Detection
Monitor for Unexpected Version Bumps
Set up alerts for new versions of your critical dependencies. Compare published versions against the project's GitHub releases or changelog to detect unauthorized publishes.
npm view axios versions --json | jq '.[-5:]'Lockfile Integrity Verification
Use npm ci instead of npm install to enforce the exact versions and integrity hashes recorded in package-lock.json. Any tampering with the published tarball will cause a checksum mismatch and fail the install.
npm ciRun npm audit Regularly
npm audit checks your dependency tree against the GitHub Advisory Database for known vulnerabilities and compromised packages.
npm audit --audit-level=moderateMitigation
- Enable two-factor authentication (2FA) on all npm maintainer accounts, especially for packages with large install bases
- Use npm ci in CI/CD pipelines to enforce lockfile integrity and detect unexpected changes
- Pin exact dependency versions and review all version bumps before merging
- Monitor npm advisory feeds and subscribe to security notifications for critical dependencies
- Use npm provenance attestations to verify that published packages were built from the expected source repository
References
- Supply Chain Attack on Axios npm Package - Socket.dev
- Mitigating the Axios npm Supply Chain Compromise - Microsoft Security Blog
- Inside the Axios Supply Chain Compromise - Elastic Security Labs
- npm Two-Factor Authentication Documentation
- npm Provenance Attestations
- ua-parser-js Hijacking Incident (2021)