T08 · Insecure Dependencies
- Location
scripts/start_mock.sh:43- Finding
Automatic Installation of an Unpinned Global npm Package
- Content
View full analysis
/dev/null; then echo "Prism not found — installing @stoplight/prism-cli globally..." npm install -g @stoplight/prism-cli fi ``` ### Technical Analysis The script automatically installs the latest available version of `@stoplight/prism-cli` from the configured npm registry. It does not specify an exact version, use a lockfile, verify package integrity, or request confirmation immediately before changing the global npm environment. An npm installation can execute package lifecycle scripts. Consequently, compromise of the upstream package, one of its transitive dependencies, the registry configuration, or the package maintainer account could result in arbitrary code execution. Global installation also changes shared user or system state beyond the project directory. Although Prism is legitimately required for the declared mock-server functionality, automatic global installation exceeds the minimum privilege needed. A project-local, version-pinned dependency would provide the same functionality with less risk. ### Attack Path 1. An attacker compromises the Prism package, one of its transitive dependencies, or the npm registry configured in the execution environment. 2. The attacker publishes malicious code under a version selected by the unpinned package request. 3. A user runs `scripts/start_mock.sh` on a system where `prism` is not already available. 4. The script invokes `npm install -g @stoplight/prism-cli`. 5. Malicious lifecycle or runtime code executes with the privileges of the user running the script. 6. If the script is run through an elevated shell, the malicious package may obtain system-wide privileges. ### Impact Assessment Successful exploitation can execute arbitra ...[truncated 625 chars]- Remediation
View remediation
``` 2. Commit `package.json` and `package-lock.json`, then use: ```bash npm ci --ignore-scripts ``` If lifecycle scripts are required, review them before enabling them. 3. Execute the project-local binary: ```bash npx --no-install prism mock "$SPEC" --port "$PORT" ``` 4. Do not perform automatic global installation inside the launcher. If the dependency is missing, exit with installation instructions or require explicit user confirmation. 5. Use npm integrity metadata, dependency scanning, and a trusted registry configuration. 6. Run the mock server as an unprivileged user and avoid invoking the script with `sudo`. ]]>
