fix: escape package names before shell interpolation in npm install (CWE-78)#341
Open
Matthew-Selvam wants to merge 1 commit into
Open
Conversation
…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
Author
|
This is ready for maintainer review whenever you get a chance — happy to make any changes requested. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #181.
install_npm_package,install_mcp_server, andinstallNpmPackagevalidate package names with/^[@a-zA-Z0-9._/-]+$/but interpolate them directly intonpm 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 totools-manager.ts, matching the pattern already used ingit/tools.tsandagent/tools.ts) at all 3 call sites:src/agent/tools.ts—install_npm_packagesrc/agent/tools.ts—install_mcp_serversrc/self-mod/tools-manager.ts—installNpmPackageTesting
tsc --noEmitpasses.tools-security.test.tsassertion that checked the literal exec command string, since escaping now quotes the package name (npm install -g axios→npm install -g 'axios').tools-security.test.ts; malicious-package-name tests for shell metacharacters still block as expected).