flawopen.com/Reference/Dependency Confusion
Imagine your family bakery has an internal secret recipe called 'GrandmaSpecialFlour'. You usually buy it from your own basement storage. But one day, someone registers 'GrandmaSpecialFlour' at the local supermarket with version number 99.0. When your delivery boy goes shopping and asks for the highest version, the supermarket sells him the poisoned bag from the public store instead of looking in your basement. In Dependency Confusion, package managers (npm, pip) download higher-versioned malicious packages from public registries instead of your private company repository.
@company/package), reservation of internal names on public registriesPackage managers like npm and pip check both public registries (npmjs.com, PyPI) and private enterprise registries (Artifactory, Nexus). If an organization uses an unscoped internal package name (e.g. corp-auth-utils), an attacker registers the identical name on the public index with a version like 99.0.0. The build tool chooses the higher public version, executing malicious install lifecycle scripts.
// VULNERABLE: Unscoped package name defaults to public npm search
{
"name": "enterprise-web-app",
"dependencies": {
"react": "^18.2.0",
"corp-billing-engine": "^1.2.0"
// Attacker registers 'corp-billing-engine' @ 99.0.0 on public npmjs.org!
// npm install will pull the attacker's public package over the internal one.
}
}
// HARDENED: Enforce organization scope tied strictly to private registry
// package.json:
{
"name": "enterprise-web-app",
"dependencies": {
"react": "^18.2.0",
"@corp/billing-engine": "^1.2.0" // Scoped package
}
}
// .npmrc:
// @corp:registry=https://nexus.corp.internal/repository/npm-private/
// //nexus.corp.internal/:_authToken=${NPM_TOKEN}
analytics-logger-internal.:analytics-logger-internal on npmjs.com with version 99.9.9.:preinstall script to package.json that reads /etc/environment and sends secrets to a webhook.:npm install, npm downloads the public package, executing the exfiltration script as root in the build agent.:@company/) and route that scope exclusively to your internal registry.npm ci rather than npm install to enforce strict SHA-512 integrity hashes from package-lock.json.--ignore-scripts in untrusted or production build environments.