flawopen.com/Reference/Dependency Confusion

Dependency Confusion & Namespace Hijacking

High Severity CWE-1395 Supply Chain & Runtime
ELI5 — The Fake Brand in the Public Supermarket

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.

Target: npm, PyPI, RubyGems, internal enterprise package builds
Vector: Registering internal package names on public registries with high semantic versions
Impact: Arbitrary command execution during package installation via preinstall hooks
Remediation: Scoped namespaces (@company/package), reservation of internal names on public registries

The Mechanism & Root Cause

Package 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.

package.json (Vulnerable Unscoped)Vulnerable
// 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.
  }
}
package.json & .npmrc (Hardened Scoped)Hardened
// 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}

The Attack & Exploit Sequence

Defensive Engineering & Prevention Rules

Explore related security topics and post-mortems: Complete Security Directory →