CWE-427OWASP A06:2021OWASP A08:2021CWE-1104

CWE-427: Dependency Confusion

Dependency confusion happens when a package manager resolves an internal package name to a malicious public package because the search path is not controlled.

Also known as: Dependency Confusion, Substitution Attack, Namespace Hijacking, Search Path Hijack

Risk

A successful dependency confusion attack runs attacker-controlled code on developer machines, CI runners, and production builds, often with full build privileges. It has been used to breach major technology companies and can lead to source theft, credential exfiltration, and supply chain compromise.

Definition

What it is

Package managers like npm, pip, and others resolve a dependency name by searching configured registries, and by default a public registry is often consulted alongside or instead of a private one. If an internal package name is published to the public registry by an attacker with a higher version number, the tool may pull the attacker's package instead of yours. This is an uncontrolled search path: the resolver trusts name and version without verifying origin. The fix is to control where each name is allowed to resolve from, through scopes, source pinning, and registry configuration.

Use-cases

How it shows up in real code

Internal name leaks publicly

A company uses an internal package called acme-auth-utils that exists only on its private registry. An attacker spots the name in a public source map and publishes acme-auth-utils 99.0.0 to npm, and the next CI build installs the attacker version.

Mixed registry resolution

A build is configured with both the public registry and a private one, with no scoping. When a transitive install resolves an internal utility, the higher public version wins and executes a malicious postinstall script.

Unscoped package rename

A team refactors a scoped package into an unscoped internal name to simplify imports. Because the name is no longer protected by an organization scope, an attacker claims it publicly and intercepts future installs.

Developer laptop compromise

A developer runs npm install on a feature branch that references an internal tool. The public substitute installs, exfiltrates environment variables and SSH keys, and the breach begins on the workstation before reaching CI.

AI risk

Why AI-generated code has increased the exposure

  • AI assistants often scaffold package.json and requirements files with plausible internal-sounding names that may already exist, or can be claimed, on a public registry.
  • Assistants rarely configure registry scoping or source pinning, so generated install steps resolve names from whichever registry responds with the highest version.
  • Generated CI configuration frequently lists both public and private registries without lockfile integrity enforcement, exactly the condition confusion exploits.
  • Models reproduce old setup snippets from training data where mixed registries were common, reintroducing a known attack pattern into new projects.
  • Assistants suggest renaming or publishing internal utilities without warning that an unscoped public name can be hijacked, so the risk is added silently.

Vibe coding

How vibe coding amplifies the risk

  • Vibe coders accept generated install commands that point at the public registry without checking whether internal names are protected by a scope.
  • Prototypes copy internal package names into public repos and demos, leaking the exact names an attacker needs to claim.
  • Rapid scaffolding skips registry configuration entirely, leaving the default resolution order that confusion relies on.
  • Without lockfile discipline, each reinstall can silently pick up a newly published public impostor of an internal name.
  • Prototypes graduate to production with no review of where each dependency actually resolves from.

Detection

How to find it

  • Enumerate every internal package name and check whether that exact name, scoped or unscoped, is unclaimed on public registries.
  • Inspect npmrc, pip configuration, and CI settings for mixed public and private registries without scoping or source pinning.
  • Audit lockfiles to confirm each dependency resolves to the expected registry URL and integrity hash, not a public fallback.
  • Scan build logs for install-time scripts and unexpected version jumps on internally named packages.

Remediation

How to fix it

  • Publish all internal packages under a reserved organization scope and map that scope to the private registry only.
  • Pin each dependency source explicitly so internal names can never resolve from the public registry.
  • Defensively register your internal names on public registries as placeholders so attackers cannot claim them.
  • Commit lockfiles and enforce integrity verification so a substituted package fails the install.
  • Add a CI gate that fails the build if any dependency resolves from an unexpected registry or if an internal name appears publicly.

Frequently asked questions

What is CWE-427 (dependency confusion)?
CWE-427 is an uncontrolled search path weakness where a package manager resolves a dependency name from the wrong source. In dependency confusion, an attacker publishes a public package matching your internal name at a higher version, and your build installs the malicious copy. It runs attacker code in your build pipeline.
How have AI assistants and vibe coding increased the risk?
AI tools scaffold install steps and CI config with mixed registries and internal-sounding names but rarely set up scoping, source pinning, or lockfile enforcement. Vibe coders accept these setups unread and leak internal names into public repos. The result is exactly the misconfiguration that confusion attacks target.
How do I fix dependency confusion?
Reserve an organization scope for internal packages and bind that scope to the private registry only, then pin every dependency source. Defensively register internal names publicly, commit lockfiles with integrity checks, and add a CI gate that fails on unexpected registry resolution.

Related weaknesses

Catch CWE-427 before you ship

Tethlyn Audit scans your codebase and its git history for CWE-427 and the rest of the dependency & supply chain risk class, then ranks each finding by real exploitability and data sensitivity.

See Tethlyn Audit