T09 · Insecure Skill Coding Practices
- Location
package.json:39- Finding
Recursive npm Install Lifecycle Causes Resource Exhaustion
- Content
View full analysis
Vulnerability Details
File Location:
package.json:39-41
Vulnerability Type: Recursive package lifecycle execution and denial of service
Risk Level: HighVulnerable Code
json "scripts": { "install": "npm install",Technical Analysis
npm automatically executes the
installlifecycle script while installing a package. The configured lifecycle script starts anothernpm installprocess in the same project. That nested installation can invoke the same lifecycle script again, resulting in recursive npm process creation.The behavior requires no malicious command-line input. It is triggered through the standard installation procedure documented by the project. Each process runs with the privileges of the user performing the installation.
Attack Path
- A user obtains the package and follows the documented installation instructions.
- The user runs
npm installin the project directory. - npm reaches the package lifecycle stage and executes the
installscript. - The script launches another
npm install. - The nested npm process executes the same lifecycle script, repeating the cycle.
- Recursive processes consume CPU, memory, process-table entries, and installation time until the operation fails, is terminated, or makes the host unstable.
Impact Assessment
The issue primarily affects availability. It can prevent installation and consume resources belonging to the current user. On constrained build agents, containers, or shared CI systems, it may terminate jobs or interfere with other workloads.
It does not independently grant elevated privileges, persistent access, or access beyond the permissions of the user running npm. Its scope is the local installation environment and any shared resources available to that environment.
- Remediation
View remediation
Remediation Suggestions
-
Remove the custom
installlifecycle script. npm already installs dependencies without this script. -
Retain only scripts that invoke the application directly, for example:
json "scripts": { "start": "node content-creator/index.js", "optimize": "node content-creator/index.js optimize", "generate": "node content-creator/index.js generate", "titles": "node content-creator/index.js titles", "hashtags": "node content-creator/index.js hashtags", "analyze": "node content-creator/index.js analyze" } -
Test installation in a clean, resource-limited container using
npm ci. -
Add CI validation that rejects lifecycle scripts which recursively invoke package installation.
-
Review all future npm lifecycle hooks because they execute automatically and with the installing user's privileges.
-
