fix: add escapeShellArg to read_file, pull_upstream, and npm install commands (CWE-78)#184
Open
quangtran88 wants to merge 1 commit intoConway-Research:mainfrom
Open
Conversation
…commands (CWE-78) Wraps user-controlled strings in shell-safe single quotes before interpolation into shell commands: - read_file: filePath in cat fallback - pull_upstream: commit hash in git cherry-pick - install_npm_package: packageName in npm install -g (tools.ts and tools-manager.ts) Also adds commit hash format validation (hex 7-40 chars) to pull_upstream. Closes Conway-Research#179, Conway-Research#180, Conway-Research#181
bed799c to
f14af30
Compare
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
Defense-in-depth: wrap user-controlled parameters with
escapeShellArg()at execution time in addition to existing policy-layer validation. Prevents command injection if policy rules are bypassed or misconfigured.Changes
src/agent/tools.ts:read_file: EscapefilePathincatshell fallback (line 174)pull_upstream: Add runtime commit hash validation (/^[a-f0-9]{7,40}$/) + escape withescapeShellArg()+ use--separator ingit cherry-pick(lines 526-530)install_npm_package: Escapepkginnpm install -g(line 447)install_mcp_server: Escapepkginnpm install -g(line 850)src/self-mod/tools-manager.ts:escapeShellArg()utility functioninstallNpmPackage: EscapepackageNameinnpm install -g(line 37)Security Impact
All 5 locations previously interpolated parameters directly into shell commands. While policy-layer validation (regex,
validate.git_hash,validate.package_name) provides first-line defense, these parameters were unescaped at execution time. A policy bypass or misconfiguration would immediately expose command injection.Closes #179, closes #180, closes #181