Join our Newsletter — 33% off our NHI Course
Home› FAQ› Cyber Security› Should organisations allow npm lifecycle scripts in production…
Cyber Security

Should organisations allow npm lifecycle scripts in production CI pipelines?

← Back to all FAQ
By NHI Mgmt Group Editorial Team Updated October 12, 2026 Domain: Cyber Security

Only when the dependency is trusted, the script is necessary, and the runner is tightly segmented from cloud metadata and secrets. Most pipelines should block lifecycle scripts by default because install-time execution is an unnecessary privilege boundary for ordinary package delivery. The safer default is deny, then whitelist with review.

Why npm lifecycle scripts are a production CI privilege boundary

npm lifecycle scripts turn dependency installation into executable code, so the question is not just whether the package is legitimate, but whether you want arbitrary install-time logic to run with CI authority. In production pipelines, that authority often includes repository access, signing material, build credentials, and cloud metadata. Allowing scripts by default widens the blast radius of a compromised package, maintainer account, or transitive dependency.

That is why the safer stance is to treat lifecycle execution as an exception path, not a routine install feature. If a package really needs a script, the dependency should be trusted, the use case should be explicit, and the runner should be isolated from secrets and metadata before the script is allowed to execute.

What makes lifecycle scripts especially risky in build systems

Lifecycle scripts are powerful because they run automatically at the exact point where CI systems are fetching, unpacking, and preparing third-party code. That means they can operate before a human has a chance to inspect what was installed, and before downstream controls such as test gates or image scanning are relevant. In practical terms, install-time execution can become a shortcut from package intake to credential theft, source tampering, or environment discovery.

The risk is not abstract. Supply-chain incidents repeatedly show that package install hooks are attractive because they sit close to secrets, tokens, and publishing workflows. A malicious script may not need broad privileges if the runner already exposes enough environment data or cloud access to move laterally. For examples of how npm package abuse turns install-time code into secret exposure, see Shai Hulud npm malware campaign and Rspack npm compromise 2024.

When organisations keep lifecycle scripts enabled globally, they also create inconsistent trust boundaries. One project may inherit a trusted package cache, another may rebuild from scratch, and a third may run with elevated tokens in a shared runner. That inconsistency makes it hard to prove whether the install step is a controlled dependency operation or an execution surface.

How to decide when to permit them, and what to lock down

The decision should be based on necessity, trust, and runner isolation. If the dependency can be installed and used without the script, block it. If the script is required, permit it only for the specific package or pipeline stage that needs it, and keep that stage away from cloud instance metadata, long-lived tokens, and high-value secrets.

That same pattern appears across real package compromises. Attackers repeatedly target developer credentials, publishing tokens, and CI secrets because a single install or postinstall hook can provide a foothold into multiple systems. The control question is therefore not “can the script run?”, but “what can it reach if it does?”

For the broader supply-chain control model, SLSA helps frame provenance and build integrity, while the NHI Lifecycle Management Guide is useful for thinking about rotation, offboarding, and exposure windows when CI systems rely on secrets. If the pipeline also uses cloud credentials, the isolation standard should resemble NIST SP 800-207 Zero Trust Architecture, because the runner should not be able to assume broad ambient trust just because it is part of the build path.

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 addresses the attack and risk surface, while SLSA, NIST SP 800-53 Rev 5 and NIST Zero Trust (SP 800-207) set the governance and control requirements practitioners need to meet.

FrameworkControl / ReferenceRelevance
OWASP Non-Human Identity Top 10NHI-02 — Secret LeakageInstall-time scripts can expose CI secrets and tokens.
NHI-05 — Overprivileged NHICI runners often hold more privilege than install scripts should receive.
Recommendation — Block lifecycle scripts where they can read secrets, then rotate any exposed material immediately. Reduce runner privileges and separate install jobs from secret-bearing environments.
SLSASupply-chain Levels for Software ArtifactsBuild provenance and integrity are central when deciding whether install-time execution is acceptable.
Recommendation — Require provenance and reproducibility checks before allowing dependency-installed code to execute.
NIST SP 800-53 Rev 5IA-5 — Authenticator ManagementLifecycle scripts often target tokens and other authenticators in CI.
AC-6 — Least PrivilegeThe core issue is whether package install code receives unnecessary CI authority.
Recommendation — Protect, rotate, and scope CI authenticators so install-time code cannot reuse them broadly. Constrain pipeline permissions so dependency installs cannot reach unrelated resources.
NIST Zero Trust (SP 800-207)Zero Trust ArchitectureRunner segmentation and metadata denial mirror zero-trust trust-boundary design.
Recommendation — Segment build runners and require explicit access checks before any secret-bearing action.

Practitioner Guidance

What to prioritise: Default to blocking npm lifecycle scripts in production CI, then create an explicit allowlist for the few packages that genuinely require execution. Treat the allowlist as a security exception register, not as a convenience setting.

What to verify: Before permitting a script, confirm that the runner cannot reach cloud metadata, production secrets, or reusable publishing credentials. If the runner can exfiltrate something valuable, the script has more privilege than the package necessarily deserves.

Common mistake: Teams often focus on whether the package is popular or pinned, then forget that install-time code still runs with the pipeline’s ambient authority. A trusted package can still become a harmful execution point if the surrounding environment is overexposed.

Decision rule: If the package is public, transitive, or rarely reviewed, block lifecycle scripts and require a non-executing install path. If the script is unavoidable, run it in a tightly segmented job with minimal network reach and no standing access to secrets.

Practitioner takeaway: The safest production posture is not “never run scripts”, it is “never let install-time code inherit more trust than the dependency has earned.”

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.

NHIMG Editorial Note
Reviewed and updated by the NHIMG editorial team on October 12, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org