Skip to content

Lesson 3 of 14 · 14m

Dependency Confusion: The Registry Outranks You

Resolvers pick the highest version across every configured index, so an unpublished internal name is a public landing zone.

When two indexes know the same name, the higher version wins

Your company publishes acme-payments to its private Artifactory at version 1.4.0. Your CI installs it with pip install --extra-index-url https://pypi.org/simple acme-payments. Here is what pip does with that flag: it queries both indexes, treats them as equally trustworthy sources for the same name, and installs the best matching version. Best means highest. An attacker who publishes acme-payments@9999.0.0 to public PyPI — an empty name they had every right to claim, because you never did — wins resolution on the next install. Your internal package is shadowed by a public package you don't control, and pip helped.

Alex Birsan demonstrated this at scale in February 2021. The reconnaissance was embarrassingly public: package.json files on npm routinely list internal-only dependency names (a public package's devDependency on a company's private lib leaks the name outright), and the same names surface in config files, Stack Overflow posts, and leaked source. Birsan registered them on npm, PyPI, and RubyGems with absurd version numbers like 9000.0.0. Corporate build machines at Apple, Microsoft, PayPal, Shopify, Netflix, Tesla, Yelp, and Uber pulled his packages and ran the install scripts, which phoned home the hostname, username, and current directory — enough to prove the compromise without touching anything else. The bug bounty total exceeded $130,000. Microsoft's own internal .NET packages were among the confused.

The wrong model: "we pinned the version"

The first instinct is acme-payments==1.4.0. That narrows the window but doesn't close the door: any unpinned transitive install, any pip install acme-payments typed by hand, any tool that resolves fresh still takes the highest version across both indexes. And even pinned installs get dangerous the moment you update — someone has to bump the pin, and the bump resolves against every configured index again.

The deeper wrong model is believing an index has loyalty. Pip has no "private index first" concept. --index-url replaces the default index; --extra-index-url adds a second, coequal source. npm is the same: registry= in .npmrc sets a default, not an exclusive. Unless the resolver is told "this name only lives here," every configured registry gets a vote.

npm scopes give you the cleanest fix — @acme/payments can only come from the acme account, and .npmrc can bind the scope:

@acme:registry=https://artifactory.acme.example/npm/

Now the name can't be confused even if someone registers acme-payments publicly, because your resolver never asks public npm about the @acme scope at all. PyPI has no scoping — flat namespace, which is why the confusion attack cuts deeper there and why PyPI proxies matter more.

What to actually do

Microsoft's February 2021 whitepaper on the attack reduces to three practices, and they're still the right ones:

  • Single feed. Route every install through one authenticated private registry (Artifactory, Nexus, devpi, CodeArtifact) that pulls through from public registries as a cache. Clients never see pypi.org or npmjs.org directly — --index-url points at yours, and there is no --extra-index-url.
  • Owned-name rules. The proxy must refuse to serve public upstream packages for names you own. Artifactory and Nexus both support exclusion patterns; reserve acme-* as internal-only at the proxy layer.
  • Claim the names. Register your internal package names publicly anyway, so the slot isn't empty for an attacker to take.

The December 2022 torchtriton incident is the same bug with better branding: PyTorch's nightly builds depended on a torchtriton wheel served from a private index, nobody had claimed it on PyPI, and the attacker who did shipped a package that exfiltrated /etc/hosts, ~/.gitconfig, and SSH keys. Nightly users worldwide installed it.

The registry doesn't know which packages are "yours." You have to tell it — at the resolver, the proxy, and the public namespace.

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.