Skip to content
Memory corruption Write-up Advanced

CVE-2026–111497 (Node2Shell): Anatomy of a Brotli Decoder Memory-Corruption Vulnerability

Vedic_error Follow

Published on medium.com

Cybersecurity

Vedic_error, on medium.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 13 min read.

Context

Brotli is a lossless compression algorithm used widely to shrink data in transit between clients, servers and services. Node.js ships a native implementation of it, exposed to JavaScript through the node:zlib module, which offers synchronous, asynchronous and stream-based interfaces for both compression and decompression.

CVE-2026-111497, which the author calls Node2Shell, is a memory-safety flaw in the Brotli decoder bundled with affected Node.js releases. The problem is incorrect handling of decoder state during a block-switch operation, which can lead to an out-of-bounds memory write. The research below is a source-level analysis plus a controlled denial-of-service reproduction on Node.js 22.23.3. It does not demonstrate remote code execution.

All work was carried out in an isolated laboratory environment for vulnerability analysis, education and defensive research.

From the original on medium.com

Setup

The practical test used the public PoC repository CVE-2026-111497-POC and its stock Node.js 22.23.3 Docker fixture, run on a local Kali Linux host.

Component Configuration
Host OS Kali Linux
Container runtime Docker 28.5.2
Node.js version 22.23.3
Architecture Linux x86-64
Base image Pinned Node.js image digest
Application port TCP 3000
Host binding [redacted]:3000
PoC repository CVE-2026-111497-POC

The fixture's Dockerfile uses a pinned image, copies the application source into /app, switches to the unprivileged node user and starts the application with:

Text
CMD ["node", "/app/src/server.js"]

The container was launched with a localhost-only port binding plus these restrictions:

  • Read-only container filesystem
  • All Linux capabilities dropped
  • no-new-privileges enabled
  • Process, memory and CPU limits
  • Temporary filesystem mounted at /tmp

That kept the demonstration away from the host and stopped the application port from being reachable from the wider network.

Finding it

The starting point was a baseline test of the normal API, to confirm the expected behaviour of Brotli compression and decompression inside the isolated Node.js environment:

JavaScript
const zlib = require("node:zlib");const input = Buffer.from("Hello, Brotli! This is a baseline test.");const compressed = zlib.brotliCompressSync(input);const decompressed = zlib.brotliDecompressSync(compressed);console.log("Original:", input.toString());console.log("Compressed size:", compressed.length, "bytes");console.log("Decompressed:", decompressed.toString());console.log("Round-trip:", input.equals(decompressed));
Artifact-1 From the original on medium.com

Artifact-1

The compression produced a 43-byte buffer, decompression reconstructed the original input and the equality check returned true. That is the expected behaviour for valid data. The point of interest is that the decoding itself happens in native code, so input handling and decoder state are the parts that matter.

Artifact-2 From the original on medium.com

Artifact-2

Enumerating the API showed six Brotli interfaces in the runtime:

  • brotliDecompressSync(): synchronous decompression.
  • brotliDecompress(): asynchronous decompression.
  • createBrotliDecompress(): a transform stream for decompression.
  • brotliCompressSync(): synchronous compression.
  • brotliCompress(): asynchronous compression.
  • createBrotliCompress(): a transform stream for compression.

Input accepted through any of these high-level calls can end up in native code, where buffer boundaries and state transitions are managed differently from ordinary JavaScript. The investigation focused on the decompression pipeline.

Tracing the interface in src/node_zlib.cc from the Node.js v22.23.3 source tree led to the BrotliDecoderContext class, which holds the decoder state and initialises, processes and closes the decoding context. Its DoThreadPoolWork() method calls BrotliDecoderDecompressStream(), passing stream data into the underlying Brotli decoding routine. Node keeps input and output buffer pointers and their length variables, and retrieves decoder-specific error information when the routine reports an error, translating it into the surrounding native compression framework.

That establishes the architectural boundary: Node.js owns the decoder context and the buffers handed to the native routine, while the Brotli decoder performs the stream processing. The wrapper alone cannot explain the root cause, so the decoder implementation and the security patch had to be examined.

Artifact-3 From the original on medium.com

Artifact-3

The trust boundary can be drawn at a high level as:

Application-provided data → Node.js node:zlib interface → Native decoder context → Brotli stream processing

The JavaScript wrapper selects the operation and initialises the native context; the native layer processes the compressed data while tracking buffers and state. The existence of this boundary does not by itself make an application vulnerable. Exposure depends on the input source, how decompression is invoked, the runtime version and the decoder's behaviour.

The decoder is stateful

Artifact-4: The BrotliRunningState enumeration defines the decoder's primary execution states, from initialization and metablock processing to compressed-data handling and completion. This illustrates the stateful nature of Brotli's streaming decoder. From the original on medium.com

Artifact-4: The BrotliRunningState enumeration defines the decoder's primary execution states, from initialization and metablock processing to compressed-data handling and completion. This illustrates the stateful nature of Brotli's streaming decoder.

The bundled decoder's state structure explicitly documents support for partial streaming decoding: decompression need not finish in a single call, so the decoder preserves progress and resumes when more input or output capacity arrives. The state.h header defines a BrotliRunningState enumeration covering the major stages: initialisation, metablock parsing, compressed metablock handling, Huffman code processing, context map processing, command execution, output handling and completion. Additional substates cover metablock headers, Huffman processing, context maps, tree groups and block lengths.

Stateful native parsers deserve particular scrutiny: correctness depends not only on validating individual inputs but on preserving valid invariants as execution moves between states.

Exploitation

Step 1: Understand the decoder's input buffer

The decoder keeps a temporary input buffer in its state structure:

Text
union {  uint64_t u64;  uint8_t u8[8];} buffer;brotli_reg_t buffer_length;

The accompanying comment describes it as temporary storage for remaining input, with eight bytes considered sufficient for the decoder to make progress. Depending on its current state, the bit reader works either directly on caller-provided input or on data retained in this internal buffer, and buffer_length tracks how much is retained. Several paths reset, refill or consume the buffer as processing advances.

This creates an invariant: the decoder's processing state and its reported input status must stay consistent with the constraints of the internal buffering mechanism.

Step 2: Compare the block-switch error handling before and after the patch

The pre-patch DecodeBlockTypeAndLength() returned a Boolean. The patched version returns a BrotliDecoderErrorCode, and that change propagates through the literal, command and distance block-switch handling functions. Instead of collapsing the outcome to true or false, the patched code preserves the decoder's specific status.

The distinction matters because decoder outcomes are not interchangeable: the decoder may need more input to continue, or it may hit a format condition that should be reported as an error. The patch introduces explicit status propagation through the block-switch path so the surrounding logic can tell these apart.

The real problem was not the return value itself but how it influenced later behaviour. An invalid block-switch condition was misinterpreted as a temporary shortage of input. Rather than terminating with a format error, the streaming decoder treated the condition as a request for more data, so additional input kept accumulating in the internal eight-byte buffer. That violated the buffer's storage constraints and produced an out-of-bounds write.

Step 3: Note the corrective change

The patch introduces BROTLI_SAFE_WITH_STATUS, which propagates the returned decoder status through the surrounding processing logic. This differs from the existing Boolean-oriented handling, which was built around operations whose failure could be treated as a need for more input. The patch also adds a specific format-error classification for block-switch handling. Together these change the decoder's error-handling contract and its interaction with the state machine.

Step 4: Examine the test application

The fixture's server.js uses native networking and compression modules:

JavaScript
const net = require('node:net');const zlib = require('node:zlib');

It creates a TCP server and initialises a Brotli decompression stream:

JavaScript
const decoder = zlib.createBrotliDecompress();

It listens on TCP port 3000:

JavaScript
}).listen(3000, '[redacted]');

Rather than HTTP, the fixture speaks a small length-prefixed TCP protocol: the server reads a four-byte frame header followed by the corresponding frame body. Received data goes into the Brotli decoder; the first frame is processed through decoder.write() and the subsequent frame through decoder.end(). That makes it a convenient network-facing way to observe decoder behaviour.

Step 5: Verify connectivity

The container exposed its application port as:

Text
[redacted]:3000 -> 3000/tcp

A harmless zero-length frame was sent with Python:

Python
import socket
Python
with socket.create_connection(("[redacted]", 3000), timeout=3) as s:    s.sendall(b"\x00\x00\x00\x00")    print(s.recv(64).decode(errors="replace").strip())

The server replied:

Text
PONG

So the TCP service was reachable and responding before the vulnerability test.

Step 6: Run the PoC

With the container running and connectivity confirmed, the repository's PoC was executed against the stock Node.js 22.23.3 x86-64 profile:

Bash
python3 poc.py --profile node-22.23.3-bookworm-x86_64

It returned:

Text
PASS: DoS verified through the declared network interfaceprofile=node-22.23.3-bookworm-x86_64trigger_sha256=[redacted]=service unavailable

The PoC reported that its denial-of-service postcondition had been met.

Step 7: Verify independently

Rather than trusting the PoC's success message, the container state was checked directly:

Bash
sudo docker ps -a

The output showed:

Text
CONTAINER ID   IMAGE                             STATUS3630d89fe4f3   cve-2026-111497-lab:v22.23.3     Exited (139) 46 seconds ago

The container had terminated with exit code 139. On Linux that status is conventionally associated with signal 11 (SIGSEGV), a segmentation fault, which is consistent with an abnormal native-process termination rather than an ordinary application-level error.

The combined evidence:

Verification Result
Initial TCP connectivity Successful
Initial application response PONG
PoC execution PASS
PoC postcondition Service unavailable
Container state after execution Exited
Container exit code 139

The stock Node.js 22.23.3 environment could be driven into a denial-of-service condition through its Brotli decompression interface. The abnormal termination is the most significant observation, and the exit code adds evidence beyond the PoC's own message. This is not remote code execution: the tested profile demonstrates denial of service only, and the result reflects one specific runtime and application configuration, not every Node.js application that uses Brotli decompression.

The PoC output and Docker exit status are runtime observations. They show the failure condition; the precise memory-corruption mechanism has to be established separately through source-level analysis.

Root cause

The decoder's block-switch handling reduced its result to a Boolean, so an invalid block-switch condition was indistinguishable from a temporary lack of input. The streaming decoder therefore asked for more data instead of raising a format error, kept appending input to the internal eight-byte buffer, overran it and wrote out of bounds. The patch fixes this by returning and propagating BrotliDecoderErrorCode through the literal, command and distance block-switch functions, using BROTLI_SAFE_WITH_STATUS, and by adding a dedicated format-error classification for block-switch handling.

Impact

The demonstrated impact on the tested stock Node.js 22.23.3 profile is denial of service: malformed Brotli input causes the process to terminate. The underlying flaw is an out-of-bounds write in the native decoder, which the author notes can potentially lead to denial of service, memory disclosure or remote code execution. Reports of code execution on other versions or configurations exist but are outside what this research independently verifies; the advisory's maximum severity should be treated as RCE-capable, while the demonstrated impact here is DoS.

Exposure depends on whether an application decompresses attacker-influenced data, how it invokes decompression, and which runtime version it runs.

Fix

The primary remediation is to upgrade Node.js to a release containing the fix. The Node.js project published security releases on 21 October 2026 covering the affected lines:

Node.js release line Minimum fixed release
22.x 22.23.4
24.x 24.22.1
26.x 26.12.1

Deploy the latest supported security release for your line rather than pinning to the minimum. End-of-life versions should be migrated to a supported release. The fix came through an upstream Brotli change plus a corresponding Node.js source change, and the decoder now distinguishes an invalid block-switch condition from a temporary shortage of input.

For containers, upgrading Node.js on the host is not enough: the application image must be rebuilt from a patched base image and redeployed, because existing containers keep running the code in their original image.

Verifying the fix

A version check is a start:

Bash
node --version

But the Brotli version alone is not sufficient. Node.js maintainers confirmed the update was applied as a cherry-pick, so process.versions.brotli can keep reporting an earlier upstream version even when the build contains the fix. A more useful capability check is whether the patched releases expose the new decoder error constant:

JavaScript
const zlib = require('node:zlib');
JavaScript
const hasFixMarker =  Object.prototype.hasOwnProperty.call(    zlib.constants,    'BROTLI_DECODER_ERROR_FORMAT_BLOCK_SWITCH'  );console.log({  nodeVersion: process.version,  brotliVersion: process.versions.brotli,  fixMarkerPresent: hasFixMarker});

The presence of BROTLI_DECODER_ERROR_FORMAT_BLOCK_SWITCH is a useful indicator for builds that include the change. It should complement, not replace, checking the official release version or the OS vendor's advisory; third-party Brotli libraries and vendor-patched builds may need their own verification.

Runtime identification

From the original on medium.com

The official Node.js 22.23.4 release exposes the new constant through node:zlib. The capability check was run against both Docker images:

JavaScript
const zlib = require('node:zlib');
JavaScript
console.log(  process.version,  Object.hasOwn(    zlib.constants,    'BROTLI_DECODER_ERROR_FORMAT_BLOCK_SWITCH'  ));

The affected Node.js 22.23.3 image returned:

Text
v22.23.3 false

The patched Node.js 22.23.4 image returned:

Text
v22.23.4 true

So the affected baseline does not expose the new error classification and the patched release does. Because the fix was cherry-picked, the embedded Brotli version string does not necessarily change, which is why this check is more reliable than process.versions.brotli alone. It is not a complete behavioural regression test: the constant confirms the exposed interface, not how the runtime handles the problematic input.

Temporary restrictions

If an affected runtime cannot be upgraded immediately, disabling Brotli decompression for untrusted input is a practical stopgap. Review every place compressed data enters the system: HTTP request bodies, uploaded or externally supplied files, data from upstream services, message queues and other asynchronous ingestion pipelines, and components that decompress through a library or middleware.

Where Brotli-encoded HTTP request bodies are accepted, a reverse proxy or web application firewall can temporarily reject requests containing:

HTTP
Content-Encoding: br

Apply this carefully, since it also blocks legitimate Brotli-encoded requests. An edge rule also does not protect against Brotli data from upstream services or decoded through other pathways; an HTTP client may process compressed response data independently of inbound request handling. Treat header filtering as a compensating control, not a replacement for upgrading the decoder.

Defence in depth

  • Input and decompression limits: cap compressed input size, decompressed output size, processing time and concurrent decompression operations. This reduces resource exhaustion but does not guarantee protection against memory corruption.
  • Least privilege: run Node.js processes under unprivileged OS accounts with only the filesystem and network permissions they need.
  • Container isolation: run as non-root, drop unnecessary capabilities, avoid privileged containers, use read-only filesystems where possible, restrict access to host resources and sensitive mounts, and apply CPU and memory limits. These reduce the consequences of a compromised process but do not stop the decoder from hitting the flaw.

Detection and monitoring

Inventory Node.js services that use Brotli decompression, including through third-party dependencies. Review direct usage such as:

Text
zlib.brotliDecompress()zlib.brotliDecompressSync()zlib.createBrotliDecompress()

Also examine middleware, HTTP clients and other libraries that decompress internally. Software composition analysis and image scanning help, but scanners should account for vendor backports and cherry-picked fixes rather than relying on an upstream version string.

Unexpected process termination is a useful indicator. In the lab, Docker reported:

Text
Exited (139)

On Linux, exit status 139 is consistent with termination by signal 11 (SIGSEGV). In production, correlate this with unexpected Node.js exits, container restart loops, health-check failures, sudden HTTP 5xx responses or connection resets, OS crash reports or core dumps, and the requests or ingestion events immediately before the failure. Exit code 139 alone is not proof of exploitation; a segmentation fault has many causes, so investigate alongside logs, process telemetry and request history.

Where Brotli-encoded request bodies are accepted, monitoring requests with Content-Encoding: br shows which services receive compressed input. The header is not malicious by itself, since Brotli is a legitimate format used by normal traffic. The goal is to spot unexpected decoder failures and tie them to the input-processing path.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 26 min read.

What happened, in plain words

A security researcher found a bug in Node.js, a popular program that lets people run JavaScript code on a server (the computer that answers requests from your browser). The bug lives in a part of Node.js that unpacks compressed data, a technique called Brotli. When the unpacking code is fed a specially crafted, broken piece of compressed data, it can write past the end of a small internal memory area. In the researcher's test, that made the whole Node.js program crash. A crash like this is called a denial of service: the service stops working for everyone using it.

The bug has an official identifier, CVE-2026-111497, and the researcher nicknamed it Node2Shell. The name hints at something scarier than a crash, because a memory bug like this can sometimes be turned into running an attacker's own code on the server. The researcher is careful to say that the test only demonstrated the crash, not code execution. The full technical report is a deep dive into the source code, the fix, and a controlled lab reproduction. This article walks through the same material for someone who has never studied security before.

From the original on medium.com

Background: what is compression, and why does it matter?

When you load a web page, the server often sends the data squeezed down to a smaller size so it travels faster. That squeezing is compression. The browser unpacks it on arrival. The same trick is used between servers, inside apps, and in almost every modern system.

Brotli is one particular compression method. It is lossless, meaning the original data comes back exactly as it went in, with nothing thrown away. Node.js includes Brotli built in, so a programmer does not need to install anything extra to use it.

Node.js offers Brotli through a module called node:zlib. A module is a bundle of ready-made functions you can load into your program. The module gives you three styles of use:

  • Synchronous: your program waits until the job is done before moving on.
  • Asynchronous: your program starts the job and continues doing other things while it finishes.
  • Stream-based: data flows through in pieces, like water through a pipe, rather than all at once.

CVE-2026-111497 is a memory-safety flaw in the Brotli decoder (the unpacking half) that ships inside affected Node.js releases. The specific problem is that the decoder mishandles its own internal state during a step called a block-switch, and that mistake can lead to an out-of-bounds memory write. An out-of-bounds write means the program stores data in a memory slot it was never supposed to touch, potentially overwriting something important nearby.

The research below is a source-level analysis (reading the actual program code) plus a controlled reproduction of the crash on Node.js 22.23.3. It does not demonstrate remote code execution, which would mean an attacker running their own commands on the server.

All work was carried out in an isolated laboratory environment for vulnerability analysis, education and defensive research. Isolated means the test machine was deliberately cut off from the rest of the world so nothing could escape by accident.

Setup: the lab

The practical test used a public proof-of-concept repository called CVE-2026-111497-POC. A proof of concept, or PoC, is a small program that demonstrates a bug really exists. The repository also included a Docker fixture. Docker is a tool that packages an application and everything it needs into a self-contained box called a container, so it runs the same way everywhere. A fixture here means a ready-made test setup.

The test ran on a local Kali Linux host. Kali Linux is a Linux distribution aimed at security testing. A host is the physical or virtual machine running everything else.

Component Configuration
Host OS Kali Linux
Container runtime Docker 28.5.2
Node.js version 22.23.3
Architecture Linux x86-64
Base image Pinned Node.js image digest
Application port TCP 3000
Host binding [redacted]:3000
PoC repository CVE-2026-111497-POC

A few of those terms deserve a plain explanation. Architecture, here x86-64, is the family of processor the code is built for. A base image is the starting template a container is built from. Pinned means the exact version was locked down so it could not change between runs. A digest is a fingerprint of that exact image. A port is a numbered doorway on a computer that network traffic can arrive at; TCP 3000 means the TCP protocol on port 3000. The binding [redacted]:3000 means the port was only reachable from the same machine, because [redacted] is the address a computer uses to talk to itself.

The fixture's Dockerfile (the recipe for building the container) uses a pinned image, copies the application source into /app, switches to the unprivileged node user and starts the application with:

Text
CMD ["node", "/app/src/server.js"]

Line by line: CMD tells Docker what command to run when the container starts. "node" is the Node.js program itself. "/app/src/server.js" is the file inside the container that Node.js should execute. The node user is a low-privilege account, so even if something goes wrong inside the container, it does not have the powers of an administrator.

The container was launched with a localhost-only port binding plus these restrictions:

  • Read-only container filesystem
  • All Linux capabilities dropped
  • no-new-privileges enabled
  • Process, memory and CPU limits
  • Temporary filesystem mounted at /tmp

A read-only filesystem means the container cannot modify its own files. Capabilities are fine-grained administrator powers in Linux; dropping them all removes those powers. no-new-privileges stops a process from gaining extra rights later. Process, memory and CPU limits cap how much of the machine the container can consume. A temporary filesystem at /tmp gives the app a scratch area that is wiped when the container stops.

That kept the demonstration away from the host and stopped the application port from being reachable from the wider network. In other words, even if the bug had done something unexpected, it would have been trapped inside the box.

Finding it: first, prove the normal case works

The starting point was a baseline test of the normal API, to confirm the expected behaviour of Brotli compression and decompression inside the isolated Node.js environment. An API, in this context, is simply the set of functions a program offers to other code. Before hunting for a bug, you want to know what correct behaviour looks like, so you can tell the difference later.

JavaScript
const zlib = require("node:zlib");const input = Buffer.from("Hello, Brotli! This is a baseline test.");const compressed = zlib.brotliCompressSync(input);const decompressed = zlib.brotliDecompressSync(compressed);console.log("Original:", input.toString());console.log("Compressed size:", compressed.length, "bytes");console.log("Decompressed:", decompressed.toString());console.log("Round-trip:", input.equals(decompressed));
Artifact-1 From the original on medium.com

Artifact-1

Line by line:

  1. const zlib = require("node:zlib"); loads the built-in compression module and stores it in a variable called zlib.
  2. const input = Buffer.from("Hello, Brotli! This is a baseline test."); turns a piece of text into a Buffer, which is Node.js's way of holding raw bytes.
  3. const compressed = zlib.brotliCompressSync(input); squeezes those bytes with Brotli and stores the result.
  4. const decompressed = zlib.brotliDecompressSync(compressed); unpacks the squeezed bytes back into their original form.

The compression produced a 43-byte buffer, decompression reconstructed the original input and the equality check returned true. That is the expected behaviour for valid data. The point of interest is that the decoding itself happens in native code, so input handling and decoder state are the parts that matter. Native code means code written in a lower-level language such as C or C++, compiled directly for the processor, rather than JavaScript. It is faster, but it also has to manage memory by hand, and that is where memory-safety bugs live.

Artifact-2 From the original on medium.com

Artifact-2

Enumerating the API showed six Brotli interfaces in the runtime. Enumerating just means listing them all out. The runtime is the environment your code runs inside, here Node.js itself.

  • brotliDecompressSync(): synchronous decompression.
  • brotliDecompress(): asynchronous decompression.
  • createBrotliDecompress(): a transform stream for decompression.
  • brotliCompressSync(): synchronous compression.
  • brotliCompress(): asynchronous compression.
  • createBrotliCompress(): a transform stream for compression.

A transform stream is an object that data flows through, changing as it goes. Input accepted through any of these high-level calls can end up in native code, where buffer boundaries and state transitions are managed differently from ordinary JavaScript. A buffer boundary is the edge of a fixed-size memory area; going past it is exactly the kind of mistake that causes memory corruption. The investigation focused on the decompression pipeline, because that is the half that handles data coming in from outside.

Tracing the interface in src/node_zlib.cc from the Node.js v22.23.3 source tree led to the BrotliDecoderContext class. A class is a blueprint in code that bundles data and the functions that work on it. This one holds the decoder state and initialises, processes and closes the decoding context. Its DoThreadPoolWork() method calls BrotliDecoderDecompressStream(), passing stream data into the underlying Brotli decoding routine. A method is a function that belongs to a class. Node keeps input and output buffer pointers and their length variables, and retrieves decoder-specific error information when the routine reports an error, translating it into the surrounding native compression framework.

That establishes the architectural boundary: Node.js owns the decoder context and the buffers handed to the native routine, while the Brotli decoder performs the stream processing. The wrapper alone cannot explain the root cause, so the decoder implementation and the security patch had to be examined. A wrapper is code that sits around another piece of code and calls it on your behalf.

Artifact-3 From the original on medium.com

Artifact-3

The trust boundary can be drawn at a high level as:

Application-provided data → Node.js node:zlib interface → Native decoder context → Brotli stream processing

A trust boundary is the line where data stops being trusted and starts being handled by code that must defend itself. On the left, data comes from the application, possibly from an attacker. On the right, native code processes it. The JavaScript wrapper selects the operation and initialises the native context; the native layer processes the compressed data while tracking buffers and state. The existence of this boundary does not by itself make an application vulnerable. Exposure depends on the input source, how decompression is invoked, the runtime version and the decoder's behaviour.

The decoder is stateful

Artifact-4: The BrotliRunningState enumeration defines the decoder's primary execution states, from initialization and metablock processing to compressed-data handling and completion. This illustrates the stateful nature of Brotli's streaming decoder. From the original on medium.com

Artifact-4: The BrotliRunningState enumeration defines the decoder's primary execution states, from initialization and metablock processing to compressed-data handling and completion. This illustrates the stateful nature of Brotli's streaming decoder.

Stateful means the decoder remembers where it is between calls, like a reader who puts a bookmark in a book and continues later. The bundled decoder's state structure explicitly documents support for partial streaming decoding: decompression need not finish in a single call, so the decoder preserves progress and resumes when more input or output capacity arrives. The state.h header defines a BrotliRunningState enumeration covering the major stages: initialisation, metablock parsing, compressed metablock handling, Huffman code processing, context map processing, command execution, output handling and completion. An enumeration is a fixed list of named values. A header is a file that declares things other files can use. Additional substates cover metablock headers, Huffman processing, context maps, tree groups and block lengths.

Stateful native parsers deserve particular scrutiny: correctness depends not only on validating individual inputs but on preserving valid invariants as execution moves between states. An invariant is a rule that must always stay true. If a stateful parser lets an invariant slip, the damage can appear far from the input that caused it.

Exploitation: how the bug actually works

Step 1: Understand the decoder's input buffer

The decoder keeps a temporary input buffer in its state structure:

Text
union {  uint64_t u64;  uint8_t u8[8];} buffer;brotli_reg_t buffer_length;

Line by line: union is a C construct where several types share the same memory. Here the same eight bytes can be read either as one 64-bit number (uint64_t u64) or as eight separate bytes (uint8_t u8[8]). buffer is the name of that storage. brotli_reg_t buffer_length; is a variable that records how many bytes are currently held in the buffer.

The accompanying comment describes it as temporary storage for remaining input, with eight bytes considered sufficient for the decoder to make progress. Depending on its current state, the bit reader works either directly on caller-provided input or on data retained in this internal buffer, and buffer_length tracks how much is retained. A bit reader is the part of a decoder that pulls individual bits out of the incoming stream. Several paths reset, refill or consume the buffer as processing advances.

This creates an invariant: the decoder's processing state and its reported input status must stay consistent with the constraints of the internal buffering mechanism. In everyday terms, the buffer is a small cup that holds at most eight bytes. If the code ever believes it can pour more in, the cup overflows.

Step 2: Compare the block-switch error handling before and after the patch

A block-switch is a point in the compressed stream where the decoder changes which table it uses to interpret the data. The pre-patch DecodeBlockTypeAndLength() returned a Boolean. A Boolean is a value that can only be true or false. The patched version returns a BrotliDecoderErrorCode, and that change propagates through the literal, command and distance block-switch handling functions. An error code is a specific label saying exactly what went wrong, rather than a vague yes or no. Instead of collapsing the outcome to true or false, the patched code preserves the decoder's specific status.

The distinction matters because decoder outcomes are not interchangeable: the decoder may need more input to continue, or it may hit a format condition that should be reported as an error. Think of a shop assistant who can only answer yes or no. Asked "is this form filled in correctly?", they say no, and you cannot tell whether the form is wrong or simply incomplete. The patch introduces explicit status propagation through the block-switch path so the surrounding logic can tell these apart.

The real problem was not the return value itself but how it influenced later behaviour. An invalid block-switch condition was misinterpreted as a temporary shortage of input. Rather than terminating with a format error, the streaming decoder treated the condition as a request for more data, so additional input kept accumulating in the internal eight-byte buffer. That violated the buffer's storage constraints and produced an out-of-bounds write. In plain terms, the decoder kept pouring more into the cup because it thought it was still thirsty, and the cup overflowed into neighbouring memory.

Step 3: Note the corrective change

The patch introduces BROTLI_SAFE_WITH_STATUS, which propagates the returned decoder status through the surrounding processing logic. This differs from the existing Boolean-oriented handling, which was built around operations whose failure could be treated as a need for more input. The patch also adds a specific format-error classification for block-switch handling. Together these change the decoder's error-handling contract and its interaction with the state machine. A state machine is a model of a system as a set of states and the allowed moves between them; the decoder is one.

Step 4: Examine the test application

The fixture's server.js uses native networking and compression modules:

JavaScript
const net = require('node:net');const zlib = require('node:zlib');

Line by line: the first line loads Node.js's built-in networking module, which lets the program open network connections. The second loads the compression module, as before.

It creates a TCP server and initialises a Brotli decompression stream:

JavaScript
const decoder = zlib.createBrotliDecompress();

A TCP server is a program that listens for incoming network connections using the TCP protocol. This line creates the decompression stream that will receive whatever arrives.

It listens on TCP port 3000:

JavaScript
}).listen(3000, '[redacted]');

.listen(3000, '[redacted]') tells the server to accept connections on port 3000 from any network address. Inside the container that is fine, because the container itself was only reachable from the host.

Rather than HTTP, the fixture speaks a small length-prefixed TCP protocol: the server reads a four-byte frame header followed by the corresponding frame body. HTTP is the protocol browsers use to fetch web pages; this fixture uses a simpler custom protocol instead. Length-prefixed means the first few bytes say how long the rest of the message is, so the receiver knows when it has the whole thing. A frame is one such complete message. Received data goes into the Brotli decoder; the first frame is processed through decoder.write() and the subsequent frame through decoder.end(). write() feeds more data into the stream, and end() says no more is coming. That makes it a convenient network-facing way to observe decoder behaviour.

Step 5: Verify connectivity

The container exposed its application port as:

Text
[redacted]:3000 -> 3000/tcp

This says that port 3000 on the host forwards to port 3000 inside the container, and only on the loopback address 127.0.0.1.

A harmless zero-length frame was sent with Python:

Python
import socket
Python
with socket.create_connection(("[redacted]", 3000), timeout=3) as s:    s.sendall(b"\x00\x00\x00\x00")    print(s.recv(64).decode(errors="replace").strip())

Line by line: import socket loads Python's networking library. socket.create_connection(("[redacted]", 3000), timeout=3) opens a connection to port 3000 on the local machine, giving up after three seconds. s.sendall(b"\x00\x00\x00\x00") sends four zero bytes, which is a frame header saying the body is empty. s.recv(64) reads up to 64 bytes of reply, .decode(errors="replace") turns them into text, and .strip() removes surrounding whitespace.

The server replied:

Text
PONG

So the TCP service was reachable and responding before the vulnerability test. This step matters because, without it, a later failure could just mean the network was broken rather than the bug being triggered.

Step 6: Run the PoC

With the container running and connectivity confirmed, the repository's PoC was executed against the stock Node.js 22.23.3 x86-64 profile:

Bash
python3 poc.py --profile node-22.23.3-bookworm-x86_64

Line by line: python3 runs the Python interpreter. poc.py is the proof-of-concept script. --profile node-22.23.3-bookworm-x86_64 selects a named test profile, here the stock Node.js 22.23.3 build on the Debian release codenamed bookworm, for 64-bit x86 processors.

It returned:

Text
PASS: DoS verified through the declared network interfaceprofile=node-22.23.3-bookworm-x86_64trigger_sha256=[redacted]=service unavailable

This output says the denial-of-service condition was verified through the network interface the profile declares. trigger_sha256 is a fingerprint of the exact input that triggered the crash, so the test can be repeated with the same bytes. postcondition=service unavailable means the expected end state, the service being down, was reached. The PoC reported that its denial-of-service postcondition had been met.

Step 7: Verify independently

Rather than trusting the PoC's success message, the container state was checked directly:

Bash
sudo docker ps -a

sudo runs the command with administrator rights. docker ps -a lists all containers, including stopped ones.

The output showed:

Text
CONTAINER ID   IMAGE                             STATUS3630d89fe4f3   cve-2026-111497-lab:v22.23.3     Exited (139) 46 seconds ago

The container had terminated with exit code 139. An exit code is the number a program returns when it finishes, and it tells you how it ended. On Linux that status is conventionally associated with signal 11 (SIGSEGV), a segmentation fault, which is consistent with an abnormal native-process termination rather than an ordinary application-level error. A segmentation fault happens when a program tries to touch memory it is not allowed to touch, and the operating system stops it immediately.

The combined evidence:

Verification Result
Initial TCP connectivity Successful
Initial application response PONG
PoC execution PASS
PoC postcondition Service unavailable
Container state after execution Exited
Container exit code 139

The stock Node.js 22.23.3 environment could be driven into a denial-of-service condition through its Brotli decompression interface. The abnormal termination is the most significant observation, and the exit code adds evidence beyond the PoC's own message. This is not remote code execution: the tested profile demonstrates denial of service only, and the result reflects one specific runtime and application configuration, not every Node.js application that uses Brotli decompression.

The PoC output and Docker exit status are runtime observations. They show the failure condition; the precise memory-corruption mechanism has to be established separately through source-level analysis.

Root cause

The decoder's block-switch handling reduced its result to a Boolean, so an invalid block-switch condition was indistinguishable from a temporary lack of input. The streaming decoder therefore asked for more data instead of raising a format error, kept appending input to the internal eight-byte buffer, overran it and wrote out of bounds. The patch fixes this by returning and propagating BrotliDecoderErrorCode through the literal, command and distance block-switch functions, using BROTLI_SAFE_WITH_STATUS, and by adding a dedicated format-error classification for block-switch handling.

Impact

The demonstrated impact on the tested stock Node.js 22.23.3 profile is denial of service: malformed Brotli input causes the process to terminate. The underlying flaw is an out-of-bounds write in the native decoder, which the author notes can potentially lead to denial of service, memory disclosure or remote code execution. Memory disclosure means leaking the contents of memory to an attacker. Reports of code execution on other versions or configurations exist but are outside what this research independently verifies; the advisory's maximum severity should be treated as RCE-capable, while the demonstrated impact here is DoS. An advisory is the official notice a vendor publishes about a vulnerability.

Exposure depends on whether an application decompresses attacker-influenced data, how it invokes decompression, and which runtime version it runs.

Fix

The primary remediation is to upgrade Node.js to a release containing the fix. The Node.js project published security releases on 21 October 2026 covering the affected lines:

Node.js release line Minimum fixed release
22.x 22.23.4
24.x 24.22.1
26.x 26.12.1

A release line is a series of versions that share a major number. Deploy the latest supported security release for your line rather than pinning to the minimum. End-of-life versions should be migrated to a supported release. End-of-life means the vendor no longer provides updates. The fix came through an upstream Brotli change plus a corresponding Node.js source change, and the decoder now distinguishes an invalid block-switch condition from a temporary shortage of input.

For containers, upgrading Node.js on the host is not enough: the application image must be rebuilt from a patched base image and redeployed, because existing containers keep running the code in their original image.

Verifying the fix

A version check is a start:

Bash
node --version

This simply prints the Node.js version number.

But the Brotli version alone is not sufficient. Node.js maintainers confirmed the update was applied as a cherry-pick, so process.versions.brotli can keep reporting an earlier upstream version even when the build contains the fix. A cherry-pick means taking one specific change from another branch and applying it on its own, without bringing the rest along. A more useful capability check is whether the patched releases expose the new decoder error constant:

JavaScript
const zlib = require('node:zlib');
JavaScript
const hasFixMarker =  Object.prototype.hasOwnProperty.call(    zlib.constants,    'BROTLI_DECODER_ERROR_FORMAT_BLOCK_SWITCH'  );console.log({  nodeVersion: process.version,  brotliVersion: process.versions.brotli,  fixMarkerPresent: hasFixMarker});

Line by line: the first line loads the compression module. The second line asks whether the module's list of constants contains the name BROTLI_DECODER_ERROR_FORMAT_BLOCK_SWITCH, and stores the answer as true or false in hasFixMarker. A constant is a named fixed value. The console.log then prints the Node.js version, the Brotli version and whether the marker is present.

The presence of BROTLI_DECODER_ERROR_FORMAT_BLOCK_SWITCH is a useful indicator for builds that include the change. It should complement, not replace, checking the official release version or the OS vendor's advisory; third-party Brotli libraries and vendor-patched builds may need their own verification.

Runtime identification

From the original on medium.com

The official Node.js 22.23.4 release exposes the new constant through node:zlib. The capability check was run against both Docker images:

JavaScript
const zlib = require('node:zlib');
JavaScript
console.log(  process.version,  Object.hasOwn(    zlib.constants,    'BROTLI_DECODER_ERROR_FORMAT_BLOCK_SWITCH'  ));

Line by line: this loads the module, then prints the Node.js version and whether the constants list owns the new error name. Object.hasOwn is a built-in check for whether an object has a particular property.

The affected Node.js 22.23.3 image returned:

Text
v22.23.3 false

The patched Node.js 22.23.4 image returned:

Text
v22.23.4 true

So the affected baseline does not expose the new error classification and the patched release does. Because the fix was cherry-picked, the embedded Brotli version string does not necessarily change, which is why this check is more reliable than process.versions.brotli alone. It is not a complete behavioural regression test: the constant confirms the exposed interface, not how the runtime handles the problematic input.

Temporary restrictions

If an affected runtime cannot be upgraded immediately, disabling Brotli decompression for untrusted input is a practical stopgap. Review every place compressed data enters the system: HTTP request bodies, uploaded or externally supplied files, data from upstream services, message queues and other asynchronous ingestion pipelines, and components that decompress through a library or middleware. A message queue is a holding area where one system leaves messages for another to pick up later. Middleware is code that sits between the incoming request and your application logic.

Where Brotli-encoded HTTP request bodies are accepted, a reverse proxy or web application firewall can temporarily reject requests containing:

HTTP
Content-Encoding: br

A reverse proxy is a server that sits in front of your application and forwards requests to it. A web application firewall inspects traffic and blocks what looks dangerous. Content-Encoding: br is an HTTP header saying the body is Brotli-compressed; br is the short name for Brotli. Apply this carefully, since it also blocks legitimate Brotli-encoded requests. An edge rule also does not protect against Brotli data from upstream services or decoded through other pathways; an HTTP client may process compressed response data independently of inbound request handling. Treat header filtering as a compensating control, not a replacement for upgrading the decoder.

Defence in depth

Defence in depth means layering several protections so that one failure does not sink you.

  • Input and decompression limits: cap compressed input size, decompressed output size, processing time and concurrent decompression operations. This reduces resource exhaustion but does not guarantee protection against memory corruption.
  • Least privilege: run Node.js processes under unprivileged OS accounts with only the filesystem and network permissions they need. Least privilege means giving each part of a system the smallest set of powers it needs to do its job.
  • Container isolation: run as non-root, drop unnecessary capabilities, avoid privileged containers, use read-only filesystems where possible, restrict access to host resources and sensitive mounts, and apply CPU and memory limits. These reduce the consequences of a compromised process but do not stop the decoder from hitting the flaw.

Detection and monitoring

Inventory Node.js services that use Brotli decompression, including through third-party dependencies. Review direct usage such as:

Text
zlib.brotliDecompress()zlib.brotliDecompressSync()zlib.createBrotliDecompress()

These are the three decompression entry points listed earlier. Also examine middleware, HTTP clients and other libraries that decompress internally. Software composition analysis and image scanning help, but scanners should account for vendor backports and cherry-picked fixes rather than relying on an upstream version string. Software composition analysis is the practice of listing every third-party component your software uses. A backport is a fix applied to an older version than the one it was originally written for.

Unexpected process termination is a useful indicator. In the lab, Docker reported:

Text
Exited (139)

On Linux, exit status 139 is consistent with termination by signal 11 (SIGSEGV). In production, correlate this with unexpected Node.js exits, container restart loops, health-check failures, sudden HTTP 5xx responses or connection resets, OS crash reports or core dumps, and the requests or ingestion events immediately before the failure. A health check is an automated probe that asks a service whether it is still alive. HTTP 5xx responses are server-side error replies. A core dump is a snapshot of a crashed program's memory. Exit code 139 alone is not proof of exploitation; a segmentation fault has many causes, so investigate alongside logs, process telemetry and request history.

Where Brotli-encoded request bodies are accepted, monitoring requests with Content-Encoding: br shows which services receive compressed input. The header is not malicious by itself, since Brotli is a legitimate format used by normal traffic. The goal is to spot unexpected decoder failures and tie them to the input-processing path.

Glossary

  • API: the set of functions a program offers to other code so they can use its features.
  • Architecture: the family of processor a piece of software is built for, such as x86-64.
  • Asynchronous: starting a job and continuing other work while it finishes.
  • Backport: a fix applied to an older version than the one it was originally written for.
  • Base image: the starting template a container is built from.
  • Bit reader: the part of a decoder that pulls individual bits out of an incoming stream.
  • Block-switch: a point in a compressed stream where the decoder changes which table it uses to interpret the data.
  • Boolean: a value that can only be true or false.
  • Brotli: a lossless compression method used to shrink data in transit.
  • Buffer: a fixed-size area of memory holding raw bytes.
  • Buffer boundary: the edge of a fixed-size memory area; crossing it is a memory-safety mistake.
  • Capabilities: fine-grained administrator powers in Linux that can be granted or dropped individually.
  • Cherry-pick: taking one specific change from another branch and applying it on its own.
  • Class: a blueprint in code that bundles data and the functions that work on it.
  • Compression: squeezing data into a smaller size so it travels faster.
  • Constant: a named fixed value in code.
  • Container: a self-contained box holding an application and everything it needs to run.
  • Core dump: a snapshot of a crashed program's memory, saved for later analysis.
  • CVE: an official identifier for a publicly known vulnerability.
  • Denial of service (DoS): making a service stop working for its users.
  • Digest: a fingerprint of an exact file or image, used to pin it.
  • Docker: a tool that packages applications into containers.
  • Dockerfile: the recipe for building a container image.
  • Enumeration: a fixed list of named values in code.
  • Error code: a specific label saying exactly what went wrong, rather than a vague yes or no.
  • Exit code: the number a program returns when it finishes, saying how it ended.
  • Fixture: a ready-made test setup.
  • Frame: one complete message in a framed protocol.
  • Header (file): a file that declares things other files can use.
  • Header (HTTP): extra information sent alongside a request or response.
  • Health check: an automated probe asking a service whether it is still alive.
  • Host: the machine running everything else.
  • HTTP: the protocol browsers use to fetch web pages.
  • Invariant: a rule that must always stay true.
  • Kali Linux: a Linux distribution aimed at security testing.
  • Least privilege: giving each part of a system the smallest set of powers it needs.
  • Length-prefixed: a message format where the first bytes say how long the rest is.
  • Lossless: compression that reconstructs the original data exactly.
  • Memory disclosure: leaking the contents of memory to an attacker.
  • Message queue: a holding area where one system leaves messages for another to pick up later.
  • Method: a function that belongs to a class.
  • Middleware: code that sits between an incoming request and your application logic.
  • Module: a bundle of ready-made functions you can load into your program.
  • Native code: code written in a lower-level language such as C or C++, compiled for the processor.
  • Node.js: a runtime that lets JavaScript run outside the browser, typically on servers.
  • Out-of-bounds write: storing data in a memory slot the program was never supposed to touch.
  • Pinned: locked to an exact version so it cannot change between runs.
  • Port: a numbered doorway on a computer that network traffic can arrive at.
  • Proof of concept (PoC): a small program demonstrating that a bug really exists.
  • Read-only filesystem: a filesystem the program cannot modify.
  • Remote code execution (RCE): an attacker running their own commands on a server.
  • Reverse proxy: a server that sits in front of your application and forwards requests to it.
  • Runtime: the environment your code runs inside.
  • Segmentation fault (SIGSEGV): the operating system stopping a program that touched memory it was not allowed to touch.
  • Software composition analysis: listing every third-party component your software uses.
  • State machine: a model of a system as a set of states and the allowed moves between them.
  • Stateful: remembering where you are between calls.
  • Synchronous: waiting until a job is done before moving on.
  • TCP: a network protocol that delivers a reliable stream of bytes between two machines.
  • Transform stream: an object that data flows through, changing as it goes.
  • Triage: sorting findings by priority.
  • Trust boundary: the line where data stops being trusted and starts being handled by code that must defend itself.
  • Union: a C construct where several types share the same memory.
  • Web application firewall: a system that inspects traffic and blocks what looks dangerous.
  • Wrapper: code that sits around another piece of code and calls it on your behalf.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.