[P0/严重] MCPManager stdio 子进程命令注入风险 #6

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

问题类型

安全漏洞 / 严重 / 后端服务

文件位置

electron/services/mcp-manager.service.ts

问题描述

MCPManager 启动 MCP Server 时通过 stdio 通信,使用 child_process.spawn(command, args)
commandargs 来自 MCP 配置文件(用户可编辑 / 第三方可篡改),未做:

  1. 命令白名单校验(如只允许 npx / node / python)
  2. 参数注入检测(如 ; && | $() shell metacharacters)
  3. PATH 环境变量劫持防护

恶意配置可执行任意命令:

{
  "command": "node; rm -rf /",
  "args": ["-e", "require('child_process').exec('malicious')"]
}

影响

  • 任意命令执行
  • 完全系统接管

建议修复

  1. 命令白名单:const ALLOWED_COMMANDS = new Set(['npx', 'node', 'python', 'python3', 'uvx']);
  2. 参数过滤:检测 shell 元字符并拒绝
  3. 使用 execFile 而非 spawn(不经过 shell)
  4. 限制工作目录为 workspace
  5. 不透传 process.env,只传必要的 PATH/HOME
## 问题类型 安全漏洞 / 严重 / 后端服务 ## 文件位置 `electron/services/mcp-manager.service.ts` ## 问题描述 MCPManager 启动 MCP Server 时通过 stdio 通信,使用 `child_process.spawn(command, args)`。 但 `command` 与 `args` 来自 MCP 配置文件(用户可编辑 / 第三方可篡改),未做: 1. 命令白名单校验(如只允许 npx / node / python) 2. 参数注入检测(如 `;` `&&` `|` `$()` shell metacharacters) 3. PATH 环境变量劫持防护 恶意配置可执行任意命令: ```json { "command": "node; rm -rf /", "args": ["-e", "require('child_process').exec('malicious')"] } ``` ## 影响 - 任意命令执行 - 完全系统接管 ## 建议修复 1. 命令白名单:`const ALLOWED_COMMANDS = new Set(['npx', 'node', 'python', 'python3', 'uvx']);` 2. 参数过滤:检测 shell 元字符并拒绝 3. 使用 `execFile` 而非 `spawn`(不经过 shell) 4. 限制工作目录为 workspace 5. 不透传 process.env,只传必要的 PATH/HOME
thzxx added the ???????????? labels 2026-07-21 21:55:37 +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#6