Typosquatting
Registering malicious packages under names that are near-misses of popular ones (misspellings, swapped/repeated characters, added prefixes/suffixes, lookalike scopes) and waiting for humans or tooling to install the wrong name.
How it works
Like Dependency Confusion, it exploits registries identifying packages by name only, but it is opportunistic rather than organization-targeted: the attacker squats many typo variants of high-download packages and waits. Name sources include common typos, package names popular in other ecosystems, Linux-distro naming variants, and LLM-hallucinated names (Slopsquatting).
Execution paths:
- Install-time — npm
preinstall/install/postinstallhooks fire onnpm install, before the app runs. - Import/call-time — code runs when the module is loaded or a function is called (e.g.
rustdecimal’sDecimal::new), which evades--ignore-scripts. - Delayed / targeted — a fully working trojanized fork that only misbehaves in a specific environment.
Sonatype argues “typosquatting” is now too narrow: the broader pattern is manufactured legitimacy (brandjacking) — prefix/suffix addition, version mimicry, embedded target terms, altered scopes/namespaces, and names that describe the function of a legit package.
Techniques / payloads
Common name mutations (TypoGard’s detection features):
| Mutation | Example |
|---|---|
| Swapped characters | reqeusts → requests |
| Repeated characters | rustdeciimal, Newtonsoftt.Json.Net |
| Separator change | rustdecimal vs rust_decimal |
| Dropped character | lodas → lodash |
| Suffix/prefix | react-router-doms, Newtonsoftt.Json.Net (.Net suffix), opensearch-setup-tool |
| Keyboard-adjacent typo | layout-based substitutions |
Metadata forgery: the NuGet Newtonsoftt.Json.Net nuspec claimed author James Newton-King, projectUrl https://www.newtonsoft.com/json, title Json.NET, MIT license, version 11.0.x (real line is 13.x) — plausible in a dependency graph.
Payload example (Microsoft, vpmdhaj cluster, May 2026, 14 npm packages imitating OpenSearch/Elastic tooling):
- Gen-1:
preinstall.jsPOSTs base64 host context to C2 with headerX-Supply: 1, dropspayload.bin;index.jsrelaunches it on everyrequire()for persistence across CI stages. - Gen-2:
setup.mjsdownloads the legitimate Bun v1.3.13 runtime from GitHub Releases and runs a ~195 KB Bun-compiled stealer — no install-time C2 round trip. - Targets: IMDSv2
169.254.169.254+ ECS169.254.170.2creds, STSGetCallerIdentity/AssumeRole, Secrets ManagerListSecrets/GetSecretValueacross 16+ regions,VAULT_TOKEN, npm tokens via/-/whoamiand/-/npm/v1/tokens; setsCI=falseto fool build-aware code. Stolen npm publish tokens enable a downstream pivot (see Malicious Packages, Shai-Hulud Worm).
Notable cases
rustdecimal(crates.io, 2022) — mimickedrust_decimal;Decimal::newexecuted a malicious binary.Newtonsoftt.Json.Net(NuGet, Aug–Oct 2025) — JFrog: a working Json.NET fork that, afterJsonConvert.DefaultSettingsinit and a delay, rigged results on the Digitain betting platform and exfiltrated them with headerX-Seq-ApiKey: theperfectheist2025. Seven versions; unlisted but still downloadable.vpmdhajnpm cluster (May 2026) —opensearch-setup,opensearch-config-utility,elastic-opensearch-helper,env-config-manager,@vpmdhaj/devops-tools; cloud/CI credential theft.reqnest(PyPI, Nov 2026) — typosquat ofrequests; on import exfiltrates Telegram files (GHSA malware advisory, campaign2026-11-reqnest).- ~800-package npm RAT campaign — “AI slop squatted or randomly generated typo-squatting” names; README instructs
require()(no lifecycle hook) to trigger the WEL1DROPPER downloader pulling payloads from Cloudflare Workers. @isaacs/cliuilookalikes — Snyk foundstring-width-cjs/strip-ansi-cjs/wrap-ansi-cjs-style squats near legitimate aliased dependencies.- Since 2022, typosquat campaigns have targeted packages with a combined 1.2B weekly downloads (Trail of Bits, citing Phylum).
Defenses
- Detection at add-time — Levenshtein checks are noisy; TypoGard (npm) uses context-aware metrics + popularity thresholds; its Rust port Typomania is deployed in crates.io and has caught malicious crates.
- Scanners — GuardDog (
uvx guarddog pypi scan <pkg>, also npm, Go, crates, RubyGems, GitHub Actions, VS Code extensions) correlates capability + threat indicators via YARA/Semgrep-style rules and metadata heuristics. - Minimum package age — a 48h (or longer) release-age gate blocks same-day squats and fast-moving campaigns.
- Show metadata at install — dependents, downloads, age, maintainer history; verify publisher, not download count.
- Disable install scripts (
--ignore-scripts) — necessary but insufficient given import-time payloads. - Pin exact versions, commit lockfiles with hashes, route installs through a curated proxy registry.
Related
- Software Supply Chain Security
- Dependency Confusion · Slopsquatting · Malicious Packages
- Shai-Hulud Worm · Leaked Cloud Credentials · Cloud Metadata Service Exploitation
Sources
- Defender's Perspective: Dep Confusion and Typosquatting (SLSA) · original
- Supply chain attacks are exploiting our assumptions (Trail of Bits) · original
- The Perfect Heist: NuGet Typosquat Targets Betting Platform to Rig Results · original
- Typosquatted npm packages used to steal cloud and CI/CD secrets · original
- Malicious Sicoob NuGet Steals Banking Credentials as npm Packages Target... · original
- Malicious code in reqnest (PyPI typosquat) · original
- Nearly 800 malicious npm packages deliver cross-platform RAT and infostealer · original
- The mysterious supply chain concern of string-width-cjs npm package · original
- GuardDog: CLI Tool to Identify Malicious PyPI and npm Packages · original
- NPM Supply Chain Attacks Explained · original
- The practical checklist for defending against supply chain attacks (Aikido) · original