fix: shell-escape package names in npm install commands (CWE-78)#270
Open
aryannpanwarr wants to merge 1 commit into
Open
fix: shell-escape package names in npm install commands (CWE-78)#270aryannpanwarr wants to merge 1 commit into
aryannpanwarr wants to merge 1 commit into
Conversation
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>
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
install_npm_package,install_mcp_server(insrc/agent/tools.ts) andinstallNpmPackage(insrc/self-mod/tools-manager.ts) interpolate package names directly intonpm install -g ${pkg}shell commands/^[@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 bypassedtools.tsalready had a localescapeShellArg()function used elsewhere — it just wasn't applied to these 3 npm install call sitesChanges
escapeShellArgutility insrc/shell-escape.tsescapeShellArg()at all 3npm installcall sitestools-security.test.tsto match escaped outputTest plan
npx tsc --noEmitpasses (zero type errors)npx vitest run src/__tests__/tools-security.test.ts— 71/71 tests passCloses #181
🤖 Generated with Claude Code