| Myth | Reality |
|---|---|
| Code review will catch a malicious dependency before it ships. | Most dependency confusion payloads execute during install via build scripts, before any code review step ever sees the package. |
| Typosquatting only affects careless developers copy-pasting install commands. | Automated build pipelines and AI coding assistants have also been shown to hallucinate or mistype package names, installing the squat automatically. |
| Using a private registry fully protects internal package names. | Without explicit scope-to-registry mapping, package managers can still fall through to the public registry and select a higher-versioned public package. |
| Popular, well-known packages are the only realistic targets. | Attackers increasingly target internal-sounding names, harvested from leaked build logs, job postings, and open source configuration files. |
How These Two Supply Chain Attacks Actually Work
Dependency confusion and typosquatting are frequently mentioned in the same breath because both weaponize the trust developers place in package names, but the mechanics differ in an important way. Typosquatting relies on human error: a developer or a script mistypes a package name and installs an attacker-controlled look-alike instead. Dependency confusion relies on package manager resolution logic: it does not require anyone to make a typo at all, only that an internal package name is also claimed on a public registry with a version number the resolver prefers.
Typosquatting: Exploiting the Keyboard
A typosquatting attack registers a package name a small edit distance away from a popular package, one character swapped, transposed, added, or removed, so that a common typo installs the malicious package instead of the intended one. Classic examples that have been observed and removed from public registries include names built to catch developers reaching for “requests,” “colorama,” and “selenium,” each substituted with a subtly misspelled variant carrying a malicious payload.
The payload itself typically executes through an install-time hook, a Python setup.py script, an npm postinstall hook, that runs automatically the moment the package is installed, with no further action required from the developer. By the time anyone notices anything unusual, the payload has already run with whatever privileges the installing user or build system held.
Dependency Confusion: Exploiting Resolution Logic
Dependency confusion works differently and, in some ways, more insidiously, because it requires no typo at all. Many organizations maintain internal, private packages, often named after internal projects or services, that are never intended to be published publicly. If an attacker discovers the name of one of these internal packages, through a leaked package.json file, a public build log, or an internal name pattern posted in a job listing, they can publish a package with the identical name on a public registry such as npm or PyPI, deliberately set to a very high version number.
Because many package manager configurations check multiple registries and default to installing whichever registry returns the highest version number for a given name, the resolver can silently select the attacker’s public package over the legitimate internal one, even though the internal package is the one the organization intended to use. The build system then executes the attacker’s code with the same privileges the internal package would have held, often inside a CI/CD pipeline with access to source code, secrets, and deployment credentials.
| Attack | Trigger | Requires developer error | Primary defense layer |
|---|---|---|---|
| Typosquatting | Misspelled or visually similar package name | Yes, or an automated tool’s mistake | Install-time scanning and lockfile discipline |
| Dependency confusion | Public registry hosting a higher-versioned package matching a private name | No, resolution logic alone is sufficient | Namespace reservation and registry pinning |
Why 2024 to 2026 Made This Worse
Registry-hosted malware has grown from a novelty into a routine occurrence. PyPI maintainers have described removing hundreds of malicious typosquats per month during recent enforcement sweeps, and independent research cataloguing real package-confusion incidents in production registries has confirmed hundreds of distinct cases rather than a handful of proof-of-concept demonstrations. This is no longer a theoretical risk discussed at conferences, it is an ongoing, high-volume attack pattern that registry maintainers actively fight on a daily basis.
Two additional trends have widened the attack surface further. First, the sheer size of modern dependency trees means a single application may pull in thousands of transitive dependencies, each one a potential confusion or typosquat target that no human reviews individually. Second, AI-assisted coding tools have introduced a new failure mode: research on large language model package recommendations has found that models sometimes hallucinate plausible-sounding package names that do not exist yet, and attackers have begun preemptively registering those hallucinated names so that a developer or an autonomous coding agent that trusts the suggestion installs a malicious package by following AI-generated advice verbatim.
Where a Dependency Confusion Attack Intercepts the Build
A developer’s manifest file references an internal package name. Without an explicit scope-to-registry mapping, the package manager queries both the internal registry and the public registry, compares version numbers, and installs whichever is higher. If an attacker has published a same-named package on the public registry with an inflated version number, the build silently pulls the attacker’s code instead of the internal package, and any install-time script executes immediately inside the build environment.
Common mistake
Assuming that because an organization uses a private package registry, dependency confusion cannot happen. Most package managers are configured by default to check multiple sources and will silently fall through to the public registry unless an administrator has explicitly configured scope-to-registry mapping or blocked public resolution for internal namespaces entirely.
Concrete Defenses That Work
Namespace Reservation
The most direct fix for dependency confusion is namespace ownership: register every internal package name as a placeholder on the public registries your organization’s tooling could ever reach, even if the placeholder package contains no functional code. This denies an attacker the ability to claim the name at all. For organizations with large or frequently changing sets of internal package names, this needs to be a routine step in the internal package creation process, not a one-time cleanup exercise.
Scoped Packages and Registry Pinning
Scoped package names, an organization-specific prefix supported by npm and mirrored by conventions on other registries, prevent a public package from ever colliding with an internal name in the first place, since the scope itself is tied to a verified account. Alongside scoping, explicit registry pinning configuration, npm’s scope-to-registry mapping in .npmrc, NuGet’s package source mapping, a single configured index URL for Python tooling, forces the resolver to fetch a given namespace or package pattern from exactly one source, removing the ambiguity that dependency confusion depends on.
Lockfiles and Exact Version Pinning
A committed, reviewed lockfile that pins exact package versions and, where supported, cryptographic hashes prevents a build from silently picking up a new, higher-versioned package of any kind, confusion attack or otherwise, without a deliberate, reviewed update to the lockfile. This is one of the cheapest and most effective controls available and should be treated as non-negotiable for any production build pipeline.
Automated Typosquat Detection
Behavioral and static analysis tools that scan packages at install time, checking for suspicious install scripts, unexpected network calls, obfuscated code, and name similarity to popular packages, catch a meaningful share of both typosquats and confusion attempts before they execute. Pairing this kind of scanning with an internal proxy or registry that quarantines newly published versions for a defined cooling-off period gives the wider community time to flag a malicious package before it reaches an internal build.
| Defense | Stops typosquatting | Stops dependency confusion | Implementation effort |
|---|---|---|---|
| Namespace reservation on public registries | Partial | Yes | Low, ongoing discipline required |
| Scoped packages | No | Yes | Moderate, requires migration |
| Registry pinning / source mapping | No | Yes | Low, one-time configuration |
| Lockfiles with exact pins and hashes | Partial | Yes | Low |
| Install-time behavioral scanning | Yes | Yes | Moderate, requires tooling adoption |
| Cooling-off period / internal proxy quarantine | Yes | Partial | Moderate |
Building a Layered Defense Program
No single control listed above closes both attack paths completely, which is why an effective program layers several together. A practical rollout order for most engineering organizations looks like this:
- Audit every manifest file across the organization’s repositories to build a complete inventory of internal package names currently in use.
- Reserve those internal names on every public registry the organization’s tooling can reach, even as empty placeholder packages.
- Configure explicit scope-to-registry mapping or single-index pinning in every build environment, not just developer laptops.
- Require committed, reviewed lockfiles with hash verification on every production build pipeline.
- Deploy an install-time scanning tool or an internal proxy with a quarantine window for newly published package versions.
- Add a recurring automated sweep that checks for newly registered look-alike names against the organization’s most-used dependencies.
What worked
One engineering organization eliminated its dependency confusion exposure in a single sprint by combining two low-effort controls: reserving every internal package name on the public registries in use, and adding scope-to-registry mapping to the CI pipeline’s package manager configuration. Neither control required rewriting application code, and both were verifiable through a simple build-log audit afterward.
- Transitive dependency blind spotsConfusion and typosquat targets are often several levels deep in a dependency tree, invisible to a manifest-only review.
- Build-time versus install-time executionMalicious install scripts run before any test suite or static analysis step ever touches the code.
- AI-assisted install commandsCoding assistants can suggest hallucinated or subtly wrong package names that attackers have pre-registered.
- Internal name leakageJob postings, public build logs, and open source configuration files routinely leak internal package naming conventions.
- Registry-level enforcement lagRegistry maintainers remove malicious packages reactively, often after the package has already been downloaded thousands of times.
What Registries and Tooling Vendors Are Doing
Public registries have added structural protections over time in response to sustained abuse: npm added scope-to-registry mapping support, NuGet introduced package source mapping, and PyPI has increased automated and manual takedown enforcement of reported malicious packages. None of these registry-side improvements remove the need for organization-side controls, since a registry can only act after a malicious package is reported or detected, and the window between publication and takedown is exactly when most damage occurs.
Independent security research has also pushed the state of the art on detection. Academic work on malicious package detection has proposed models that analyze behavioral sequences common to malicious packages across both npm and PyPI simultaneously, and newer research into cryptographic registry provenance explores structural defenses intended to prevent dependency confusion at the protocol level rather than relying purely on organizational configuration discipline.
Key Takeaways
- Typosquatting relies on a misspelled or visually similar package name; dependency confusion relies on resolver logic and needs no typo at all.
- Malicious payloads typically execute at install time through build scripts, before any code review step ever runs.
- A private registry alone does not prevent dependency confusion without explicit scope-to-registry mapping or single-index pinning.
- Reserving internal package names on public registries is a low-effort, high-impact defense against dependency confusion.
- Committed lockfiles with exact version pins and hashes are one of the cheapest and most effective controls available.
- AI coding assistants can hallucinate package names that attackers have pre-registered, creating a new typosquatting vector.
- No single control fully closes both attack paths; layered defenses across naming, resolution, and install-time scanning are required.
FAQs
What is the core difference between dependency confusion and typosquatting?
Typosquatting requires a developer, script, or tool to mistype or misjudge a package name and install a malicious look-alike. Dependency confusion requires no typo at all, it exploits a package manager’s tendency to select the highest-versioned package across multiple registries, letting a public package silently override an internal one of the same name.
Why does using a private package registry not fully prevent dependency confusion?
Most package managers check multiple sources by default and will fall through to a public registry unless explicitly configured otherwise. Without scope-to-registry mapping or single-index pinning, a resolver can still select a higher-versioned public package over the intended internal one, even when a private registry hosts the legitimate package.
How do malicious packages typically execute their payload?
Most confirmed dependency confusion and typosquatting payloads execute through install-time hooks, such as an npm postinstall script or a Python setup.py routine, that run automatically the moment the package is installed. This happens before any code review, test suite, or static analysis step ever inspects the code.
What is namespace reservation and why does it help?
Namespace reservation means registering every internal package name as a placeholder on public registries the organization’s tooling can reach, even if the placeholder contains no functional code. This denies attackers the ability to claim that name for a malicious package, directly closing off the dependency confusion attack path.
Do lockfiles actually prevent these attacks?
A committed, reviewed lockfile with exact version pins and cryptographic hashes prevents a build from silently picking up a new package version without a deliberate, reviewed change. It is one of the cheapest and most effective controls against both dependency confusion and typosquatting, though it should be paired with other defenses rather than relied on alone.
Can AI coding assistants make typosquatting worse?
Yes. Research has found that large language models sometimes hallucinate plausible but nonexistent package names, and attackers have begun preemptively registering those exact names. A developer or autonomous coding agent that installs a suggested package without verification can end up installing an attacker-controlled package.
What role does an internal registry proxy play in defense?
An internal proxy that mirrors public registries can enforce a quarantine or cooling-off period before newly published package versions become available to internal builds. This gives the broader security community time to detect and report malicious packages before they reach a production build pipeline.
How common are these attacks in practice today?
They are no longer rare. Public registry maintainers have reported removing hundreds of malicious typosquat packages per month during active enforcement periods, and dedicated research studies have confirmed hundreds of real-world dependency confusion incidents across production package registries rather than isolated proof-of-concept cases.
Glossary
- Dependency confusion
- An attack where a public package with the same name and a higher version number than an internal private package is installed by mistake due to registry resolution logic.
- Typosquatting
- Registering a package name a small edit distance from a popular package to catch developers who make a typing mistake during installation.
- Scoped package
- A package name prefixed with an organization-specific namespace, tied to a verified account, that prevents naming collisions with unrelated public packages.
- Registry pinning
- Configuration that forces a package manager to resolve a given package name or scope from exactly one specified registry, removing ambiguity between sources.
- Install-time hook
- A script, such as an npm postinstall or Python setup.py routine, that a package manager executes automatically during installation, before any manual review occurs.
- Lockfile
- A file that records the exact resolved version and, optionally, cryptographic hash of every dependency in a project, preventing silent version drift.
For more on protecting the software build pipeline, see our guides on software supply chain attack patterns, CI/CD pipeline security, SBOM implementation, shift-left security without blocking developers, our companion article on third-party risk management for SaaS sprawl, and our overview of open source licensing models.
- SecurityScientist, “Are Dependency-Confusion and Typosquatting Attacks a Real Risk?”
- SecurityScientist, “12 Questions and Answers About Typosquatting (PyPI/NPM)”
- Vulert, “Dependency Confusion Attacks Explained”
- SixHack Academy, “Dependency Confusion and Malicious Packages: The Supply Chain Attack”
- The Bright Byte, “Supply Chain Attacks 2024-2026: XZ, npm, and PyPI Lessons”
- arXiv, “The Range Shrinks, the Threat Remains: Re-evaluating LLM Package Hallucinations on the 2026 Frontier-Model Cohort”
- arXiv, “Cryptographic Registry Provenance: Structural Defense Against Dependency Confusion in AI Package Ecosystems”
- arXiv, “Killing Two Birds with One Stone: Malicious Package Detection in NPM and PyPI Using a Single Model of Malicious Behavior Sequence”
- Kayssel, “Supply Chain Attacks: Owning the Install Step”
