Configuring Package Manager Security Settings
What you'll learn: How to lock down your package manager to prevent dependency confusion and typosquatting attacks through proper registry configuration.
Now that you understand how dependency confusion and typosquatting attacks work, it's time to configure your package manager to defend against them. Think of this as setting up strict border controls: you're explicitly declaring which sources you trust and blocking unauthorized package sources.
Setting Explicit Registry Sources
Package managers often default to public registries (like npmjs.com or PyPI), but you should explicitly configure trusted sources. This removes ambiguity about where packages come from.
For npm, this means configuring .npmrc:
registry=https://your-private-registry.company.com/
@yourscope:registry=https://your-private-registry.company.com/
For pip, use pip.conf or pip.ini:
[global]
index-url = https://your-private-pypi.company.com/simple
Disabling Public Registry Fallbacks
This is critical: if your private package isn't found, the package manager should fail, not fall back to the public registry. That fallback is what enables dependency confusion attacks.
In npm, you can prevent fallback by ensuring all scoped packages use your private registry exclusively. In pip, avoid using --extra-index-url, which creates a dangerous fallback chain.
Configuring Authentication Properly
Your private registry should require authentication. Store credentials securely—never in version control. Use environment variables or credential managers:
//your-private-registry.company.com/:_authToken=${NPM_TOKEN}
Key Takeaway: Explicitly configure trusted package registries, disable public registry fallbacks to prevent dependency confusion, and require authentication for private sources—these settings form your first line of defense against supply chain attacks.