← All guides

Typosquatting explained: how to spot a fake package

By Doruk Kıno · · 2 min read

Typosquatting is one of the simplest and most common supply-chain tricks: someone publishes a package whose name is almost exactly like a popular one, hoping you mistype it, or copy it from a shady tutorial, and install the fake by mistake. Because the fake can run code the moment you install it, this small naming trick can do real damage.

Why it works

Package names are typed by hand, copied from blog posts, and pasted from chat messages all day long. Attackers register names that are one keystroke away from a real package and wait. You install it thinking it's the real thing, its install script runs, and that's that. The whole attack rides on a name you didn't look at closely.

Common patterns

  • A missing or added character. cross-env vs crossenv; lodash vs lodahs.
  • Different spelling. American vs British (color vs colour), or a singular vs plural.
  • Scope confusion. An unscoped name imitating a real scoped package like @org/thing.
  • Extra words. package-js, official-package, or a trendy prefix/suffix added to a real name.

How to spot it

  • Get the exact name from the project's official docs or site — not from a random tutorial or a chat message.
  • On the package page, check weekly downloads and the first-published date: a “popular” package with few downloads or a very recent debut is suspicious.
  • Check the repository link and the publisher: a real package points to its official source and is published by its maintainers.
  • Look for an install script (postinstall) — most ordinary libraries don't need one.

It's not just npm

The same trick shows up across package registries — Python's PyPI, and others. The defence is always the same: confirm the exact name from an official source, sanity-check the download numbers and publisher, and be wary of anything that wants to run code at install time.

Let a scanner help

You don't have to catch every lookalike by eye. GiTRay reads a repository's dependency files and checks them against a public database of known-malicious packages, without installing anything. For the full package checklist, see how to tell if an npm package is malicious.

Scan a repository now

Paste a public GitHub URL and GiTRay runs all of these checks in seconds — without cloning or running anything.

Try:
See all 39 checks GiTRay runs →

The bottom line

Typosquatting beats you at the moment you type or paste a name. Slow down for that one second, confirm the spelling from an official source, and the trick falls apart.