CVE-2026-123874: Node.js HTTP/2 Use-After-Free -- respondWithFile() and the Missing Stream Reference

The advisory

Node.js shipped security releases on November 2026 covering several HTTP/2 vulnerabilities. CVE-2026-123874 stood out: a use-after-free in the HTTP/2 server that lets an unauthenticated client corrupt heap memory when the application serves files with stream.respondWithFile() or stream.respondWithFD(). CVSS 7.5 High (AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H). The fix commit included an in-tree test, but it used duplexPair (an in-process mock transport) and --expose-gc, so it never sent traffic over the network.

I built a network-based PoC that sends real HTTP/2 frames, confirmed the heap-use-after-free with AddressSanitizer, and captured the attack traffic in a pcap.

PoC, detection rules, and live pcap: al4n4n/achilles-heel/CVE-2026-123874

How Node.js serves files over HTTP/2

To understand the bug, you need to know how respondWithFile() works under the hood, and why it behaves differently from the more common respond() or pipe() patterns.

Node.js HTTP/2 is built on nghttp2, the C library that handles frame parsing, flow control, and stream state. On top of that, Node.js adds its own C++ layer (Http2Session, Http2Stream) that bridges nghttp2 into V8’s event loop and garbage collector. This layer is where the bug lives.

When a Node.js HTTP/2 server calls stream.respondWithFile(path), the file is not piped through JavaScript. Instead, the native layer opens the file through a FileHandle, reads chunks into ArrayBuffer backing stores via FileHandle::ReadStart(), and pushes them onto the session’s outgoing_buffers_ queue as NgHttp2StreamWrite structs. Each struct holds two references: a req_wrap (the write request) and a buffer_owner (ownership of the backing store memory). The session then calls uv_write to send the buffered data to the TCP socket.

This is efficient. The file data flows from disk to the network through native buffers, bypassing JavaScript entirely. But there is a gap: NgHttp2StreamWrite does not hold a reference to the Http2Stream itself. The struct knows about the write request and the buffer, but not about the stream that originated the response.

In normal operation this is fine. The HTTP/2 session holds the stream, and the stream lives as long as the session or until the response finishes. The JavaScript application typically holds a reference to the stream too, since it called respondWithFile() on it. But with respondWithFile(), the response continues asynchronously at the native level, and the JavaScript reference can go out of scope before the writes complete.

HTTP/2 gives clients a tool to break the assumption that the stream outlives its writes: RST_STREAM. Any client can cancel any stream at any time by sending a RST_STREAM frame with error code 0x8 (CANCEL). The server must honor it.

The vulnerable code

Here is the path through src/node_http2.cc before the fix. When OnSendData pushes a buffer for a respondWithFile() response:

1
2
3
4
5
6
// src/node_http2.cc (before fix)
outgoing_buffers_.emplace_back(NgHttp2StreamWrite {
req_wrap, // the write request
buf_owner // owns the backing store
// <-- no stream reference
});

The NgHttp2StreamWrite struct (from src/node_http2.h) had no Http2Stream field:

1
2
3
4
5
struct NgHttp2StreamWrite {
BaseObjectPtr<AsyncWrap> req_wrap;
BaseObjectPtr<BackingStore> buf_owner;
// Missing: no BaseObjectPtr<Http2Stream> to prevent GC
};

Compare with the fix:

1
2
3
4
5
struct NgHttp2StreamWrite {
BaseObjectPtr<AsyncWrap> req_wrap;
BaseObjectPtr<BackingStore> buf_owner;
BaseObjectPtr<Http2Stream> stream; // <-- THE FIX
};

One field. That is the entire difference between a safe server and a use-after-free.

The race

With respondWithFile(), the server pushes large file buffers onto the outgoing queue and starts writing them to the socket asynchronously via uv_write. The write is non-blocking; libuv assembles an array of iovec entries (each pointing to a backing store and giving its length) and passes them to the kernel’s writev syscall when the socket file descriptor becomes writable. For a large file, the write queue may contain dozens of iovec entries spanning megabytes of data, and the kernel may take several event loop iterations to drain them all.

Now consider what happens when a client sends RST_STREAM (CANCEL) while those writes are pending:

  1. The server processes RST_STREAM and closes the stream.
  2. The stream’s JavaScript wrapper loses its references.
  3. V8’s garbage collector runs and collects the Http2Stream C++ object.
  4. Http2Stream::CompleteDestroyCleanup runs, destroying the SimpleWriteWrap objects and freeing the backing stores (BackingStore::~BackingStore calls free).
  5. The pending uv_write callback fires. writev reads from the iovec, which still points to the freed backing store.

Step 5 is a textbook use-after-free. The iovec contains a pointer and a length for a 64 KB buffer that no longer exists.

Building the lab

The challenge was making the race reliable. Understanding the bug is one thing; observing it is another. On localhost, TCP writes complete almost instantly because there is no network latency; the kernel socket buffer is large enough to absorb the entire write in one writev call before the event loop returns to process the stream destruction. Without intervention, even if GC frees the backing store, the freed region still contains the original file data (the allocator does not zero it), and writev reads it successfully. The corruption is invisible.

I needed three things: a way to force GC to run between the RST_STREAM and the write callback, a file large enough to keep the write queue busy across multiple event loop iterations, and AddressSanitizer to poison freed memory so the access becomes observable as a crash instead of a silent read.

The lab server (lab/server.js) is a minimal HTTP/2 server that serves a 64 MB file via respondWithFile(). It runs with --expose-gc and --max-old-space-size=64 (constraining V8’s heap to 64 MB), and a timer calls global.gc() every 5 milliseconds. These are not default settings, and they would not be present in production. They exist to close the race window: forcing frequent garbage collection makes the stream wrapper get collected while writes are still pending, and the large file keeps writes queued long enough for GC to run.

The ASAN build was compiled from the Node.js 24.22.2 source with ./configure --enable-asan and clang 18 on Ubuntu 24.04 (x86_64). AddressSanitizer replaces the standard allocator with one that quarantines freed memory and fills it with the poison byte 0xfd. When writev reads from a freed backing store, it hits poisoned memory and ASAN traps the access, printing a detailed report with the allocation, free, and access stack traces. Without ASAN, the same read would succeed silently because the freed memory still holds the file data, and the program would continue with corrupted internal state.

The crash

On the first run, the ASAN server crashed. From evidence/target-asan-crash.txt:

1
2
3
4
5
6
7
8
==3444471==ERROR: AddressSanitizer: heap-use-after-free on address 0x531000465630 [...]
READ of size 12752 at 0x531000465630 thread T0
#0 [...] in read_iovec [...]
#1 [...] in writev [...]
#2 [...] in uv__writev deps/uv/src/unix/stream.c:665
#3 [...] in uv__try_write deps/uv/src/unix/stream.c:812
#4 [...] in uv__write deps/uv/src/unix/stream.c:861
#5 [...] in uv__stream_io deps/uv/src/unix/stream.c:1233

The access: writev reads 12,752 bytes from an iovec pointing into a freed 64 KB region.

1
2
3
4
5
freed by thread T0 here:
#0 [...] in free [...]
#1 [...] in v8::internal::BackingStore::~BackingStore() [...]
#2 [...] in non-virtual thunk to node::SimpleWriteWrap<[...]>::~SimpleWriteWrap() [...]
#3 [...] in node::http2::Http2Stream::CompleteDestroyCleanup()::$_0 node_http2.cc

The free: CompleteDestroyCleanup is the callback that runs when the Http2Stream is garbage-collected. It destroys the write wraps, which free their backing stores.

1
2
3
4
previously allocated by thread T0 here:
[...]
#5 [...] in node::Environment::allocate_managed_buffer [...]
#6 [...] in node::fs::FileHandle::ReadStart() [...]

The allocation: FileHandle::ReadStart() allocated the buffer when reading the file for respondWithFile().

This is the complete causal chain. The buffer was created for the file response, freed when the stream was garbage-collected after RST_STREAM, and read by the pending socket write. The ASAN shadow memory around the buggy address is all fd (freed heap region):

1
2
3
4
Shadow bytes around the buggy address:
0x531000465580: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
=>0x531000465600: fd fd fd fd fd fd[fd]fd fd fd fd fd fd fd fd fd
0x531000465680: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd

The PoC result from evidence/poc-vuln-asan.txt:

1
2
3
4
5
6
CVE-2026-123874 PoC Results
Target: 127.0.0.1:9082
Rounds: 1
Hits: 1/1
Result: VULNERABLE -- server crashed 1/1 rounds
Impact: Denial of service (memory corruption / crash)

Negative control

The same PoC against Node.js 24.22.3 (the first patched version):

1
2
3
4
5
CVE-2026-123874 PoC Results
Target: 127.0.0.1:9081
Rounds: 5
Hits: 0/5
Result: Not vulnerable (or not triggered in 5 rounds)

Five rounds, 2,500 streams opened and reset, zero crashes. The fix works.

Impact

The advisory rates this CVSS 7.5 High with an availability impact of High and no confidentiality or integrity impact. That matches what I observed: the use-after-free corrupts heap memory and crashes the server (denial of service). The read-after-free does not leak data to the attacker because the corrupted data stays inside the server process, in the writev iovec, and is never sent back to the client. The corruption happens inside libuv’s write path, in kernel-side writev, reading from an iovec that points to freed userspace memory.

Any Node.js HTTP/2 server that calls respondWithFile() or respondWithFD() is affected. These APIs are the recommended way to serve static files over HTTP/2 in Node.js. The http2 module documentation explicitly suggests respondWithFile() for serving static content because it avoids the overhead of reading the file through JavaScript streams. Web frameworks and static file servers built on Node.js HTTP/2 are the most likely targets.

The attack requires no authentication. The client sends only standard HTTP/2 frames: HEADERS to open streams and RST_STREAM to cancel them. No special headers, no crafted payloads, no session state. Any HTTP/2 client library can produce these frames, and there is nothing unusual about RST_STREAM CANCEL in normal HTTP/2 traffic (browsers send it when navigating away from a page).

In practice, the bug is harder to trigger without the lab’s forced GC and constrained heap. A production server with a large default heap (around 1.5 GB) and no --expose-gc will have less frequent garbage collection, making the race window narrower. The race requires GC to run between the RST_STREAM processing (which drops the stream references) and the libuv write callback (which reads from the buffer). On localhost, TCP writes complete almost instantly, so GC rarely gets a chance. Over a real network with latency, the write takes longer and the window widens. Under sustained load with many concurrent connections and large file transfers, natural memory pressure can trigger GC at the right moment. Without ASAN, the corruption is silent unless the freed region is reallocated and overwritten before writev reads it, or unless the heap metadata around the freed region is corrupted enough to crash the allocator.

Claim Status Evidence
Heap-use-after-free (ASAN, crash, 1/1) Proven evidence/target-asan-crash.txt
Root cause confirmed by ASAN stack trace Proven evidence/target-asan-crash.txt
Attack is unauthenticated (AV:N, PR:N) Proven No credentials in PoC
Patched version unaffected (0/5) Confirmed evidence/poc-patched.txt
Remote code execution Not reached CVSS vector is C:N/I:N/A:H

Detection

Two experimental / minimally validated rule sets, each tested against the canonical attack capture and one benign fixture only:

Suricata (detection/cve-2026-123874.rules): alerts on a burst of 20 or more HTTP/2 RST_STREAM CANCEL frames from a single client within 10 seconds. Not specific to this CVE. Requires Suricata 7.0+ with HTTP/2 app-layer enabled; TLS inspection needed for h2 (as opposed to h2c).

Sigma (detection/cve-2026-123874-crash.yml): detects a Node.js HTTP/2 server crash (ASAN heap-use-after-free, SIGSEGV, or SIGABRT) with concurrent ERR_HTTP2_STREAM_CANCEL in the application log. Requires ASAN builds or crash-producing heap layouts to fire.

The fix

Commit 8e100ac by Matteo Collina adds one field to NgHttp2StreamWrite:

1
BaseObjectPtr<Http2Stream> stream;

This BaseObjectPtr is a release-prevented reference. As long as any NgHttp2StreamWrite in outgoing_buffers_ holds a pointer to the stream, V8’s garbage collector cannot collect it. The stream stays alive until its write buffers are consumed and dequeued, at which point the BaseObjectPtr destructor releases the reference and the stream can be collected normally.

The fix also simplifies HasWritesOnSocketForStream to use wr.stream.get() instead of walking the session’s stream map, since the stream reference is now directly available in each write buffer.

Advisory and fix

Date Event
November 2026 Node.js security release advisory published
November 2026 Node.js 24.22.3 and 26.13.1 released with the fix
2026-11-16 Reproduction and write-up

Reproduction

Readers can verify every claim in this post by running the PoC from the repository. The ASAN proof requires building Node.js from source with --enable-asan on a Linux x86_64 host.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
git clone https://github.com/al4n4n/achilles-heel.git
cd achilles-heel/CVE-2026-123874

# Start the lab
python3 setup.py

# Check vulnerability
python3 check.py --target 127.0.0.1:9080

# Trigger (against ASAN target)
python3 poc.py --target 127.0.0.1:9082 --rounds 5 \
--pid-file /tmp/server.pid --server-log /tmp/server.log

# Negative control (patched)
python3 poc.py --target 127.0.0.1:9081 --rounds 5

# Teardown
python3 setup.py --down

The full evidence, detection rules, and live pcap are in the repository: al4n4n/achilles-heel/CVE-2026-123874.