Typosquatting tricks a person into installing a package with a name close to the real one. Dependency confusion tricks a package manager into choosing a public package over a private one with the same name. The first is a human error, the second a configuration flaw, so the defenses differ.
Definitions
Typosquatting: a malicious package is published under a name resembling a popular one, hoping someone mistypes or misremembers it. SLSA's threat model puts this in the category of using a compromised package where users are tricked into installing the wrong one, and says typosquatting is mostly outside its scope.
Dependency confusion: a public package is published under the exact name of a private one. If the build can search a public source, it may pick the attacker's version.
Compared
| Typosquatting | Dependency confusion | |
|---|---|---|
| Name | Similar | Identical |
| Who errs | A person | A tool configuration |
| Target | Anyone installing from a public registry | Organizations with private packages |
| Where it shows up | A manual install or a copied command | A build that resolves several sources |
| Best fix | Review additions, check names, allow lists | Single source registry, scoped names |
Defenses for typosquatting
- Review new dependencies. A pull request that adds a package should be looked at, including the name.
- Use an approved list or internal mirror for packages that may be added.
- Copy install commands from official sources, not from search results or chat.
- Watch for very new, low usage packages with names near known ones.
Defenses for dependency confusion
- Resolve from one source. The pip documentation warns against using an extra index for packages not in the main repository, calling it a dependency confusion risk.
- Map scopes to registries. In npm a scope can be tied to a specific registry.
- Install from lockfiles in CI, so changes are explicit. The npm ci command errors on a mismatch.
Shared controls
Both are helped by an inventory, by lockfile review in pull requests, and by policy that treats a very new package as needing approval.
Which one should you prioritize?
If you have private packages, fix dependency confusion first because the fix is configuration and cheap. If your developers add dependencies often, invest in review and an approved list for typosquats.
Quick check
Can the same scanner address both?
Partly. A scanner can flag unusual names and sources, but the durable fixes are process and configuration.
Is a typosquat the same as a compromised package?
No. A typosquat is a separate package with a deceptive name. A compromised package is a legitimate one that was altered.
Where Safeguard fits
Safeguard offers dependency scanning and policies and gates for pull requests, so new dependencies can be reviewed. The free scan lists a project's dependencies.
Sources
Last reviewed: 19 October 2026.