Early-2021 security research showed this technique working against more than 35 large technology companies. No internal network access, no credentials, no social engineering. The researcher uploaded public packages carrying the same names as internal ones, gave them higher version numbers, and waited. Package managers did the rest.
That is dependency confusion. Nothing about it is sophisticated. Its power comes from an assumption built into name resolution across internal and public registries, an assumption that stops being true the moment private package feeds enter the picture.
The core mechanism
Given a dependency name, a build system consults its configured registries in a set order. Many common setups query both internal and public sources and take the highest version found. An internal package at 1.2.3 loses to a public package at 9.0.0 that happens to share the name.
Your internal registry stays untouched. The attacker only needs one internal package name, and those leak constantly: published artifacts, error logs, CI output, public build scripts on GitHub. Minutes of searching, not days of reconnaissance.
When the malicious package installs, lifecycle hooks it declares run with the installer's own permissions. A postinstall script can read environment variables, reach mounted filesystems, call out over the network, and write anywhere the build user can. A scan step later in the pipeline is too late; the hook already ran.
Where package managers get it wrong
Version precedence was designed for a world with one source of packages. Add a second registry and that logic becomes an opening. npm's scoped packages, the ones starting with @orgname/, resist it because scoped names resolve only from the registry they belong to. Unscoped internal packages carry the risk.
PyPI presents similar exposure for internal packages served from a private index. With pip pointed at both a private index and PyPI, and no PyPI entry for the private name, an attacker can claim that name publicly. Poetry and pipenv inherit the risk wherever their source order allows it.
Go modules stand a little further back, since the module path carries a domain, which makes squatting harder. Maven has a variant through mirror configuration. Mechanics differ by ecosystem; the structural fault is the same. A name by itself stops being a unique identifier once several sources are involved.
What an attack looks like in practice
Take a fintech backend team with an internal utility called data-transform-core, used to normalize financial records before database writes. It has sat on an internal npm registry at 2.1.0 for two years. Nobody asked whether the name exists publicly, because the package has no business being public.
An attacker scans the company's GitHub org and finds the name in a Dockerfile someone left public. They publish [email protected] to npm with a postinstall script that reads environment variables and posts them to an external endpoint. The next developer or CI runner installing dependencies picks 99.0.0 from the public registry.
The payload runs at install, ahead of any test or scan step. By the time a security team reviews the manifest, exfiltration has finished. The build may even pass, since 99.0.0 ships a compatible API surface next to the malicious code.
Detection signals that matter
Catching this at the source beats catching it after install. The point is to spot the attack before the postinstall hook runs, which means examining packages before fetching them rather than scanning what already sits on disk.
Three signals mark a dependency-confusion candidate. A name on the public registry that also appears in internal manifests. A sudden version jump on the public registry for a name that was dormant or absent. Install hooks (postinstall, preinstall) in a package whose only job is to export library code; libraries rarely need them.
HuntedIabs runs cross-registry name collision detection as part of every dependency graph scan. When a resolution would pull a public package whose name also exists on a configured private feed, the public package's contents, version history, and lifecycle scripts get inspected. That happens before installation, not afterward.
Configuration defenses
Scoping is the durable fix
On npm, the lasting fix is moving internal packages under your organization's scope. A package published as @yourorg/data-transform-core cannot be confused with a public one, because the scope is a namespace your npm organization controls. Renaming packages and chasing every reference costs real effort up front; after that the attack surface for those names is gone for good.
Registry priority settings
Package managers with registry priority options let you confine internal names to the internal registry. npm does it with scoped registry entries in .npmrc; pip does it through index URL priority in pip.conf. Keeping those files correct on every developer laptop, CI runner, and Docker base image is the hard part. One misconfigured runner puts the hole back.
Proxy registries that front both internal and public feeds and enforce namespace rules centrally hold up better than config pushed to every client. They only work, though, if the proxy applies collision rules correctly and keeps up with registry changes.
What registry hardening leaves open
Tight registry configuration blocks dependency confusion and nothing more. That is not a claim about supply-chain security as a whole; it is one well-understood vector, behind real incidents, that costs little to close once the mechanism is clear.
It will not stop a legitimate public package from being compromised after you added it. It will not stop typosquatting, where the attacker registers a name similar rather than identical to yours. It will not stop a maintainer slipping malicious code into a routine update.
Each of those needs its own detection approach. For the larger picture of hidden exposure, the article on understanding transitive dependency risks covers attack surface buried in dependency graphs. For spotting packages published with hostile intent, see detecting malicious npm packages before they reach CI.
Dependency confusion makes a good starting point: the fix is concrete and the attack is documented. Stopping there would be a mistake.