Public vs Private Package Repository Resolution
What You'll Learn
You'll learn how package managers decide which repository to fetch a package from when you have both public (like npm, PyPI) and private (internal company) repositories configured — and why that choice is a critical security decision.
The Repository Resolution Problem
When you run npm install mypackage or pip install mypackage, your package manager must decide where to look. Most organizations use:
- Public repositories: npm, PyPI, Maven Central, RubyGems — the internet's package libraries
- Private repositories: Internal company registries for proprietary code (e.g.,
@mycompany/auth-lib)
The danger arises because package managers follow resolution rules that determine search order. If misconfigured, they might check the public registry before your private one, or check both and pick based on version numbers.
The Critical Risk
Imagine your company has a private package called auth-utils. If your package manager checks the public npm registry first (or at all) for this name, an attacker could:
- Upload a malicious
auth-utilspackage to public npm - Give it a higher version number (e.g., 999.0.0)
- Wait for your build system to fetch it
This is the dependency confusion attack in action, enabled by poor repository resolution configuration.
Why This Happens
Default package manager configurations often:
- Search public registries as a fallback
- Prefer higher version numbers regardless of source
- Lack namespace restrictions (any name can exist in both places)
Organizations must explicitly configure scoped packages (like @mycompany/*) to only resolve from private registries, never falling back to public sources.
Key Takeaway: Package managers' repository resolution order and fallback behavior determine whether attackers can inject malicious packages by exploiting the boundary between your private and public dependencies — proper scoping and registry configuration is essential defense.