> ## Documentation Index
> Fetch the complete documentation index at: https://writer.wjstar.top/llms.txt
> Use this file to discover all available pages before exploring further.

# React Server Components 远程代码执行漏洞分析

> React Flight Protocol 存在严重 RCE 漏洞，影响 Next.js 15.x/16.x 和 React 19.x，攻击者可通过构造恶意请求在服务器端执行任意代码。

## 漏洞概述

CVE-2025-55182 是一个影响 React Server Components (RSC) 架构的远程代码执行漏洞。攻击者可以通过构造恶意的 Flight Protocol 请求，在服务器端执行任意 JavaScript 代码。

如果你的出海项目使用 Next.js App Router 或 React 19 的 Server Components，需要检查是否受影响。

**受影响版本：**

* react-server-dom-webpack: 19.0.0 \~ 19.2.0
* react-server-dom-turbopack: 同上
* Next.js: 15.x、16.x（补丁前），以及 14.3.0-canary.77 之后的 canary 版本

**已修复版本：**

* React: 19.0.1+、19.1.2+、19.2.1+
* Next.js: 15.0.5、15.1.9、15.2.6、15.3.6、15.4.8、15.5.7、16.0.7+

## 漏洞原理

这个漏洞的根源在于 React Flight Protocol 处理序列化数据时的信任问题。安全研究员 [ejpir](https://github.com/ejpir/CVE-2025-55182-research) 和 [maple3142](https://gist.github.com/maple3142) 披露了完整的利用链。

攻击分为三个阶段：

### 1. 路径遍历获取 Function 构造器

攻击者使用 `$1:constructor:constructor` 格式的引用，通过原型链遍历访问到 JavaScript 的 `Function` 构造器。漏洞代码位于 `getOutlinedModel()` 函数：

```javascript theme={null}
// 漏洞代码：没有验证属性是否为对象自身属性
for (key = 1; key < reference.length; key++)
  parentObject = parentObject[reference[key]];  // 可遍历原型链
```

### 2. 伪造 Chunk 对象注入

攻击者构造一个特殊的对象，通过自引用的 `then` 属性（`$@0` 指向自身）伪装成 Promise。当 React 尝试 await 这个对象时，会调用 `Chunk.prototype.then`，此时攻击者注入的 `_response` 数据被当作真实响应处理。

表单字段结构：

```
Field 0: {"then":"$1:__proto__:then", "status":"resolved_model", ...}
Field 1: "$@0"    ← 指向 Field 0，形成循环引用
Field 2: []       ← 空数组，用于 _chunks Map
```

### 3. \$B 处理器触发代码执行

`$B` 处理器原本用于处理 Blob 数据，但在攻击链中被利用来调用 `Function` 构造器：

```javascript theme={null}
// parseModelString() 中的漏洞代码
case "B":
  return response._formData.get(response._prefix + obj);  // 执行 Function(code)
```

## 为什么 WAF 拦不住

传统基于签名匹配的 WAF 对这个漏洞基本无效，原因有两个：

### Unicode 编码绕过

JSON 和 JavaScript 都支持 Unicode 转义。WAF 检查的是原始 HTTP 数据，而服务器解码后才处理：

| 原始 Payload      | 编码形式                              | WAF 能否匹配 |
| --------------- | --------------------------------- | -------- |
| `constructor`   | `\u0063onstructor`                | 否        |
| `__proto__`     | `\u005f\u005fproto\u005f\u005f`   | 否        |
| `child_process` | `String.fromCharCode(99,104,...)` | 否        |

### 超大 Payload 绕过

AWS WAF 等产品对请求体检查有大小限制（通常 8KB 或 16KB）。攻击者在恶意代码前填充足够的垃圾数据，超出检查范围的部分会被放行。

## 修复方案

### 升级依赖（推荐）

React 19.2.1 的补丁包含四项修复：

1. 使用 `RESPONSE_SYMBOL` 替代直接访问 `chunk._response`，Symbol 无法通过 JSON 伪造
2. 在 `getOutlinedModel()` 添加 `hasOwnProperty` 检查，阻止原型链遍历
3. 在 `reviveModel()` 中过滤 `__proto__` 属性
4. 验证 listener 类型必须为函数

升级命令：

```bash theme={null}
# npm
npm update next react react-dom

# pnpm
pnpm update next react react-dom

# 验证版本
npm ls next react
```

升级后检查 `package-lock.json` 或 `pnpm-lock.yaml`，确认实际安装的版本。

### 临时缓解措施

如果暂时无法升级：

* **禁用 Server Actions**：在网关层阻断带有 `Next-Action` 请求头的 POST 请求
* **调整 WAF 策略**：将超大请求体的处理策略从 `CONTINUE` 改为 `BLOCK`
* **运行时监控**：hook `Function` 构造器和 `child_process` 模块，记录异常调用

这些措施只能降低风险，不能完全阻止攻击。

## 参考资料

* [CVE-2025-55182 研究仓库](https://github.com/ejpir/CVE-2025-55182-research)
* [maple3142 的利用链分析](https://gist.github.com/maple3142)
