They work because attackers exploit trust in familiar package names, weak namespace discipline, and automated dependency resolution. When a package name closely resembles an internal or well known project, developers may install it by mistake. Pre-install script execution then turns that mistake into data exfiltration or further compromise before defenders can react.
Why package ecosystems keep being exploitable
Package ecosystems make dependency confusion and namesquatting durable because they optimise for easy publication and fast resolution, not for human scrutiny. If a build system can accept the “best” matching name from a public index, or if a nearly identical package name is available, the attacker only needs one trusted developer or pipeline to pick it once. That combination of automated trust and naming ambiguity is enough.
Two design choices matter most. First, many ecosystems do not enforce strong namespace ownership, so a package name can be claimed before an internal team formally protects it. Second, dependency tooling often resolves names automatically and may prefer version or availability signals over provenance, so a typo, an unqualified import, or an overly broad dependency declaration can turn into unreviewed code execution. That is why these attacks persist across ecosystems rather than dying out after one incident.
Attackers also benefit from the fact that package installation is often treated as routine developer work. A malicious package does not need to look obviously suspicious if it can mimic a familiar internal utility, a vendor library, or a transitive dependency name. Once installed, pre-install or post-install hooks can convert a simple naming mistake into secret theft, environment enumeration, or code execution before downstream controls notice anything unusual. See also the LiteLLM PyPI package breach for a direct example of how package trust can be abused.
What makes the attack path so reliable
Dependency confusion works when an organisation uses an internal package name that is also available, or can be claimed, on a public registry. Build tools may then fetch the public package because they interpret it as a valid dependency source, especially when versioning or resolution rules are loose. Namesquatting is simpler but related, because the malicious package only needs to be close enough in spelling or branding to trick a developer, maintainer, or automated workflow.
The reliability comes from predictable operational habits. Developers reuse names, mirror internal conventions, and install dependencies with high trust during build and test phases. Attackers know that if they can get the malicious package into a CI/CD path, they may inherit the same execution context as the build itself. That can expose tokens, source code, artifact credentials, cloud keys, or other secrets stored in the pipeline environment. The relevant pattern is well illustrated in PyPI Breach and the broader analysis in 52 NHI Breaches Analysis.
Namespace weakness is the enabling condition, but trust is the real prize. A package name that looks legitimate can bypass the kind of scepticism people apply to unfamiliar downloads. Once the package is installed, the attacker can exploit the build or runtime environment immediately, which is why a naming trick can produce a compromise that looks like an ordinary dependency update.
Risk and Threat Considerations
These attacks matter because the first failure is often silent: the wrong package is accepted as normal software, and execution begins inside a trusted pipeline or workstation. The same weakness can expose both source and secrets, then expand into downstream compromise if the package has network access, write access, or token access.
Failure mechanism: A public package with a trusted-looking name is resolved, installed, and executed by tooling that does not sufficiently verify namespace ownership, provenance, or intended source.
Impact: Attackers can steal credentials, alter builds, implant backdoors, or pivot into adjacent systems before the organisation realises the dependency came from the wrong place.
Standards & Framework Alignment
This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.
OWASP Non-Human Identity Top 10 address the attack and risk surface, while CIS Controls v8 and NIST CSF 2.0 set the governance and control requirements practitioners need to meet.
| Framework | Control / Reference | Relevance |
|---|---|---|
| CIS Controls v8 | CIS 2 — Inventory and Control of Software Assets | Package confusion depends on uncontrolled software intake and ambiguous package inventory. |
| CIS 8 — Audit Log Management | Install-time execution and dependency pulls need traceability for investigation and detection. | |
| CIS 16 — Application Software Security | Malicious packages exploit software delivery and install-time execution paths. | |
| Recommendation — Inventory approved package sources and block untrusted dependencies from entering builds. Log dependency resolution, package installs, and script execution for review and alerting. Require secure dependency handling and restrict risky install-time code execution. | ||
| NIST CSF 2.0 | PR.DS — Data Security | Package attacks often aim at secrets, source code, and other sensitive data in build contexts. |
| PR.PS — Platform Security | Dependency resolution and package execution are platform-level supply-chain controls. | |
| Recommendation — Protect sensitive build data and restrict where secrets are available during dependency installs. Harden package retrieval and execution paths to prevent untrusted software from running. | ||
| OWASP Non-Human Identity Top 10 | NHI-04 — Secret and Credential Exposure | Malicious packages commonly steal tokens and keys exposed in build or runtime environments. |
| NHI-06 — Excessive Privileges | Compromised packages become far more damaging when build identities have broad access. | |
| NHI-08 — Third-Party and Supply Chain Risk | Dependency confusion and namesquatting are supply-chain abuses of package trust and provenance. | |
| Recommendation — Minimise secret availability during installs and rotate any exposed credentials immediately. Reduce build and pipeline privileges so package execution cannot access more than necessary. Verify package provenance and constrain dependency sources to trusted registries only. | ||
Practitioner Guidance
What to prioritise: Treat package-name governance and dependency source policy as a build-control issue, not a developer preference. Internal package names should be reserved early, and build tooling should be configured so that public registries cannot silently satisfy internal dependency names.
What to verify: Check whether your install process validates the expected repository, package owner, and provenance before execution. If a dependency can run install scripts, verify whether that execution is actually required or whether it can be blocked for high-risk environments.
What practitioners underestimate: The real danger is not just a malicious package existing, but a legitimate workflow deciding it is trusted enough to execute automatically. That is why the most effective control is to reduce ambiguous name resolution and to make package origin visible at the point of install.
Practitioner takeaway: If your ecosystem lets names resolve before trust is established, attackers do not need to beat your defenders, they only need to beat your naming and resolution rules.
Related resources from NHI Mgmt Group
- Why do dependency confusion attacks keep working in mature organisations?
- Why do package hallucinations and dependency confusion increase supply chain risk?
- Why do package impersonation and dependency confusion still work against mature teams?
- What is the difference between malicious package publishing and a controlled dependency confusion challenge in practice?
Deepen Your Knowledge
Reviewed and updated by the NHIMG editorial team on September 17, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org