安全漏洞 / 严重 / 工具系统
electron/harness/tools/built-in/command.ts
project_memory.md 明确要求:
code-search must use execFile instead of exec to prevent command injection git tools must use execFile (not exec) to prevent command injection
但 RunCommandTool 仍使用 child_process.exec。exec 会经过 shell 解析,命令字符串中的 ; && | $() ` 等元字符会被 shell 解释,导致命令注入。
child_process.exec
;
&&
|
$()
`
即使 checkTokens 做了 token 分析,复杂的字符串拼接(如 r"m" -rf /)仍可绕过。
r"m" -rf /
import { execFile } from 'child_process'; // 修改前 exec(command, options, callback); // 修改后 execFile(command, argsArray, options, callback);
注意:
文件: electron/harness/tools/built-in/command.ts
问题: RunCommandTool 使用 child_process.exec,命令字符串经过 shell 解析,存在命令注入风险。即使有 checkTokens 和 validateCommand 双层校验,复杂的字符串拼接仍可能绕过。
checkTokens
validateCommand
修复方案:
parseCommandSimple(command)
shell-quote
{ command, args }
execFile
exec
设计决策: 完全改为 execFile 会破坏管道、重定向、Windows chcp 等功能。此方案在安全性(简单命令用 execFile)和兼容性(复杂命令保留 exec + 安全校验)之间取得平衡。
验证: tsc --noEmit 类型检查通过。
tsc --noEmit
No dependencies set.
The note is not visible to the blocked user.
问题类型
安全漏洞 / 严重 / 工具系统
文件位置
electron/harness/tools/built-in/command.ts问题描述
project_memory.md 明确要求:
但 RunCommandTool 仍使用
child_process.exec。exec 会经过 shell 解析,命令字符串中的;&&|$()`等元字符会被 shell 解释,导致命令注入。即使 checkTokens 做了 token 分析,复杂的字符串拼接(如
r"m" -rf /)仍可绕过。影响
建议修复
注意:
修复说明
文件:
electron/harness/tools/built-in/command.ts问题: RunCommandTool 使用
child_process.exec,命令字符串经过 shell 解析,存在命令注入风险。即使有checkTokens和validateCommand双层校验,复杂的字符串拼接仍可能绕过。修复方案:
parseCommandSimple(command)方法:用shell-quote解析命令,如果只包含 word tokens(无管道、重定向、&&等 shell 运算符),返回{ command, args }供execFile使用execFile(不经过 shell,从根本上防止注入)exec(已有 SandboxManager.scanCode + validateCommand 双层校验)execFile路径共享相同的 options(cwd/timeout/maxBuffer/encoding/env)设计决策: 完全改为 execFile 会破坏管道、重定向、Windows chcp 等功能。此方案在安全性(简单命令用 execFile)和兼容性(复杂命令保留 exec + 安全校验)之间取得平衡。
验证:
tsc --noEmit类型检查通过。