[P0/严重] RunCommandTool 仍使用 exec 而非 execFile,违反硬性约束 #8

Open
opened 2026-07-21 21:55:39 +08:00 by thzxx · 0 comments
Owner

问题类型

安全漏洞 / 严重 / 工具系统

文件位置

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 解释,导致命令注入。

即使 checkTokens 做了 token 分析,复杂的字符串拼接(如 r"m" -rf /)仍可绕过。

影响

  • LLM 生成的恶意命令可执行任意操作
  • 系统完全接管风险

建议修复

import { execFile } from 'child_process';

// 修改前
exec(command, options, callback);

// 修改后
execFile(command, argsArray, options, callback);

注意:

  1. 需要重新设计命令解析逻辑,将 command + args 拆分为数组
  2. 不允许 shell 元字符(强制 execFile 行为)
  3. 更新测试用例
## 问题类型 安全漏洞 / 严重 / 工具系统 ## 文件位置 `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 解释,导致命令注入。 即使 checkTokens 做了 token 分析,复杂的字符串拼接(如 `r"m" -rf /`)仍可绕过。 ## 影响 - LLM 生成的恶意命令可执行任意操作 - 系统完全接管风险 ## 建议修复 ```ts import { execFile } from 'child_process'; // 修改前 exec(command, options, callback); // 修改后 execFile(command, argsArray, options, callback); ``` 注意: 1. 需要重新设计命令解析逻辑,将 command + args 拆分为数组 2. 不允许 shell 元字符(强制 execFile 行为) 3. 更新测试用例
thzxx added the ???????????? labels 2026-07-21 21:55:39 +08:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: MetonaTeam/metona-ai-desktop#8