---
title: "Dependency confusion"
description: "Dependency confusion is an attack where a build installs a malicious public package instead of an internal package with the same name. It works…"
canonical_url: "https://cloudsmith.com/resources/glossary/dependency-confusion"
last_updated: "2026-10-16T14:52:13Z"
---
# Dependency confusion

## What Is Dependency Confusion?

Dependency confusion is an attack where a build installs a malicious public package instead of an internal package with the same name. It works because many package managers search public and private sources together and may prefer the public copy, often because it carries a higher version number.

## How Dependency Confusion Works

The attack follows a predictable path:

1. The attacker finds internal package names in leaked manifests or build files
2. They publish a package with the same name to a public registry
3. They give it a very high version number
4. The build tool resolves the public package as the newest match
5. Install scripts run on a developer machine or CI runner

No one has to be tricked into a mistake. The build tool makes the choice on its own.

## Why Dependency Confusion Matters

Build environments often hold credentials, signing keys and access to production systems. Code that runs during an install can reach all of them. Internal package names are also easier to discover than many teams expect.

## How to Reduce Dependency Confusion Risk

Teams usually combine several controls:

- Use scoped or namespaced package names
- Resolve all installs through one registry that decides which source wins
- Pin versions and use lock files with integrity hashes
- Reserve internal names on public registries

Controlling where each name can resolve from is the most reliable fix.

## Final Thought

Dependency confusion exploits trust in name resolution. Defining which sources are trusted for which names closes the gap.

## Frequently asked questions

### Who discovered dependency confusion?

Security researcher Alex Birsan publicized the technique in 2021, after using it to reach the build systems of several large companies.

### Which package managers are affected?

Any ecosystem that can resolve from both public and private sources can be affected, including npm, PyPI, RubyGems, Maven and NuGet. Exposure depends on how each client is configured.

### Is dependency confusion the same as typosquatting?

No. Typosquatting relies on a human mistyping a name, while dependency confusion relies on the build tool choosing the wrong source for a correct name.

### Do lock files prevent dependency confusion?

They help, because they fix versions and hashes. They do not protect the first resolution or any update that regenerates the lock file.

### Can private packages be attacked if they were never published publicly?

Yes. An attacker only needs to know the name, and then publishes a package under it on a public registry.
