Skip to content

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
quangtran88:fix/shell-injection-tools
Open

fix: add escapeShellArg to read_file, pull_upstream, and npm install commands (CWE-78)#184
quangtran88 wants to merge 1 commit intoConway-Research:mainfrom
quangtran88:fix/shell-injection-tools

Conversation

@quangtran88
Copy link
Contributor

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: Escape filePath in cat shell fallback (line 174)
  • pull_upstream: Add runtime commit hash validation (/^[a-f0-9]{7,40}$/) + escape with escapeShellArg() + use -- separator in git cherry-pick (lines 526-530)
  • install_npm_package: Escape pkg in npm install -g (line 447)
  • install_mcp_server: Escape pkg in npm install -g (line 850)

src/self-mod/tools-manager.ts:

  • Add local escapeShellArg() utility function
  • installNpmPackage: Escape packageName in npm 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

…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
@quangtran88 quangtran88 force-pushed the fix/shell-injection-tools branch from bed799c to f14af30 Compare February 22, 2026 04:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant