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/postinstall hooks fire on npm install, before the app runs.
  • Import/call-time — code runs when the module is loaded or a function is called (e.g. rustdecimal’s Decimal::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):

MutationExample
Swapped charactersreqeusts → requests
Repeated charactersrustdeciimal, Newtonsoftt.Json.Net
Separator changerustdecimal vs rust_decimal
Dropped characterlodas → lodash
Suffix/prefixreact-router-doms, Newtonsoftt.Json.Net (.Net suffix), opensearch-setup-tool
Keyboard-adjacent typolayout-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.js POSTs base64 host context to C2 with header X-Supply: 1, drops payload.bin; index.js relaunches it on every require() for persistence across CI stages.
  • Gen-2: setup.mjs downloads 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 + ECS 169.254.170.2 creds, STS GetCallerIdentity/AssumeRole, Secrets Manager ListSecrets/GetSecretValue across 16+ regions, VAULT_TOKEN, npm tokens via /-/whoami and /-/npm/v1/tokens; sets CI=false to fool build-aware code. Stolen npm publish tokens enable a downstream pivot (see Malicious Packages, Shai-Hulud Worm).

Notable cases

  • rustdecimal (crates.io, 2022) — mimicked rust_decimal; Decimal::new executed a malicious binary.
  • Newtonsoftt.Json.Net (NuGet, Aug–Oct 2025) — JFrog: a working Json.NET fork that, after JsonConvert.DefaultSettings init and a delay, rigged results on the Digitain betting platform and exfiltrated them with header X-Seq-ApiKey: theperfectheist2025. Seven versions; unlisted but still downloadable.
  • vpmdhaj npm 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 of requests; on import exfiltrates Telegram files (GHSA malware advisory, campaign 2026-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/cliui lookalikes — Snyk found string-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.

Sources