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
| Measure | What it removes | What it leaves |
|---|---|---|
| A proxy with enforced package-origin rules | Public substitution for protected internal names when upstream fallback is blocked or names are bound to approved origins | New 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 registered | The attacker’s ability to publish under your name | Names created later, and ecosystems where prefixes are not enforced |
| Version or artifact pins plus approved hashes, enforced during installation | Files outside the approved set | Initial approval and deliberate upgrades can still accept malicious content |
| Restricting what the build may reach on the network | Fetches from anywhere except the approved index | Everything 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):
- pip documentation, pip install โ the dependency confusion warning and the description of how locations are searched and matches selected.
- pip documentation, Secure installs โ hash-checking mode, why hashes are required for every requirement, and the limits of hashes obtained from an index.
- AWS CodeArtifact, Package origin controls
- pip documentation, Build System Interface
- Python Packaging, Binary distribution format
Discover more from Insightful Data Lab
Subscribe to get the latest posts sent to your email.
