Running npm install or pip install is a routine part of a developer’s week when working on a project. However, these commands can also create opportunities for attackers to get malicious code into a software supply chain. An example is dependency confusion, and companies are still being targeted.
Earlier this year, Microsoft found 33 malicious npm packages impersonating internal corporate packages across nine organizational scopes, and its analysis said they were built to profile developer environments.

Organizations often use a mix of public and private packages in their projects, and dependency confusion exploits how they manage these packages.
Essentially, it’s a software supply chain attack in which an attacker publishes a public package with the same name as an organization’s private package. The public copy usually has a higher version number, so a misconfigured package manager may install it instead of the internal one.
Security researcher Alex Birsan named the attack in February 2021. His research found that publishing public packages with the same names as companies’ internal packages was “a nearly sure-fire method” for getting into the networks of large tech companies.
Dependency confusion can target public registries such as npm, PyPI, RubyGems, and NuGet, and is also known as a substitution attack or, in some cloud documentation, “dependency substitution.”
The issue is in how package managers decide which registry to use. If a package with the same name is available publicly and privately, they can end up choosing the public one. It’s a problem with package resolution and configuration, not a vulnerability in the library itself.
In many cases, malicious code can run during installation, even if the package is never imported or included in a production release.
In npm, scripts such as preinstall, install, and postinstall can run automatically. However, since npm 12, dependency install scripts won’t run unless they’re approved.
The impact of a dependency confusion attack depends on where the package is installed:
CI/CD servers hold secrets and deploy tokens, and they usually have network access to internal systems.
Developer workstations store SSH keys and cloud credentials, along with Git configuration and environment variables.
If malicious code runs on either, attackers can steal credentials that give them access to other projects and cloud accounts.
A good example is when PyTorch nightly builds installed a malicious torchtriton package from PyPI instead of the intended package from PyTorch’s own repository. In this case, the malicious code ran when the package was imported.
The following are ways an attacker can use dependency confusion to get a malicious package installed:
Discover internal package names: Attackers look for private package names in public JavaScript files and public GitHub repositories, as well as in leaked package.json files.
Register the same name publicly: Publish a package with the same name on npm, PyPI, or RubyGems. For npm scoped packages, this could involve using a matching scope that the attacker controls.
Inflate the version number: The package is given a much higher version, such as 99.99.99 or 100.100.100, which the package manager could select over the internal package if the version requirement allows it.
Take advantage of package source configuration: A misconfigured package manager or proxy may select the public package instead of the internal one when resolving dependencies.
Execute on install: If install-time scripts are allowed to run, malicious code can send host information and secrets to an attacker. Birsan’s test packages, for example, reported back over DNS.
Python’s package manager, pip, chooses the newest version that meets a requirement, but it doesn’t automatically distinguish between trusted and untrusted package sources.
The pip documentation explains that there is no priority between the locations it searches. If the same package is available from public and private indexes, pip may select the public version if it has a higher version number.
An option is to use a single internal package index that hosts private packages and provides access to approved packages from public registries. Then pip only needs to check one source when installing dependencies.
Hashes in requirements files provide another way to check that downloaded packages match the expected files. However, this doesn’t guarantee a package is safe, because a malicious package can still pass the check if its hash is already listed.
The same issue can affect NuGet, the package manager for .NET. If a package is available from more than one source, NuGet may not always use the source you expect.
NuGet’s Package Source Mapping feature (available in NuGet 6.0 and later) helps prevent this by associating specific package names or patterns with particular sources. Organizations can use it to make sure internal packages come from their private feed, while other packages come from nuget.org.
Some organizations use registry proxies to manage access to public and private packages. These proxies retrieve packages from configured sources and can combine public and private feeds into one.
The problem is when both sources offer the same package. Depending on how the proxy and package manager are configured, the package manager could select the public version, especially if it has a higher version number.
Recent npm campaigns show how attackers use inflated version numbers to get their packages installed. Sonatype reported packages published with version number 99.99.99, while Microsoft found that attackers used version 100.100.100 to make their packages take precedence over internal versions.
npm lets organizations publish packages under a shared name called a scope. For example, @yourcompany/utils uses the @yourcompany scope. The organization needs to create an npm organization with that name first; otherwise, someone else could claim it and publish packages under that scope.
To protect against this, a committed .npmrc file can tell npm to retrieve scoped packages from the internal registry. The organization should also register its scope on npmjs.com, so no one else can claim it.
An attacker doesn’t need access to the target network to carry out this attack, as finding an internal package name and registering it on a public registry may be enough. If a build picks up the public package, the attacker can get their code into the environment.
There are different methods attackers use to get malicious packages into software projects. Dependency confusion is one, but other techniques exist.
| Attack | What the attacker relies on | Example |
| Dependency confusion | A public package with the same name as a private one, plus a setup that allows the public version to be installed | Microsoft-tracked npm packages published at version 100.100.100
|
| Typosquatting | A developer mistyping a popular public package name |
reactt instead of react
|
| Dependency hijacking | An attacker taking over a package maintainer’s account and publishing a malicious update | A malicious new release of a legitimate library |
| AI-hallucinated package names (“slopsquatting”) | An AI assistant suggesting a package that doesn’t exist, which an attacker then publishes | A nonexistent package suggested in generated Python or JavaScript code |
Typosquatting and hallucinated names depend on a person or model choosing the wrong name, but dependency confusion doesn’t need a developer typo. The name is correct, and the source is wrong.
AI coding assistants add a related risk by sometimes suggesting packages that don’t exist, and if an attacker registers one of those names, a developer who installs the suggestion ends up with the attacker’s package.
A 2025 USENIX Security study found that commercial AI models suggested nonexistent packages in around 5% of recommendations, compared with around 22% for open-source models.
The risk varies depending on which package manager or registry an organization uses. Here’s a look at the potential issues and the safeguards available for each.
| Package manager or registry tool | Potential risk | General safeguard |
| pip | Public and private indexes contain packages with the same name, and pip may select the higher-versioned one. | Use a controlled package index for approved dependencies. |
| npm | Public packages can use the same names as unscoped internal packages. | Use scoped names and configure them to resolve through the private registry. |
| NuGet | Packages can be available from multiple sources, making it unclear which source NuGet will use. | Use Package Source Mapping to associate packages with specific sources. |
| Azure Artifacts | Multiple upstream sources can affect which package is returned. | Configure upstream sources carefully. |
| AWS CodeArtifact | Packages can be retrieved from public upstream sources when internal versions are also available. | Configure package origin controls to restrict upstream sources. |
| JFrog Artifactory | Virtual repositories can combine packages from public and private sources. | Configure repository priority to favor internal packages. |
There are ways to reduce the risk of dependency confusion, starting with controlling which package sources developers and build systems can access. However, no configuration can guarantee protection against every attack.
The OWASP Top 10 CI/CD Security Risks also covers dependency chain abuse and recommends monitoring for attacks that get past preventive controls.
Several practices can lower the risk for teams:
Control package sources: Make sure installations use trusted registries or proxies, with clear rules for where internal packages can be downloaded from.
Keep internal package names private: Where possible, register internal package names and scopes on public registries before attackers can claim them. Publishing placeholder packages is one way to do this, as PyTorch did.
Keep dependencies under control: Pin package versions and commit lockfiles so installations use the expected versions. Also, use hashes to check that downloaded packages haven’t changed.
Limit install-time scripts: Turn off installation scripts where possible; for example, npm supports the --ignore-scripts option. Builds should also run without access to sensitive credentials.
Check package origins: Look for dependencies from unexpected sources or with unusually high version numbers. Use checksums and digital signatures where supported.
Keep internal package names out of public repositories: Don’t include them in public code or published bundles, where attackers could find and reuse them.
If a malicious package gets through the initial controls, teams need to be able to identify it. They can do this by:
Monitoring public registries for packages that use internal package names or scopes.
Checking for dependencies from unexpected sources or with unusually high version numbers.
Monitoring outbound network traffic from build agents and blocking connections to destinations they don’t need to access.
Changing credentials if a build environment installs a package suspected of being malicious.
Developers should also configure dependencies securely with the package managers and tools they use, so they better understand what to look for and how to respond when they notice something unusual.
Start by making a list of internal package names from project manifests and private registries. Search for those names on the corresponding public registries. If an internal name is already registered by someone else, investigate whether the package could be selected during installation. Names that haven’t been registered publicly could still be claimed by an attacker.
Another useful place to look is in build logs to check whether internal packages are being downloaded from public registries or whether their versions are higher than the latest internal release. Either could indicate that the package manager is pulling dependencies from the wrong source and needs to be reconfigured.
It’s a good idea to use threat modeling during the design stage to identify potential dependency risks and how dependencies enter a project, including where public and private package sources could be mixed up.
Once risks are found, developers can fix them directly in the project, for example, by making sure internal package names are only resolved from the private registry.

The SecureFlag training platform gives developers hands-on practice in real development environments with the same tools they use at work, across more than 75 technologies, including DevOps and cloud. The training also includes labs on dependency confusion and other software supply chain attacks.
SecureFlag also supports secure design through ThreatCanvas, its automated threat modeling solution that helps teams identify risks in their architecture, including how they manage external dependencies and package sources.
In terms of AI-assisted development, the platform also includes labs for the OWASP Top 10 for LLMs, agentic AI, MCP, and RAG, as well as Agentic Coding Labs.
Teams can also use analytics and reporting dashboards to see how their developers are doing with secure coding.
Book a demo to see SecureFlag in action.
Yes. Attackers published npm packages at versions like 100.100.100 in 2026, so any team mixing public and private sources should audit its configuration now.
It helps once versions and hashes are locked. It won’t protect a project when someone adds a new dependency or regenerates the lockfile against misconfigured sources.
Dependency confusion copies a private package name exactly. Typosquatting relies on developers misspelling a popular public package name.
Any client or proxy that consults public and private sources for the same name can be affected, including npm, pip, RubyGems, NuGet, and registry proxies. Configuration, not the tool itself, determines the risk.
They can suggest nonexistent packages that attackers then register. Researchers describe this as a related package confusion risk rather than classic dependency confusion.