T08 · Insecure Dependencies
- Location
scripts/mock-server.sh:66- Finding
Unpinned npm Dependencies Allow Mutable Third-Party Code Execution
- Content
View full analysis
"$MOCK_DIR/package.json" << 'EOF' { "name": "appdev-mock-server", "version": "1.0.0", "dependencies": { "express": "^4.18.2", "cors": "^2.8.5", "body-parser": "^1.20.2" }, "devDependencies": { "nodemon": "^3.0.1" } } EOF cd "$MOCK_DIR" npm install cd .. ``` ### Technical Analysis The script dynamically creates a dependency manifest containing semver ranges and then invokes `npm install`. No reviewed lockfile or integrity-pinned installation is supplied with the project. The versions actually installed therefore depend on registry state at execution time. npm also permits package lifecycle scripts to execute during installation. A compromised direct or transitive dependency could run arbitrary commands with the privileges of the user invoking the script. Although this is not an explicit malicious payload embedded in the project, it creates a mutable code-execution path through third-party package infrastructure. ### Attack Path 1. An attacker compromises an allowed direct or transitive npm package version, or the corresponding registry account. 2. The malicious version remains compatible with one of the declared semver ranges. 3. A user runs: ```bash bash scripts/mock-server.sh init ``` or starts the server before the `mock` directory exists. 4. The script invokes `npm install`. 5. npm resolves the compromised package and executes any associated lifecycle scripts. 6. The dependency code runs with the developer account's filesystem and process privileges. ### Impact Assessment Successful exploitation could provide arbitrary code execution as the invoking user. This could expose source code, environment variables, development credentials, SSH material readable by that user, and writable project or ...[truncated 113 chars]- Remediation
View remediation
