Skip to content

fix: shell-escape package names in npm install commands (CWE-78)#270

Open
aryannpanwarr wants to merge 1 commit into
Conway-Research:mainfrom
aryannpanwarr:fix/shell-escape-npm-install
Open

fix: shell-escape package names in npm install commands (CWE-78)#270
aryannpanwarr wants to merge 1 commit into
Conway-Research:mainfrom
aryannpanwarr:fix/shell-escape-npm-install

Conversation

@aryannpanwarr

Copy link
Copy Markdown

Summary

  • install_npm_package, install_mcp_server (in src/agent/tools.ts) and installNpmPackage (in src/self-mod/tools-manager.ts) interpolate package names directly into npm install -g ${pkg} shell commands
  • While a regex guard (/^[@a-zA-Z0-9._/-]+$/) exists, defense-in-depth requires shell escaping as a second layer to prevent command injection if the regex is ever relaxed or bypassed
  • tools.ts already had a local escapeShellArg() function used elsewhere — it just wasn't applied to these 3 npm install call sites

Changes

  • Add shared escapeShellArg utility in src/shell-escape.ts
  • Apply escapeShellArg() at all 3 npm install call sites
  • Update test expectation in tools-security.test.ts to match escaped output

Test plan

  • npx tsc --noEmit passes (zero type errors)
  • npx vitest run src/__tests__/tools-security.test.ts — 71/71 tests pass

Closes #181

🤖 Generated with Claude Code

The install_npm_package, install_mcp_server, and installNpmPackage
functions interpolated package names directly into shell commands.
While a regex guard exists, defense-in-depth requires shell escaping
as a second layer to prevent command injection.

- Add shared escapeShellArg utility in src/shell-escape.ts
- Apply escapeShellArg at all 3 npm install call sites
- Update test expectation to match escaped output

Closes Conway-Research#181

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Security: Unescaped package names in npm install commands (CWE-78)

1 participant