Skip to content

fix: escape package names before shell interpolation in npm install (CWE-78)#341

Open
Matthew-Selvam wants to merge 1 commit into
Conway-Research:mainfrom
Matthew-Selvam:fix/181-npm-install-command-injection
Open

fix: escape package names before shell interpolation in npm install (CWE-78)#341
Matthew-Selvam wants to merge 1 commit into
Conway-Research:mainfrom
Matthew-Selvam:fix/181-npm-install-command-injection

Conversation

@Matthew-Selvam

Copy link
Copy Markdown

Summary

Fixes #181. install_npm_package, install_mcp_server, and installNpmPackage validate package names with /^[@a-zA-Z0-9._/-]+$/ but interpolate them directly into npm install -g ${pkg} without shell escaping. The regex allows / (path-like input), and a regex change or bypass would immediately expose the injection surface.

Fix

Wrap the already-validated package name with the existing escapeShellArg() helper (added locally to tools-manager.ts, matching the pattern already used in git/tools.ts and agent/tools.ts) at all 3 call sites:

  • src/agent/tools.tsinstall_npm_package
  • src/agent/tools.tsinstall_mcp_server
  • src/self-mod/tools-manager.tsinstallNpmPackage

Testing

  • tsc --noEmit passes.
  • Updated the existing tools-security.test.ts assertion that checked the literal exec command string, since escaping now quotes the package name (npm install -g axiosnpm install -g 'axios').
  • Full test suite passes (71/71 in tools-security.test.ts; malicious-package-name tests for shell metacharacters still block as expected).

…CWE-78)

Wraps the already-validated package name with escapeShellArg() before
interpolating into 'npm install -g' at all 3 call sites
(install_npm_package, install_mcp_server, installNpmPackage), as
defense-in-depth alongside the existing character-class validation.

Fixes Conway-Research#181
@Matthew-Selvam

Copy link
Copy Markdown
Author

This is ready for maintainer review whenever you get a chance — happy to make any changes requested.

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