Typosquatting in Package Registries: How One Wrong Letter Installs Malware
Most developers install packages by typing a name they remember, copying it from a tutorial, or accepting an autocomplete suggestion, and that moment of trust is exactly what typosquatting attacks exploit. A typosquatted package is a malicious package published under a name that closely resembles a popular one: a transposed pair of letters, a missing letter, a swapped hyphen, or a similar-looking word. Install the wrong name and the malicious code runs with the same privileges as the installation itself, which in many setups means full access to the project and sometimes to the machine. The Package Typosquatting Checker compares a package name you supply against well-known packages and flags close matches, so a suspicious name can be investigated before anything is installed. It checks name similarity; it cannot prove a package is safe, since a correctly-spelled package can still be malicious.
The attack works because package installation is usually a low-attention task. A developer following a tutorial at speed, or copying a name from a chat message, is unlikely to notice that a name differs by one letter from the intended package, especially when the registry page looks plausible and the package even contains some of the expected functionality. Attackers count on this: they publish packages that mimic popular ones, sometimes with a similar description and version history, and wait for mistaken installs. The cost of the attack is low, the potential payoff is high, and the victim often discovers the problem only when something else goes wrong.
How it works
A typosquatting checker measures how similar a supplied name is to known popular package names, using string-similarity techniques that catch transpositions, deletions, insertions and substitutions. It may also consider phonetic similarity and common confusions, such as a hyphen versus an underscore, or a plural versus a singular form. The output is a list of close matches with a similarity indication, so the user can see whether the name they typed is a near-miss of something well known. A close match is a warning to investigate, not a verdict: some legitimate packages genuinely have similar names, and the checker's job is to make the similarity visible, not to decide the question alone.
How it works
Similarity alone is never enough, which is why a checker result should trigger a short investigation. Open the registry page for the package and check its download counts, its publication history, its maintainer, and its README: a typosquatted package often has far fewer downloads than the popular package it mimics, a very recent first publication, and a thin or copied README. Compare the name character by character with the intended package, and check whether the package you meant is actually the one your project's lockfile records. The lockfile is the ground truth for what is installed, and a discrepancy between the lockfile and the name you typed is itself a finding.
Worked example
Worked example with sample values. Suppose a developer intends to install a popular package with 12 million weekly downloads, but types a name that differs by one transposed pair of letters. The checker compares the typed name against a list of 100 popular packages and reports 1 close match: the intended package, at a similarity that the checker classes as high. The lookalike package itself has 340 weekly downloads and was first published 9 days ago, while the intended package has 12 million weekly downloads and a history of 6 years. The download ratio is 12,000,000 divided by 340, which is about 35,294 to 1, and the age difference is 6 years versus 9 days. Those two numbers, not the similarity score alone, make the decision obvious. These are sample values for illustration.
Worked example
The same example shows the value of checking before installing rather than after. Suppose the mistaken package had been installed and its install script had run: the malicious code would already have had its chance, and removing the package afterwards would not undo whatever it did. Checking the name first costs under a minute, while investigating a compromised project costs hours or days, and may require rotating credentials and rebuilding from a known-good state. The economics are entirely one-sided, which is why the check belongs in the workflow before the install command, not in the post-incident review.
Mistakes to avoid
One common mistake is trusting autocomplete or a search result without reading the exact name, especially in a terminal where a suggestion can be accepted with a single keypress. Another is copying install commands from untrusted sources, such as forum posts or chat messages, without verifying the package name against the project's documentation. A third is assuming that a package with a plausible README and a few hundred downloads is legitimate: download counts can be inflated, and a README can be copied from the genuine package in minutes.
Mistakes to avoid
A further mistake is treating the checker as a guarantee. A package that is not a near-miss of any popular name can still be malicious, and a new typosquatting technique may not be caught by similarity measures at all. Combine the name check with the other defences that matter: install only packages the project actually needs, review lockfile changes in code review, pin versions, and keep install scripts under scrutiny. The checker is one layer, and layers are what make the whole system resilient when any single layer fails.
Putting it into practice
Make the name check a habit for every manual install: before running the install command, check the name, compare it character by character with the intended package, and glance at the registry page's downloads and history. In team settings, add the same discipline to code review, so lockfile changes that introduce unfamiliar package names get a second look. When a suspicious package is found, report it to the registry rather than merely avoiding it, because the next developer to mistype the same name will benefit from the report. Typosquatting is a low-effort attack, and a low-effort check is a proportionate defence.
Related tools and reading: Related tools and reading: the Package URL Parser and the Dependency End-of-Life Checker cover neighbouring checks that pair naturally with this one, and the guide at [/blog/cyber-security-tools-guide/] extends the same topic with further background and examples for readers who want to go deeper.
Key points
- Typosquatting exploits one-letter differences from popular package names
- A close match is a warning to investigate, not a verdict on its own
- Compare downloads, publication history and the lockfile before installing
- Check the name before installing, since removal cannot undo an install script
In short: t.yposquatting exploits one-letter differences from popular package names
One habit ties all of this together: re-check after every change. A result is only as current as the input it was run on, so a fix, a redesign, or a new version of the underlying material deserves a fresh run rather than reliance on an old report. Keep the previous result alongside the new one, note what changed between them, and treat any new finding as a question to investigate rather than a verdict to accept or dismiss. That loop of checking, fixing, re-checking and recording is what turns a one-off test into a reliable routine, and it costs far less time than debugging a problem that a second check would have caught early.