Subscribe to the Non-Human & AI Identity Journal

What breaks when a malicious package runs during dependency installation?

The main failure is that installation becomes code execution inside a trusted environment. If that environment can see tokens, keys, or cloud credentials, the attacker does not need a separate exploit. The package can steal secrets, modify local state, and create a path into connected systems before defenders notice. Package trust must therefore be treated as an access-control issue, not just a software integrity issue.

Why This Matters for Security Teams

A malicious package does not need to “break out” of the installer if the installer itself can already reach secrets, caches, signing material, or cloud metadata. That makes dependency installation a privilege boundary, not just a software supply chain step. NHI Management Group has repeatedly shown how package-level compromise turns into credential theft and downstream access, including the LiteLLM PyPI package breach and the Shai Hulud npm malware campaign.

The security mistake is assuming “install time” is harmless because it happens inside CI, a dev container, or a build host. In practice, those environments often contain long-lived tokens, reusable API keys, package-publish credentials, and indirect trust into cloud and source control systems. Once code executes during installation, the attacker can harvest secrets, alter build outputs, or plant persistence before any runtime controls are engaged. Current guidance from the NIST Cybersecurity Framework 2.0 supports treating this as an asset and access problem, not only an integrity problem. In practice, many security teams encounter the impact only after a build credential or signing token has already been reused outside the original pipeline.

How It Works in Practice

During dependency installation, package manager hooks, lifecycle scripts, native build steps, and post-install actions can execute with the same trust and network reach as the installer. If the environment has ambient access to NHI secrets, the malicious package can read environment variables, search local credential stores, reach metadata services, query mounted volumes, or call internal APIs. That is why package trust must be paired with workload identity and runtime authorization, not just checksum verification.

For security teams, the practical control set is straightforward:

  • Run installs in ephemeral, isolated build workers with minimal network access.
  • Remove static credentials from build contexts and replace them with short-lived, task-scoped access.
  • Separate dependency resolution from privileged build and release steps.
  • Use policy checks to block install scripts unless there is explicit approval.
  • Prefer workload identity over shared secrets so every build action is attributable and revocable.

That approach aligns with broader NHI governance in the Ultimate Guide to Non-Human Identities, especially where secrets exposure, over-privilege, and poor visibility combine. It also matches NIST’s emphasis on protecting identity-enabled access paths rather than relying on perimeter assumptions alone. In practice, the common failure is not the package manager itself but the surrounding environment, especially when CI runners, developer laptops, or container build stages reuse the same tokens and cloud roles across many jobs. These controls tend to break down when build systems are long-lived and highly networked because package installation then becomes a lateral-movement path into adjacent infrastructure.

Common Variations and Edge Cases

Tighter install controls often increase build friction, requiring organisations to balance developer speed against blast-radius reduction. There is no universal standard for this yet, so current guidance suggests using different controls for different trust tiers rather than enforcing one policy everywhere.

Some environments cannot fully disable install-time scripts because legitimate packages depend on them for compilation or native extensions. In those cases, the safer pattern is to allow scripts only in hardened build sandboxes, with no production secrets and no standing cloud credentials. Air-gapped or cached builds reduce exposure, but they do not eliminate risk if the cache itself contains tokens or if the runner can still reach internal services. Teams also need to watch for transitive dependencies, because the malicious component is often not the top-level package that a developer selected. For that reason, dependency approval should include provenance checks, secret scoping, and post-install telemetry. When packages are installed on developer endpoints instead of controlled build hosts, the exposure becomes even harder to contain because local browsers, password stores, and SSH agents may be available to the installer process.

For environments with CI/CD publishing rights, the biggest edge case is privilege chaining: a low-trust install step can steal a token that later signs artifacts, pushes containers, or updates infrastructure. That is why package installation should never share the same identity as release approval. The safest operating model is temporary identity, minimal secrets, and explicit separation between untrusted dependency code and privileged delivery actions.

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 and OWASP Agentic AI Top 10 address the attack and risk surface, while NIST AI RMF set the governance and control requirements practitioners need to meet.

Framework Control / Reference Relevance
OWASP Non-Human Identity Top 10 NHI-03 Install-time code execution often abuses long-lived NHI secrets and over-privilege.
OWASP Agentic AI Top 10 A-04 Malicious install scripts behave like autonomous code with tool and secret access.
NIST AI RMF The issue is runtime access under dynamic context, not only software integrity.

Replace standing build secrets with short-lived NHI credentials and rotate anything exposed during installs.