Install-time scripts turn a dependency into active code, so package presence is no longer the same as package safety. A malicious dependency can run before scanners or review processes notice it, which means the control point shifts from manifest review to execution governance and runtime monitoring.
When install scripts make dependency presence unsafe
The break is in the trust model. A lockfile or manifest no longer tells you only what was declared, it also signals what will execute during install. That means dependency review cannot stop at source reputation, version pinning, or static scanning. The security question becomes whether the install path itself is allowed to run untrusted code.
Once install-time execution is permitted, a package can affect the host before a human ever approves it. That changes npm from a passive distribution mechanism into an execution surface, which is why package managers need controls for script behavior, not just package integrity.
That shift is visible in multiple real-world supply chain incidents. Shai Hulud npm malware campaign, Nx s1ngularity attack 2025, and coa and rc npm hijacks 2021 all show how install-time execution can be used to steal secrets, alter developer environments, or plant payloads during routine package installation.
Why traditional package review breaks down
Manual review usually assumes the package you inspect is the package you get. Install scripts break that assumption because the visible artifact and the executed behavior are not the same thing. A benign-looking dependency can hide a postinstall, preinstall, or prepare step that runs shell commands, fetches remote content, or touches local credentials.
That creates a blind spot for scanners that only inspect the dependency tree, package metadata, or published source. A dependency can pass review and still behave maliciously at install time, especially when the script is short, obfuscated, or triggered only in certain environments.
It also changes what “safe” means operationally. A package can be acceptable as code but unsafe as an installation event, which is why teams should treat script execution as a separate control decision from dependency inclusion.
What defenders need to control instead
When install scripts are allowed, the control point moves from “is this package approved?” to “is this execution path bounded, observable, and justified?” That usually means restricting script execution in automated environments, forcing explicit approval for packages that need build hooks, and monitoring for unusual filesystem, process, network, or secret-access activity during install.
Packages that really need scripts should be exceptional, not the default. If a dependency requires execution to work, teams should be able to explain why that execution is necessary, what it can access, and how the blast radius is contained.
This is also where dependency policy and developer ergonomics collide. The stronger the control around install scripts, the more likely you are to catch malicious behavior early, but the more you must manage legitimate build-time requirements through allowlists, sandboxing, or dedicated build pipelines.
Risk and Threat Considerations
Install scripts are attractive to attackers because they run in a trusted workflow with access to developer machines, CI runners, and often local secrets. That makes them a practical route for credential theft, persistence, and supply chain poisoning even when the package itself looks ordinary.
Failure mechanism: A malicious package uses install-time execution to reach secrets, tamper with files, or stage a second payload before review or detection controls inspect the runtime behavior.
Impact: The compromise can spread from one developer workstation or build job into source control, cloud credentials, downstream builds, and every application that consumes the poisoned dependency.
Standards & Framework Alignment
This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.
MITRE ATT&CK addresses the attack and risk surface, while CIS Controls v8, NIST SP 800-53 Rev 5 and OWASP ASVS set the governance and control requirements practitioners need to meet.
| Framework | Control / Reference | Relevance |
|---|---|---|
| MITRE ATT&CK | T1059 — Command and Scripting Interpreter | Install scripts are executed code during package installation. |
| Recommendation — Hunt for script execution during installs and restrict shell-based launch paths. | ||
| CIS Controls v8 | CIS-2 — Inventory and Control of Software Assets | Dependency installs need software asset visibility and approval boundaries. |
| Recommendation — Inventory dependencies and block unapproved install-time execution. | ||
| NIST SP 800-53 Rev 5 | SI-7 — Software, Firmware, and Information Integrity | Malicious install scripts undermine integrity of software delivery. |
| CM-7 — Least Functionality | Disabling install scripts reduces unnecessary execution surface. | |
| Recommendation — Validate package integrity and detect unauthorized changes during installs. Disable package execution paths that are not explicitly required. | ||
| OWASP ASVS | V15 — Secure Coding and Architecture | Build and dependency execution paths are part of secure software architecture. |
| Recommendation — Treat dependency install hooks as part of the trusted execution design. | ||
Practitioner Guidance
What to prioritise: Treat install-script execution as a separate approval path from dependency approval. If a package does not genuinely need lifecycle hooks, disable them by default in CI and production build workflows.
What to verify: Confirm whether your package manager, lockfile policy, and build runners still allow arbitrary install hooks, and check whether secrets are exposed in the same environment where installs occur.
What good looks like: Routine dependency installs are non-executable by default, exceptions are documented, and any package that must execute during install is monitored as a code execution event, not just a dependency event.
Practitioner takeaway: The real control failure is not “untrusted package installed”, it is “untrusted code got to run before governance could intervene.”
Related resources from NHI Mgmt Group
- What breaks when AI coding agents automatically install poisoned npm packages?
- What breaks when npm install scripts can access long-lived credentials?
- What breaks when npm packages execute code through binding.gyp instead of package.json scripts?
- What breaks when a trusted npm package can execute post-install code?
Deepen Your Knowledge
Free weekly newsletter
Subscribe to the NHI & AI Identity Journal
The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.
Bonus 33% off our NHI Course when you subscribe.
Reviewed and updated by the NHIMG editorial team on October 11, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org