Lab PoC for CVE-2026-96889: Next.js Image Optimization SVG typed as AVIF reaches librsvg UAF (RUSTSEC-2026-0305). Unauthenticated RCE on glibc Linux.
Lab proof of concept for unauthenticated RCE (or DoS) through Next.js
/_next/image on glibc Linux. Run it only against systems you own.
A document that starts <!--ftypavif--> is a legal SVG, but Next's magic
sniffer types it as image/avif. AVIF is not in BYPASS_TYPES, so the buffer
reaches sharp → libvips → librsvg. librsvg then frees an xmlEntity that
libxml2 is still using (RUSTSEC-2026-0305).
Usable for RCE on official non-PIE node v24.20.0 and v22.23.3 (same chain, different addresses). node v20.20.2 is DoS only (SIGSEGV). sharp 0.35.5 (librsvg 2.63.2) is immune.
| GHSA | GHSA-2464-fhr4-w9xw |
| CVE | CVE-2026-96889 |
| Severity | Critical, CVSS 9.5 |
| Affected | next >= 10.0.0 <= 15.5.27, > 16.0.0 <= 16.4.0 |
| Fixed | next 15.5.28 / 16.4.1 (pins sharp >= 0.35.5) |
| Platform | glibc Linux |
| Workaround | sharp >= 0.35.5. images.unoptimized: true also removes the surface. |
The 16.4.1 / 15.5.28 patches do not change content-type sniffing. A
deployment that upgraded Next but left sharp at 0.35.4 is still vulnerable.
Check the decoder (sharp.versions / /sharpinfo), not the Next version string.
Supported is the vendor advisory: next >= 10.0.0 <= 15.5.27 and
> 16.0.0 <= 16.4.0, glibc Linux, sharp < 0.35.5. Tested is what
this repo actually ran.
| Version | This lab | |
|---|---|---|
| next | 16.4.0 + sharp 0.35.4 | UAF probe + RCE (app/) |
| next | 15.5.27 + sharp 0.35.4 | same rce.svg, no padding change (app15/) |
| next | 16.4.1 + sharp 0.35.5 | fixed (payload rasterizes) |
| next | 16.4.1 + sharp 0.35.4 | vulnerable again (sniffing unchanged) |
| next | 15.5.28 (stock) | vendor pin sharp >= 0.35.5; patched HTTP run is 16.4.1 |
| next | 10.0.0 – 15.5.26 | advisory range, not re-run |
| sharp | 0.35.4 → libvips 8.18.6 / librsvg 2.62.91 | fires (harness/vuln) |
| sharp | 0.35.5 → libvips 8.18.7 / librsvg 2.63.2 | clean (harness/fixed) |
| node | official linux-x64 v24.20.0 (non-PIE EXEC) | RCE |
| node | official linux-x64 v22.23.3 | RCE (same chain, different addresses) |
| node | official linux-x64 v20.20.2 | DoS (SIGSEGV) |
| OS | glibc x86-64 Linux | required for the shipped ROP tables |
PIE / musl / self-built node binaries are outside the shipped tables; extract
addresses with harness/find-gadgets.py. 15.x also needs a sharp build that
reports heif (canDecodeAvif); this lab's 0.35.4 reports heif 1.23.2.
| Library | librsvg (Rust, statically linked into libvips), not sharp and not Next |
| Sharp advisory | GHSA-wq5f-xc86-pv6w (sharp < 0.35.5) |
| RustSec | RUSTSEC-2026-0305, Use-after-free when XML includes have duplicated entities |
| Fix | librsvg 2.63.2 (8a1b0cd3 — “no longer frees xmlEntity pointers still owned by libxml2”) |
| Versions used here | sharp 0.35.4 → libvips 8.18.6 / librsvg 2.62.91 (vulnerable); sharp 0.35.5 → libvips 8.18.7 / librsvg 2.63.2 (fixed) |
Mechanism: recursive XInclude. The inner document redeclares an entity name
that already exists. librsvg and libxml2 share one entity map;
entity_insert() frees the outer xmlEntity that xmlCtxtParseEntity() is
still using.
N ≤ 4 duplicate-name pairs rasterize on both builds; N ≥ 5 they split.
The vulnerable build fails with PCDATA invalid Char value 0.
.svg never hits this 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 is copied back untouched. sharp is never called.
AVIF detection in detect-content-type.js is:
if ([0,0,0,0,'f','t','y','p','a','v','i','f'].every((b,i)=>!b || buffer[i]===b))
return _imagetype.AVIF
The first four bytes are wildcards. Bytes 4..11 can live in an XML comment:
<!--ftypavif--><svg ...>
Then:
image/avif → not in BYPASS_TYPES → sharp → librsvgimage/svg* → dangerouslyAllowSVG is never consulted (stock config works)<?xml …?>
declaration: if it is not at byte 0, librsvg errors with
XML declaration allowed only at the start of the documentAVIF is the only magic check where “starts with <!--” and “reaches sharp”
are both true. HEIC has the same wildcard but is in BYPASS_TYPES.
imageOptimizerTransform() catches optimizer failures and returns the
upstream buffer with the upstream type, still HTTP 200. Do not look at the
status code.
| File | sharp 0.35.4 | sharp 0.35.5 |
|---|---|---|
avif-control.svg (valid SVG, no entity) | 200 image/jpeg | 200 image/jpeg |
avif-uaf-5.svg (5 pairs) | 200 image/avif — body is the payload itself | 200 image/jpeg |
plain-baseline.svg (real SVG) | 400 (dangerouslyAllowSVG: false) | 400 |
Vulnerable: the body starts with <!--ftypavif-->. A raster never does.
The control must rasterize too: the same catch also fires when sharp is not
installed, so a text fallback alone is ambiguous.
Fetch in this order: liveness → payload → control. The control is itself an SVG parse and moves the heap, so it goes last.
The optimizer caches rasters on disk per url+w+q. After a key has succeeded
once, later requests never reach librsvg. q is restricted to
images.qualities (default: 75). Force a cold fetch with --w, which must be
one of images.imageSizes / deviceSizes.
Public PoCs for this librsvg UAF (EQSTLab CVE-2026-94545
and others) target next/og (ImageResponse). exploit.mjs uses the same
inner documents and padding, with an outer wrapper of <!--ftypavif--> +
<xi:include> so the bytes reach /_next/image.
| Prerequisite | non-PIE node binary (official linux-x64 tarballs are Type: EXEC), glibc, x86-64 Linux. No leak — addresses are compile-time constants |
| Gadgets | From official node v24.20.0 / v22.23.3. Built-in tables in exploit.mjs; extract more with harness/find-gadgets.py |
| Carrier | ROP chain (≤ 60 qwords) as shortest IEEE-754 decimal text inside <path d="…">. 8 bytes ↔ double ↔ text is lossless |
| Command length | ≤ 71 bytes |
| Verification | Out of band. execve replaces the worker; stdout never returns in the HTTP response. The connection drops |
| node | sharp / librsvg | Result |
|---|---|---|
| 24.20.0 | 0.35.4 / 2.62.91 | RCE |
| 22.23.3 | 0.35.4 / 2.62.91 | RCE (same chain shape, different addresses) |
| 20.20.2 | 0.35.4 / 2.62.91 | DoS (SIGSEGV). Call slot does not land on the chain |
| 24.20.0 | 0.35.5 / 2.63.2 | Rasterized, process lives |
Without --table, exploit.mjs tries 24 → 22 → 20 and waits --restart-wait
(default 25 s) between shots for the host to bring the worker back.
The same payload file works on Next 16.4.0 and 15.5.27 with no padding change. 16.4.1 + sharp 0.35.5 is fixed; 16.4.1 with sharp swapped back to 0.35.4 is usable again.
The command bytes shift the ROP doubles inside the buffer. If a given
--command only crashes, change the spelling (spaces around > are free) or
--pad and retry after the worker restarts. Misses are SIGSEGV.
The payload cannot ride in the URL (data: is rejected; url is capped at
3072 chars). The target has to be able to fetch the file.