Dependency Confusion

Dependency confusion occurs when a build resolves a package name to an attacker-controlled package instead of the intended internal one. The pip install documentation warns that an extra index does not give private packages priority over identically named public candidates.

Nothing is broken in that scenario. The resolver does what it is documented to do, the registry accepts a package under an unclaimed name, and the build installs the best match it found.

When a public candidate can win

The attacker needs a name they can publish, a route through which the resolver can see it, and a candidate that the selection rules accept. Those conditions depend on the ecosystem and configuration.

In pip, configured locations are considered without index priority. A high public version can win only if it satisfies the version requirement and applicable Python and platform constraints, and is not rejected by artifact checks. For example, internal-util>=1,<2 excludes 9.9.9. A pin alone may still admit a different distribution with the same name and version; approved hashes restrict the allowed files.

Selection and execution are separate steps. Building a selected source distribution can execute its backend and hooks on the build agent. Normal wheel installation does not use that source-build path, though malicious code in a wheel can run when the application imports it or invokes an entry point. The credentials exposed depend on where that execution happens.

How internal names leak

Teams often treat internal package names as though they were secret, and they are not. Four routes are routine: lock files and manifests committed to a repository that later becomes public or is forked; build logs attached to an issue or pasted into a support ticket; container images that ship the manifest along with the application; and error messages in a public bug report that include a module path. Any one of them is enough, which is why nobody knows our package names is not a control.

What actually prevents it

MeasureWhat it removesWhat it leaves
A proxy with enforced package-origin rulesPublic substitution for protected internal names when upstream fallback is blocked or names are bound to approved originsNew names, policy changes, permitted upstream packages, and direct bypass routes still need control; a single endpoint alone is insufficient
Reserving the internal namespace publicly, or using a scope or prefix that is registeredThe attacker’s ability to publish under your nameNames created later, and ecosystems where prefixes are not enforced
Version or artifact pins plus approved hashes, enforced during installationFiles outside the approved setInitial approval and deliberate upgrades can still accept malicious content
Restricting what the build may reach on the networkFetches from anywhere except the approved indexEverything that comes through the approved index, and the maintenance of the destination list

The pip Secure installs guidance requires all requirements, including dependencies, to be pinned and hashed in hash-checking mode. Enforce it explicitly with --require-hashes and maintain the accepted hashes through review. A checksum supplied by the same index as the file does not independently establish that the file was approved. The dependency lock file records the selected inputs; installation must actually enforce that record.

Checking your own case

Inspect reachable indexes and the proxyโ€™s upstream policy separately. For an internal name, test which origin wins, whether public fallback is blocked, and whether the build can bypass the proxy. Protect newly created names as well as existing ones. AWS CodeArtifactโ€™s origin controls illustrate why permitting upstream ingestion is a policy decision distinct from using one endpoint. Reservation helps only where the registry actually enforces that namespace.

When a source-build hook executes on a build agent, its exposure includes the credentials and network access available there. A payload executed later by the application has that runtimeโ€™s authority instead. A software bill of materials helps inventory observed components, but is not itself a control over execution or origin.

How this fits with code review, image identity, provenance, and pipeline permissions is worked through in The Pipeline Had the Keys.

References (pip illustrates one resolver; other ecosystems differ):


Discover more from Insightful Data Lab

Subscribe to get the latest posts sent to your email.

Similar Posts

Questions, corrections, or additional insights?

This site uses Akismet to reduce spam. Learn how your comment data is processed.