# Package typosquatting

Package typosquatting is publishing a harmful package under a name close to a popular one, so that a typo, a copied command or an AI assistant's suggestion installs it. It is not domain typosquatting, which registers web addresses such as `gooogle.com`. A typosquatted package runs code on the machine that installs it.

This page shows how such names are made, what they did in real incidents, how much a check on names catches, and what prevents them. The short answer: a check on names is a hint. What prevents typosquatting is a rule that no new dependency enters a project before someone approves it.

## How a typosquatted name is made

The names copy a popular name in a few repeated ways. The examples below come from two incidents that the registries published in 2017: 38 npm packages of the account `hacktask`, and 11 packages removed from PyPI.

| Shape | Examples | Looks like |
|---|---|---|
| One character added, removed or changed | `mongose`, `crossenv`, `urlib3` | `mongoose`, `cross-env`, `urllib3` |
| The name with a prefix or a suffix | `jquery.js`, `nodemailer-js`, `noderequest` | `jquery`, `nodemailer`, `request` |
| A separator added or removed | `setup-tools`, `babelcli` | `setuptools`, `babel-cli` |
| The name of software that is not a popular package | `ffmepg`, `node-openssl`, `tkinter` | FFmpeg, OpenSSL, Python's Tkinter |
| The name of a standard library module | `urllib`, `pwd`, `xml` | Modules that come with Python |

Other attacks use two more shapes. One replaces a character with one that looks the same, for example `l0dash` for `lodash`. The other writes an npm scope into the name, for example `types-node` for `@types/node`.

A newer source of names is AI coding assistants. A 2025 study (USENIX Security) found that code generated by commercial models suggested packages that do not exist at least 5.2% of the time, and code from open-source models 21.7% of the time. It counted 205,474 different invented names. When the same request was repeated 10 times, 43% of the invented names came back every time. So an attacker can predict such a name and publish a package under it. This is called slopsquatting.

## What happens when one is installed

Installing a package can run its code at once. During `npm install`, npm runs a package's `preinstall`, `install` and `postinstall` scripts. A package with a `binding.gyp` file builds native code by default. Nobody has to import the package for its code to run.

That is how both 2017 incidents worked:

- On npm, `crossenv` sent the environment variables of the machine it was installed on to `npm.hacktask.net`. Environment variables often hold tokens and passwords. npm removed about 40 packages of the account.
- On PyPI, 11 packages sent the package name and version, the user name and the host name to a server when they were installed. They also installed the module the user wanted, so nothing looked wrong. They were online from June until 6 September 2017.

## What the registries already do

- Since December 2017, npm does not let anyone publish a new package whose name differs from an existing one only in punctuation. While `react-native` exists, `reactnative` and `react_native` cannot be published.
- npm's naming rules for unscoped packages also say that a new name "is not spelled in a similar way to another package name".
- PyPI compares names without case, and treats `.`, `-` and `_` as the same character. `Requests_OAuthlib` and `requests-oauthlib` are one name.

These rules decide what can be published. They cannot decide what your project installs. Every package in the two incidents above was published, and was installed by people before it was removed.

## How much a check on names catches

A tool can compare each package name with the names of popular packages and warn about names that are close. SpellBound, a research tool from 2020, does this with 6 kinds of change: repeated, missing and swapped characters, swapped words, common typos and version numbers. It treats a package with 15,000 or more downloads a week as popular. It found about 60% of the past attacks that npm's security team reported. It warned on about 1 in 1,000 npm installs and 1 in 200 PyPI installs.

A name check finds copies of the names it knows. Some attackers copy the name of a program that is not a package at all: in npm's 2017 incident, `ffmepg` copied FFmpeg and `node-openssl` copied OpenSSL. An AI assistant can also invent a name that looks like no popular package. So a name check should help the person who decides. It should not be the only thing that keeps a package out.

## How to prevent package typosquatting

1. **Approve every new dependency before it enters.** Keep a list of the packages your projects may use, and check every pull request against it. A package that nobody has approved fails the check, whatever its name looks like. This also stops the copies that no name check can see.
2. **Check the package before you approve it.** Is the name exactly the one you meant? How old is the package, and how many people download it? Does it run code when installed? Does it name a source repository? Look again at a package that was published last week and has almost no downloads.
3. **Turn off install scripts where you can.** With `ignore-scripts=true` in `.npmrc`, npm does not run the scripts in `package.json` files when it installs. pnpm 10 and later do not run the install scripts of dependencies unless you allow that package (`allowBuilds` in pnpm 11). Some packages need their build step to work, for example native modules: allow only those.
4. **Copy names, do not type them.** Copy the install command from the package's registry page or its documentation, not from memory or from a chat.
5. **Check names that an AI assistant suggests.** Before you install a package an assistant suggested, open its page on the registry. Stop if the package does not exist, or if it is only a few days old.

## How Depos does this

- **The allowlist is the approval step.** Depos checks every package against the allowlist, in every ecosystem it reads. There is nothing to turn on. A pull request that adds a package nobody has allowed fails the **Depos allowlist** check. If you make that check required in GitHub's branch protection, the pull request cannot be merged. This works whatever the package's name looks like. See [Allowlist and policy](https://depos.dev/docs/guides/allowlist#policy) and [Pull request checks](https://depos.dev/docs/guides/pull-request-checks#blocking-merges).
- **The person who decides sees the hints.** On the **Allowlist** page, **To review** shows the packages nobody has decided on yet, as **Not listed**. A sign next to a package's name says when the name is close to a popular package's name. This covers npm names, against about 16,000 of the most downloaded npm packages. A package's **Checks** also say when it is new (first published less than 30 days ago, and downloaded fewer than 1,000 times last week), and, for npm packages, when it runs code when installed. See [Similar names](https://depos.dev/docs/guides/package-search#similar-names).
- **A hint never decides.** It does not change the allowlist or the pull request check. A person does.

[Sign up](https://depos.dev/auth/register) to try it on your repositories.

## Questions

### What is typosquatting in package management?

It is publishing a harmful package under a name close to a popular package's name, on a registry such as npm or PyPI. A typo, a copied command or an AI assistant's suggestion then installs it, and its install scripts run on that machine.

### Is package typosquatting the same as domain typosquatting?

No. Domain typosquatting registers web addresses close to a known one, for phishing or ads. Package typosquatting publishes code under a name close to a popular package's name. A typosquatted domain needs someone to visit it. A typosquatted package runs code when it is installed.

### What is the difference between typosquatting and dependency confusion?

In dependency confusion, an attacker publishes a public package with the same name as a company's private package. A build that looks in both places can then install the public one. Typosquatting copies a public name with a small change. A rule that every new package must be approved stops both.

### What is slopsquatting?

Slopsquatting is publishing a package under a name that AI coding assistants invent. A 2025 study found that 43% of invented names came back every time the same request was repeated, so attackers can predict them. A name check does not see such a name when it looks like no popular package.

### Do npm and PyPI stop typosquatting?

In part. npm refuses new names that differ from an existing name only in punctuation, and PyPI treats names that differ only in case or separators as one name. Neither stops every close name, and neither decides what your projects install.

### Is a name similarity check enough?

No. A name check marks names that are close to the popular names it knows. Some typosquatted names copy software that is not a package, such as FFmpeg and OpenSSL. Others are names that an AI assistant invented. Use a name check to help the person who approves a package, not instead of that person.

### What should I do if I installed a typosquatted package?

Remove it, and treat the machine as exposed. Change the tokens, keys and passwords that the package could read, including environment variables and files in your home folder. If it ran in CI, change the secrets that the CI job could read. Then add a rule that every new package must be approved, so the next copy cannot enter without a decision.
