Skip to content
jshacks.dev
Node.js

Node.js HTTPS Heap Leak From an Empty TLS Write Explained

How a zero-byte TLS write let HTTPS clients read Node.js server heap memory, which servers were exposed, and how to patch or mitigate it on 22, 24 and 26.

11 min read
Summarize in AI
Flat illustration of a shield with a lock, a key and a password field, with the Node.js, Let's Encrypt, OpenSSL and JSON Web Tokens logos.

CVE-2026-123864 is the most serious bug in the Node.js security release of 11 November 2026. An unauthenticated client of a Node.js HTTPS server could make the server copy its own heap into a request body, and the advisory says that memory can hold "TLS private keys and other users' requests". It affects every active line, and the fixed builds are Node.js 22.23.5, 24.22.3 and 26.13.1. The project rates it High rather than Critical because the server needs a specific handler shape before the leak can be read. This post walks through that shape, the mechanism behind it, how to tell whether your process was exposed, and what to do if you cannot deploy a new runtime today.

Who is exposed and who is not

Three things have to be true at once. The advisory states them plainly, and they are worth checking one by one before you panic or relax.

  1. Node.js terminates TLS itself, through https.createServer() or a framework that wraps it. Cleartext node:http is not affected, so a service behind nginx, HAProxy, a cloud load balancer or a service mesh sidecar that speaks plain HTTP to Node.js is out of scope for this CVE.

  2. Some handler calls res.flushHeaders() before the request body has finished arriving, then later calls res.end() with a non-empty chunk.

  3. Some route echoes or stores a request body, so the attacker can read back what the server put there. The advisory calls this "any ordinary route", and most APIs have one: a validation error that repeats the input, a paste or comment endpoint, a webhook log.

The second condition is the one that narrows things. flushHeaders() is not exotic. Server-sent event endpoints, long-polling handlers and progress streams call it so the client sees the status line before the first chunk of data. But the handler also has to finish with res.end(chunk) on a response that ends up writing zero bytes to the socket, and that is the trigger the rest of this post explains.

Release lines matter less than usual here, because the bug sits in shared HTTP parser and TLS code. The table shows the fixed build per line.

LineAffectedFirst fixed build
Node.js 22 (Jod LTS)yes22.23.5
Node.js 24 (Krypton LTS)yes24.22.3
Node.js 26 (Lithium LTS)yes26.13.1
Node.js 20 and olderend of life, no fixupgrade to a supported line

Later builds on each line, such as 24.23.0 and 26.14.0 from 30 November 2026, carry the fix as well, because release lines are cumulative.

The handler shape that sets it up

Here is a minimal handler with the shape the advisory describes. It is ordinary code. Nothing in it looks dangerous, which is why this class of bug gets through review.

src/server.mjsJavaScript
import { createServer } from 'node:https';
import { readFileSync } from 'node:fs';

const server = createServer(
  {
    key: readFileSync('certs/server-key.pem'),
    cert: readFileSync('certs/server-cert.pem'),
  },
  (req, res) => {
    // Send the status line early so slow uploads see a response start.
    res.flushHeaders();

    const chunks = [];
    req.on('data', (chunk) => chunks.push(chunk));
    req.on('end', () => {
      res.end('done');
    });
  },
);

server.listen(8443, () => {
  console.log('listening on https://localhost:8443');
});
Text
listening on https://localhost:8443

On its own this handler leaks nothing. The problem is what happens when res.end('done') ends up as a zero-length write on the TLS socket while the HTTP parser is still in the middle of reading the next request's body. The regression test that ships with the fix, test/parallel/test-https-empty-write-nested-parser-execute.js, gets there with a HEAD request. Node.js drops the body of a response to HEAD, so res.end('done') writes an empty string, and the 'end' handler runs from the tick queue while the body of a second pipelined request is being parsed.

What a zero-byte write did inside TLSWrap

Node.js wraps every TLS connection in a C++ class called TLSWrap. It reads encrypted records from the socket, decrypts them, and hands the cleartext to whatever listens on the stream. For an HTTPS server that listener is the HTTP parser, which runs llhttp over the bytes and calls back into JavaScript for headers and body chunks. The loop that pumps records through is called a cycle.

The bug was a shortcut in TLSWrap::DoWrite(). When asked to write zero bytes, it called ClearOut() directly, and ClearOut() decrypts the next pending TLS record and delivers it to the listener. That is harmless when the write comes from outside a cycle. It is not harmless when the write comes from JavaScript that is already running inside one, for example from the parser's on_body callback. The fix commit describes the result in its message: "For an HTTPS server this runs llhttp_execute() inside itself."

So the parser was re-entered. The inner llhttp_execute() call processed the next record from its own buffer and could stop halfway through a body chunk, leaving llhttp's record of where the current span starts pointing into the inner buffer. When the inner call returned, that buffer was freed. The outer call then reported the span against its own buffer and its own offsets. The bytes it passed up as request body were whatever sat at that address: freed memory or unrelated heap. In the commit's words, "the request body contains server heap memory, or the process aborts."

That is where the third precondition comes in. The leaked bytes land in req's data events as if the client had sent them. A route that echoes the body back, or stores it somewhere the attacker can read, hands the heap contents to the attacker. Because TLS keys, session state and other connections' buffers live in the same process heap, a patient client can sample it repeatedly. That is the same family as Heartbleed in 2014, reached through a very different path: an over-read of process memory returned in a normal-looking response.

What the fix changed

The patch, landed as "tls,http: prevent nested parser execution from empty writes" in all three lines, makes two changes. Either one would have closed the leak. Shipping both is defense in depth.

The first is in src/crypto/crypto_tls.cc. An empty write no longer reads ahead while a cycle is running:

src/crypto/crypto_tls.ccDiff
   if (length == 0) {
     Debug(this, "Empty write");
-    ClearOut();
+    if (cycle_depth_ == 0) ClearOut();
     if (BIO_pending(enc_out_) == 0) {

The cycle already reads and encrypts pending data once the JavaScript listener returns, so skipping the read here loses nothing. It only stops the next record from being delivered to a listener that is still handling the current one.

The second change is in src/node_http_parser.cc. Re-entrant Execute() calls stay legal, because JavaScript can push data into a socket synchronously from a callback. But each call now saves the caller's buffer pointer and length and restores them on return, instead of clearing them to null. And every data callback checks that the span it is about to report lies inside the buffer currently being executed. If it does not, the parser fails with the reason HPE_REENTRANT_EXECUTE:Parser re-entered in the middle of data instead of reading memory it does not own.

Check your exposure

Start with the runtime, because that is the fix. The small script below compares a version string against the first fixed build on its line and is safe to run in CI against every image you ship.

scripts/check-cve-2026-123864.mjsJavaScript
const FIXED = { 22: [23, 5], 24: [22, 3], 26: [13, 1] };

function status(version) {
  const [major, minor, patch] = version.replace(/^v/, '').split('.').map(Number);
  const fixed = FIXED[major];
  if (!fixed) return `${version}: unsupported line, upgrade`;
  const [fMinor, fPatch] = fixed;
  const ok = minor > fMinor || (minor === fMinor && patch >= fPatch);
  return `${version}: ${ok ? 'patched' : 'VULNERABLE'}`;
}

for (const v of ['v20.19.5', 'v22.23.4', 'v22.23.5', 'v24.22.2', 'v24.23.0', 'v26.13.1']) {
  console.log(status(v));
}
console.log(status(process.version));

On a machine running Node.js 24.22.2, the last line reports the local runtime, so its output differs on yours:

Text
v20.19.5: unsupported line, upgrade
v22.23.4: VULNERABLE
v22.23.5: patched
v24.22.2: VULNERABLE
v24.23.0: patched
v26.13.1: patched
v24.22.2: VULNERABLE

Check the runtime inside the container, not the one on your laptop. A FROM node:24 line in a Dockerfile resolves to whatever that tag pointed to on the day the image was built, and an image built in October still runs 24.22.x until you rebuild it.

Next, find out whether you terminate TLS in Node.js at all. Search the code for the HTTPS and TLS server constructors, and for the header flush that the trigger depends on:

Shell
grep -rnE "https\.createServer|createSecureServer|flushHeaders\(" --include=*.js --include=*.mjs --include=*.ts src

A hit list for a typical service with one server-sent events route looks like this, and yours will name your own files:

Text
src/server.mjs:4:const server = createServer(
src/routes/events.mjs:12:    res.flushHeaders();

No https.createServer hit means TLS ends somewhere else, and CVE-2026-123864 does not reach you, although other bugs in the same release might (see the HTTP/2 and TLS issues in the roundup of this release). A createSecureServer hit is HTTP/2, which does not use the HTTP/1 parser at the center of this bug. A flushHeaders() call in a service that does terminate TLS is the case to treat as exposed until the runtime is upgraded. Framework code counts too: run the same search across node_modules if a library might be flushing headers for you.

Patch first

The fix is the runtime upgrade, and nothing in user code replaces it. Move each line to its fixed build or later: 22.23.5, 24.22.3 or 26.13.1. On a version manager that is nvm install 24.22.3 or fnm install 24.22.3; in containers, pin the base image to a digest or a full version tag and rebuild. There are no API changes in these builds, so the usual risk of a patch upgrade is the dependency updates that rode along. The 24.22.3 release notes list llhttp 9.4.4, undici 7.30.2, sqlite 3.54.1 and brotli 1.2.1. Run your test suite against the new build and pay attention to anything that parses unusual HTTP framing, since a parser update can reject input the old one tolerated.

If you are still on Node.js 20, there is no build to install. It reached end of life on 30 April 2026, and the advisory repeats the project's standing rule that end-of-life versions are always affected by a security release. Plan the move to 24 now rather than looking for a workaround.

Mitigations while you cannot patch

These lower the risk. They do not remove it.

Terminating TLS in front of Node.js is the strongest one, because the advisory states cleartext node:http is unaffected. If you already run a reverse proxy, point it at a plain HTTP listener on the loopback interface and stop serving HTTPS from the Node.js process. That changes your threat model (traffic between the proxy and Node.js is now cleartext on that host), which is usually acceptable on loopback and not acceptable across a network you do not control.

The second is to stop flushing headers before the body is complete. For most request handlers the early flush buys nothing, and waiting for 'end' takes the handler out of the trigger shape:

src/routes/upload.mjsDiff
 export function upload(req, res) {
-  res.flushHeaders();
   const chunks = [];
   req.on('data', (chunk) => chunks.push(chunk));
   req.on('end', () => {
+    res.writeHead(200, { 'content-type': 'text/plain' });
     res.end('done');
   });
 }

Server-sent event routes need the early flush to work, but they rarely receive request bodies. If yours do not, rejecting requests with a body on those routes, and rejecting HEAD there, keeps the parser from ever being mid-body when the flush happens.

The third is to reduce what an attacker can read back. Routes that echo raw request bodies in error messages are worth fixing anyway. They are also the read side of this bug. Returning a fixed error string instead of the input closes the most common one.

None of these protects a server you have not audited, and dependencies can flush headers on your behalf. Treat them as a bridge to the upgrade, measured in days.

Detection and hardening

There is no reliable network signature for exploitation of the unpatched runtime, because the leaked bytes leave inside an ordinary encrypted response. What you can watch is the patched runtime. After the upgrade, a request that would have re-entered the parser fails with the code HPE_REENTRANT_EXECUTE, and server-side parser failures surface on the 'clientError' event:

src/client-errors.mjsJavaScript
export function logClientErrors(server, log = console) {
  server.on('clientError', (err, socket) => {
    log.warn(JSON.stringify({ code: err.code, reason: err.reason }));
    socket.destroy();
  });
}

If a client sends a pipelined sequence that hits the old trigger, the log line on a patched server reads:

Text
{"code":"HPE_REENTRANT_EXECUTE","reason":"Parser re-entered in the middle of data"}

A legitimate browser does not produce that pattern, so a burst of these lines from one address after the upgrade is someone testing for the bug. Alert on it.

If you ran an exposed configuration before upgrading, assume the TLS private key may have been read. Rotating the certificate and key is cheap compared with explaining later why you did not. Revoke the old certificate, issue a new key pair rather than reusing the old private key, and invalidate long-lived session tokens if any of them pass through request bodies on that server.

What this bug teaches

Three lessons carry over to code that has nothing to do with Node.js internals.

Re-entrancy is the bug, not the symptom. A callback that can trigger more input processing while the processor is mid-step needs either a guard that refuses the nested call or state that survives it. Node.js chose both: the TLS layer refuses to read ahead during a cycle, and the parser restores its caller's buffer. Your own event emitters, stream transforms and middleware chains have the same failure mode at a smaller scale.

Zero-length operations are edge cases that take shortcuts. DoWrite() treated an empty write as "nothing to send, so pump the reader instead", which is a reasonable optimization until it runs in the wrong context. When you write a fast path for an empty input, ask what state the caller is in.

Where TLS terminates is a security decision. Teams that end TLS at a proxy were not exposed to this CVE at all, while teams that terminate in Node.js for simplicity were. That is not an argument that one design is always right. It is an argument for knowing which one you run, and having the node --version of every TLS-terminating process in your inventory on the day a release like this lands.

Also inSecurity
Share

Keep reading

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.