Skip to content
DoS Disclosed report Advanced CVE-2024-27983

"Assertion failed" in node::http2::Http2Session::~Http2Session() leads to HTTP/2 server crash

A Node.js HTTP/2 server can be crashed by sending a HEADERS frame without the END_HEADERS flag followed by a CONTINUATION frame, then abruptly closing the TCP connection. This leaves nghttp2 memory allocated when the Http2Session destructor runs, tripping an assertion and aborting the process, so an attacker can cause a permanent denial of service.

bart Follow

Originally disclosed on HackerOne

High 8.2 View original
  • Triaged in under an hour
  • Fixed in 3 months
  • Disclosed after 3 months

Summary by the program

An attacker can make the Node.js HTTP/2 server completely unavailable by sending a small amount of HTTP/2 frames packets with a few HTTP/2 frames inside. It is possible to leave some data in nghttp2 memory after reset when headers with HTTP/2 CONTINUATION frame are sent to the server and then a TCP connection is abruptly closed by the client triggering the Http2Session destructor while header frames are still being processed (and stored in memory) causing a race condition.

The report

Summary:

I discovered a vulnerability in Node.js HTTP/2 stack (http2) package. An attacker can send a very small amount of TCP packets with a few HTTP/2 frames inside. After a few seconds a Node.js (latest: 21.5.0 and latest LTS: v20.11.0) server crash with the following stack:

  #  node[3253]: virtual node::http2::Http2Session::~Http2Session() at ../src/node_http2.cc:534
  #  Assertion failed: (current_nghttp2_memory_) == (0)

----- Native stack trace -----

 1: 0xca5430 node::Abort() [node]
 2: 0xca54b0 node::errors::SetPrepareStackTraceCallback(v8::FunctionCallbackInfo<v8::Value> const&) [node]
 3: 0xce7156 node::http2::Http2Session::~Http2Session() [node]
 4: 0xce7192 node::http2::Http2Session::~Http2Session() [node]
 5: 0x106f01d v8::internal::GlobalHandles::InvokeFirstPassWeakCallbacks() [node]
 6: 0x10f3215 v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::internal::GarbageCollectionReason, char const*) [node]
 7: 0x10f3d7c v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node]
 8: 0x10ca081 v8::internal::HeapAllocator::AllocateRawWithLightRetrySlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [node]
 9: 0x10cb215 v8::internal::HeapAllocator::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [node]
10: 0x10a8866 v8::internal::Factory::NewFillerObject(int, v8::internal::AllocationAlignment, v8::internal::AllocationType, v8::internal::AllocationOrigin) [node]
11: 0x15035f6 v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [node]
12: 0x7f41df699ef6 
Aborted (core dumped)

The attack is easy to perform so a permanent Denial of Service is possible. It is also hard to debug from server admins (check Impact section).

Description:

The http2 package has an assertion in the Http2Session destructor which check if current memory usage of nghttp2 library (current_nghttp2_memory_) has been reset to 0.

C++
Http2Session::~Http2Session() {
  CHECK(!is_in_scope());
  Debug(this, "freeing nghttp2 session");
  // Explicitly reset session_ so the subsequent
  // current_nghttp2_memory_ check passes.
  session_.reset();
  CHECK_EQ(current_nghttp2_memory_, 0);
}

However it is possible to leave some data in nghttp2 memory (or counter is improperly implemented) after reset when headers with HTTP/2 CONTINUATION frame are sent to the server and then a TCP connection is abruptly closed by the client triggering the Http2Session destructor while header frames are still being processed (and stored in memory).

Steps To Reproduce:

  1. Start a http2 server.
  2. Send a HTTP/2 request:
    • Send necessary init frames.
    • Send HEADERS frame for a simple GET / request (with no END_HEADERS flag).
    • Send CONTINUATION frame with a single header (also with no END_HEADERS flag).
  3. Disconnect TCP connection.

I'm attaching an exploit in Golang that demonstrates the issue. It starts a loop and in each iteration it opens a TCP connection to the server. It sends necessary headers and then just leaves the connection open. After 10 seconds, another go routine simply exists the application which kills all opened TCP connections which triggers the bug. To run it simply run: go run ./exploit2.go -address [server]. For simplicity it works only for h2c (HTTP/2 without TLS) server but with extra code it should work against any Node.js server (with TLS).

I was testing it against the simple Node.js server:

NODEJS
const http2 = require('http2');
const fs = require('fs');

const server = http2.createServer();

server.on('error', (err) => console.error(err));

server.on('stream', (stream, headers) => {
    // Respond to the request with a simple hello world message
    stream.respond({
        'content-type': 'text/plain; charset=utf-8',
        ':status': 200
    });
    stream.end('Hello World with HTTP/2!');
    console.log("Request handled")
});

server.listen(7777, () => {
    console.log('Server is running on http://localhost:7777');
});

Impact

An attacker can make the Node.js HTTP/2 server completely unavailable. Because of the fact that send HTTP/2 frames never establish a full HTTP request, the server admins may have problems with debugging the issue or rate-limiting the attacker (requests not visible in the logs). The payload sent to exploit the issue is also very small.

Additionally, an attack can cause some problems with data integrity because GOAWAY frames will not be sent but they contain (often important): Last-Stream-ID parameter, from specification:

The last stream identifier in the GOAWAY frame contains the highest-numbered stream identifier for which the sender of the GOAWAY frame might have taken some action on or might yet take action on. All streams up to and including the identified stream might have been processed in some way.

This means that clients may submit duplicate request for request that have been already processed by a server.

Attachments

Screen_Recording_2024-01-15_at_15.40.42.mov From the original on HackerOne

The original report as published on HackerOne, by bart. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

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. 5 min read.

Context

Node.js ships an http2 module that implements an HTTP/2 server and client on top of the nghttp2 library. Applications use http2.createServer() (cleartext, h2c) or the TLS variant to accept HTTP/2 connections, and the module tracks the memory that nghttp2 allocates on behalf of each session in a counter called current_nghttp2_memory_.

The Http2Session destructor contains an assertion that this counter has returned to zero before the session is torn down. The report describes a way to make that assertion fail, which aborts the whole Node.js process rather than just the offending connection.

Setup

The researcher tested against Node.js 21.5.0 (described as latest at the time) and v20.11.0 (latest LTS). The proof of concept is a Go program, run as go run ./exploit2.go -address [server], and it targets an h2c server, that is HTTP/2 without TLS. The report notes that with extra code the same approach should work against any Node.js server, including one with TLS.

The server used for testing is a minimal http2 server that answers every stream with a fixed response:

NODEJS
const http2 = require('http2');
const fs = require('fs');

const server = http2.createServer();

server.on('error', (err) => console.error(err));

server.on('stream', (stream, headers) => {
    // Respond to the request with a simple hello world message
    stream.respond({
        'content-type': 'text/plain; charset=utf-8',
        ':status': 200
    });
    stream.end('Hello World with HTTP/2!');
    console.log("Request handled")
});

server.listen(7777, () => {
    console.log('Server is running on http://localhost:7777');
});

Finding it

The destructor of Http2Session asserts on the nghttp2 memory counter:

C++
Http2Session::~Http2Session() {
  CHECK(!is_in_scope());
  Debug(this, "freeing nghttp2 session");
  // Explicitly reset session_ so the subsequent
  // current_nghttp2_memory_ check passes.
  session_.reset();
  CHECK_EQ(current_nghttp2_memory_, 0);
}

The comment explains the intent: resetting session_ should release nghttp2's allocations so that the following check passes. The researcher found that this does not always hold. If headers are sent using the HTTP/2 CONTINUATION frame and the client then abruptly closes the TCP connection, the destructor can run while header frames are still being processed and stored in memory. Some data is left in nghttp2 memory after the reset, or the counter is improperly implemented, and the assertion fails.

When it fails, the process does not merely drop the connection. It aborts with the following output:

Text
  #  node[3253]: virtual node::http2::Http2Session::~Http2Session() at ../src/node_http2.cc:534
  #  Assertion failed: (current_nghttp2_memory_) == (0)

----- Native stack trace -----

 1: 0xca5430 node::Abort() [node]
 2: 0xca54b0 node::errors::SetPrepareStackTraceCallback(v8::FunctionCallbackInfo<v8::Value> const&) [node]
 3: 0xce7156 node::http2::Http2Session::~Http2Session() [node]
 4: 0xce7192 node::http2::Http2Session::~Http2Session() [node]
 5: 0x106f01d v8::internal::GlobalHandles::InvokeFirstPassWeakCallbacks() [node]
 6: 0x10f3215 v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::internal::GarbageCollectionReason, char const*) [node]
 7: 0x10f3d7c v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node]
 8: 0x10ca081 v8::internal::HeapAllocator::AllocateRawWithLightRetrySlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [node]
 9: 0x10cb215 v8::internal::HeapAllocator::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [node]
10: 0x10a8866 v8::internal::Factory::NewFillerObject(int, v8::internal::AllocationAlignment, v8::internal::AllocationType, v8::internal::AllocationOrigin) [node]
11: 0x15035f6 v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [node]
12: 0x7f41df699ef6
Aborted (core dumped)

Exploitation

The attack needs only a small number of TCP packets containing a few HTTP/2 frames.

Step 1: start an HTTP/2 server

Run the http2 server shown above, listening on port 7777.

Step 2: send a partial HTTP/2 request

  1. Send the necessary init frames.
  2. Send a HEADERS frame for a simple GET / request, without the END_HEADERS flag.
  3. Send a CONTINUATION frame with a single header, also without the END_HEADERS flag.

Step 3: disconnect the TCP connection

The client closes the TCP connection abruptly. This triggers the Http2Session destructor while the header frames are still being processed and stored in memory, and the assertion fires.

The Go exploit automates this. It starts a loop, and in each iteration it opens a TCP connection to the server, sends the necessary headers, and leaves the connection open. After 10 seconds another goroutine simply exits the application, which kills all opened TCP connections and triggers the bug. The report includes a screen recording of the exploit running:

Screen_Recording_2024-01-15_at_15.40.42.mov From the original on HackerOne

Root cause

The destructor assumes that resetting session_ releases every nghttp2 allocation, so that current_nghttp2_memory_ is zero by the time the check runs. When a header block is left incomplete by omitting END_HEADERS and the connection is closed while those frames are still being processed, data remains in nghttp2 memory after the reset, or the counter does not reflect the real state. The CHECK_EQ then aborts the process. The report frames this as a race condition between the destructor and the in-progress header processing.

Impact

An attacker can make the Node.js HTTP/2 server completely unavailable, and because the attack is easy to perform, a permanent denial of service is possible. The payload is very small.

Debugging is difficult for server administrators. The frames sent never establish a full HTTP request, so the requests are not visible in the logs, which also complicates rate-limiting the attacker.

The attack can additionally cause data integrity problems. GOAWAY frames will not be sent, and those frames carry the Last-Stream-ID parameter, which the report quotes from the specification:

The last stream identifier in the GOAWAY frame contains the highest-numbered stream identifier for which the sender of the GOAWAY frame might have taken some action on or might yet take action on. All streams up to and including the identified stream might have been processed in some way.

As a result, clients may submit duplicate requests for requests that the server has already processed.

Fix

The report does not describe a fix or a code change.

Variants to test

  • Send HEADERS without END_HEADERS followed by one or more CONTINUATION frames, then close the TCP connection abruptly, against other Node.js HTTP/2 deployments. A positive result is the Assertion failed: (current_nghttp2_memory_) == (0) message and an aborted process.
  • Repeat the same sequence over TLS rather than h2c, since the report states the technique should work against any Node.js server with extra code. A positive result is the same crash.

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. 16 min read.

What happened, in plain words

Node.js is a program that lets people run JavaScript code on a server, that is, on a computer that answers requests from other computers over the internet. Many websites and web services are built on it. One of the things Node.js can do is speak a particular language with browsers and other programs called HTTP/2. HTTP/2 is a newer version of the language (protocol) that web browsers and servers use to exchange pages and data. It is designed to be faster than the older HTTP/1.1 by sending many requests over a single connection at the same time.

A researcher found that a person with bad intentions (an attacker) can send a very small number of network packets, containing just a few HTTP/2 messages, to a Node.js server that speaks HTTP/2, and make the entire server program stop working. Not just one connection: the whole process shuts down. The server becomes completely unavailable to everyone. Because the attack is easy to repeat, the server can be knocked over again and again, which is called a denial of service (DoS).

The cause is a safety check inside Node.js that is supposed to confirm that some temporary memory has been cleaned up before a connection is closed. Under a particular sequence of events, that check fails, and instead of handling the problem gracefully, Node.js deliberately aborts the whole program. The report calls this a race condition, meaning two things happen at nearly the same time and the order in which they finish matters: the connection is being torn down while header information is still being processed.

Context

To follow this, you need a few ideas.

  • API (application programming interface): a set of functions that one piece of software offers to another. Think of it as a menu in a restaurant: you do not go into the kitchen, you order from the menu and the kitchen does the work. Node.js offers an API called http2 that programmers use to build HTTP/2 servers and clients.
  • Library: a collection of ready-made code that a program uses instead of writing everything from scratch. Node.js's http2 module is built on top of a library called nghttp2, which does the low-level work of speaking HTTP/2.
  • Module: a bundle of related functions in Node.js. http2 is one such module.
  • Server and client: the server is the program that waits for and answers requests. The client is the program that sends requests, such as a browser or a script.
  • TLS: the encryption layer behind the padlock in a browser. HTTP/2 can run with TLS (encrypted, usually on https://) or without it. The unencrypted version is called h2c (HTTP/2 cleartext).
  • Session: one conversation between a client and a server over one network connection. Node.js represents each such conversation with an object called Http2Session.
  • Destructor: code that runs automatically when an object is about to be destroyed and its memory freed. In C++, the language parts of Node.js are written in, a destructor's name starts with ~, so ~Http2Session is the destructor of Http2Session.
  • Assertion: a check in code that says "this must be true; if it is not, something is seriously wrong". Node.js uses a macro called CHECK for assertions that are meant to be fatal.
  • Memory counter: a number that keeps track of how much memory a library has borrowed. Here it is called current_nghttp2_memory_ and it counts memory that nghttp2 has allocated for a session.

Node.js ships the http2 module, which implements an HTTP/2 server and client on top of nghttp2. Applications use http2.createServer() for cleartext (h2c) servers, or the TLS variant for encrypted ones, to accept HTTP/2 connections. The module tracks the memory nghttp2 allocates on behalf of each session in the counter current_nghttp2_memory_.

The Http2Session destructor contains an assertion that this counter has returned to zero before the session is torn down. The report describes a way to make that assertion fail, which aborts the whole Node.js process rather than just the offending connection.

Setup

The researcher tested against Node.js 21.5.0 (described as the latest at the time) and v20.11.0 (the latest long-term-support release, LTS, meaning a version maintained for a long period). The proof of concept, that is, the demonstration program that proves the bug is real, is a Go program. Go is a programming language, different from JavaScript, often used for network tools. It is run with the command go run ./exploit2.go -address [server], and it targets an h2c server, HTTP/2 without TLS. The report notes that with extra code the same approach should work against any Node.js server, including one with TLS.

The server used for testing is a minimal http2 server that answers every stream with a fixed response:

NODEJS
const http2 = require('http2');
const fs = require('fs');

const server = http2.createServer();

server.on('error', (err) => console.error(err));

server.on('stream', (stream, headers) => {
    // Respond to the request with a simple hello world message
    stream.respond({
        'content-type': 'text/plain; charset=utf-8',
        ':status': 200
    });
    stream.end('Hello World with HTTP/2!');
    console.log("Request handled")
});

server.listen(7777, () => {
    console.log('Server is running on http://localhost:7777');
});

Line by line:

  1. const http2 = require('http2'); loads the built-in http2 module and stores it in a constant called http2. This is how Node.js code gets access to the HTTP/2 API.
  2. const fs = require('fs'); loads the file system module. It is not used further in this snippet, but it is there in case the server needs to read files.
  3. const server = http2.createServer(); creates an HTTP/2 server object. Because no TLS options are passed, this is a cleartext h2c server.
  4. server.on('error', (err) => console.error(err)); registers a handler: if the server reports an error, print it to the console. This is a normal way to see problems instead of them being silent.
  5. server.on('stream', (stream, headers) => { registers a handler for the stream event. In HTTP/2, each request and response pair travels on its own stream, a logical channel inside the single connection. When a client opens a stream, this function runs with the stream object and the request headers.
  6. stream.respond({ starts sending the response headers.
  7. 'content-type': 'text/plain; charset=utf-8', tells the client the body is plain text encoded in UTF-8 (a standard way to represent characters).
  8. ':status': 200 sets the HTTP status code to 200, which means "OK". The leading colon marks a pseudo-header, a special header in HTTP/2 that carries information that used to be on the request line in HTTP/1.1.
  9. }); closes the response header object.
  10. stream.end('Hello World with HTTP/2!'); sends the body text and ends the stream.
  11. console.log("Request handled") prints a line to the server console each time a request is answered. This is useful for the researcher to see that requests are arriving.
  12. }); closes the stream handler.
  13. server.listen(7777, () => { tells the server to listen on port 7777. A port is a numbered door on a computer; different services listen on different doors. 7777 is just a chosen number here.
  14. console.log('Server is running on http://localhost:7777'); prints a message once the server is ready. localhost means this same computer.
  15. }); closes the listen callback.

Finding it

The destructor of Http2Session asserts on the nghttp2 memory counter:

C++
Http2Session::~Http2Session() {
  CHECK(!is_in_scope());
  Debug(this, "freeing nghttp2 session");
  // Explicitly reset session_ so the subsequent
  // current_nghttp2_memory_ check passes.
  session_.reset();
  CHECK_EQ(current_nghttp2_memory_, 0);
}

Line by line:

  1. Http2Session::~Http2Session() { begins the destructor, the code that runs when a session object is being destroyed.
  2. CHECK(!is_in_scope()); is an assertion that the session is not currently "in scope", meaning it is not in the middle of being used. If this is false, the program aborts. It is a guard against destroying something that is still active.
  3. Debug(this, "freeing nghttp2 session"); writes a debug message, only when debug output is enabled, saying the nghttp2 session is being freed.
  4. The two comment lines explain the intent of the next statement: reset the session so that the following memory check passes.
  5. session_.reset(); releases the underlying nghttp2 session object. The idea is that this frees all the memory nghttp2 borrowed, so the counter should drop to zero.
  6. CHECK_EQ(current_nghttp2_memory_, 0); asserts that the memory counter equals zero. CHECK_EQ means "check equal". If the counter is anything other than zero, the process aborts.
  7. } closes the destructor.

The comment explains the intent: resetting session_ should release nghttp2's allocations so that the following check passes. The researcher found that this does not always hold. If headers are sent using the HTTP/2 CONTINUATION frame and the client then abruptly closes the TCP connection, the destructor can run while header frames are still being processed and stored in memory. Some data is left in nghttp2 memory after the reset, or the counter is improperly implemented, and the assertion fails.

A few terms here:

  • TCP connection: the underlying network connection between two computers. HTTP/2 runs on top of TCP. Closing it abruptly means the client just stops talking without a polite goodbye.
  • Frame: HTTP/2 breaks everything into small units called frames. A request's headers are sent in a HEADERS frame, and if they do not fit, the rest is sent in one or more CONTINUATION frames.
  • END_HEADERS flag: a marker on a frame saying "this is the last piece of the headers". If it is not set, the receiver knows more header pieces are coming and keeps what it has in memory, waiting.

When the assertion fails, the process does not merely drop the connection. It aborts with the following output:

Text
  #  node[3253]: virtual node::http2::Http2Session::~Http2Session() at ../src/node_http2.cc:534
  #  Assertion failed: (current_nghttp2_memory_) == (0)

----- Native stack trace -----

 1: 0xca5430 node::Abort() [node]
 2: 0xca54b0 node::errors::SetPrepareStackTraceCallback(v8::FunctionCallbackInfo<v8::Value> const&) [node]
 3: 0xce7156 node::http2::Http2Session::~Http2Session() [node]
 4: 0xce7192 node::http2::Http2Session::~Http2Session() [node]
 5: 0x106f01d v8::internal::GlobalHandles::InvokeFirstPassWeakCallbacks() [node]
 6: 0x10f3215 v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::internal::GarbageCollectionReason, char const*) [node]
 7: 0x10f3d7c v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node]
 8: 0x10ca081 v8::internal::HeapAllocator::AllocateRawWithLightRetrySlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [node]
 9: 0x10cb215 v8::internal::HeapAllocator::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [node]
10: 0x10a8866 v8::internal::Factory::NewFillerObject(int, v8::internal::AllocationAlignment, v8::internal::AllocationType, v8::internal::AllocationOrigin) [node]
11: 0x15035f6 v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [node]
12: 0x7f41df699ef6
Aborted (core dumped)

What this output means:

  1. The first two lines are the message from the failed assertion: the destructor at ../src/node_http2.cc:534 found that current_nghttp2_memory_ was not (0).
  2. ----- Native stack trace ----- introduces a list of function calls, a stack trace, which is like a receipt showing the chain of functions that led to the crash. Reading from the bottom up shows how the program got there.
  3. Line 1, node::Abort(), is the function that deliberately stops the program.
  4. Lines 3 and 4 show the Http2Session destructor being called.
  5. Line 5, GlobalHandles::InvokeFirstPassWeakCallbacks, is part of V8, the JavaScript engine inside Node.js. It runs callbacks for objects that are no longer needed.
  6. Lines 6 and 7 are garbage collection functions. Garbage collection is the automatic process of finding memory that is no longer in use and reclaiming it, like a cleaner clearing tables after guests leave.
  7. Lines 8 to 11 are memory allocation functions, showing the program was busy allocating memory when the cleanup happened.
  8. Line 12 is an address with no symbol name, meaning the tool could not map it to a function name.
  9. Aborted (core dumped) means the process terminated abnormally and the operating system wrote a core dump, a snapshot of memory at the moment of the crash, which developers can inspect.

Exploitation

The attack needs only a small number of TCP packets containing a few HTTP/2 frames. A packet is a small chunk of data sent over a network; every message is broken into packets.

Step 1: start an HTTP/2 server

Run the http2 server shown above, listening on port 7777. This is the victim: the program the attacker wants to knock over. The researcher runs it locally to test safely.

Step 2: send a partial HTTP/2 request

  1. Send the necessary init frames. HTTP/2 requires a short opening exchange before real requests, to agree on settings. Think of it as saying hello and agreeing on the rules before playing.
  2. Send a HEADERS frame for a simple GET / request, without the END_HEADERS flag. GET / means "give me the home page". Leaving off END_HEADERS tells the server "wait, more header pieces are coming".
  3. Send a CONTINUATION frame with a single header, also without the END_HEADERS flag. This adds one more header piece but still does not say the headers are complete.

Step 3: disconnect the TCP connection

The client closes the TCP connection abruptly. This triggers the Http2Session destructor while the header frames are still being processed and stored in memory, and the assertion fires. In plain terms: the server is still holding the half-finished headers when the connection vanishes, and the cleanup code finds memory that has not been released.

The Go exploit automates this. It starts a loop, and in each iteration it opens a TCP connection to the server, sends the necessary headers, and leaves the connection open. After 10 seconds another goroutine simply exits the application, which kills all opened TCP connections and triggers the bug. A goroutine is Go's lightweight unit of concurrent work, roughly like a separate task running at the same time. The report includes a screen recording of the exploit running:

Screen_Recording_2024-01-15_at_15.40.42.mov From the original on HackerOne

Root cause

The destructor assumes that resetting session_ releases every nghttp2 allocation, so that current_nghttp2_memory_ is zero by the time the check runs. When a header block is left incomplete by omitting END_HEADERS and the connection is closed while those frames are still being processed, data remains in nghttp2 memory after the reset, or the counter does not reflect the real state. The CHECK_EQ then aborts the process. The report frames this as a race condition between the destructor and the in-progress header processing.

A recoverable error would be like a shop assistant telling one customer "sorry, that did not work" while the shop stays open. A hard check is like pulling the fire alarm and closing the whole shop because one customer's order went wrong.

Impact

An attacker can make the Node.js HTTP/2 server completely unavailable, and because the attack is easy to perform, a permanent denial of service is possible. The payload, meaning the data the attacker sends, is very small.

Debugging is difficult for server administrators. The frames sent never establish a full HTTP request, so the requests are not visible in the logs, which also complicates rate-limiting the attacker. Logs are the records a server keeps of what happened. Rate-limiting means restricting how many requests one source may make in a period, like a bouncer limiting how many times one person may enter a club. If the attack never appears as a normal request, the usual tools for spotting and blocking abuse do not see it.

The attack can additionally cause data integrity problems. GOAWAY frames will not be sent, and those frames carry the Last-Stream-ID parameter, which the report quotes from the specification. A GOAWAY frame is HTTP/2's polite shutdown notice: it tells the client "I am closing, and here is the last request I handled". The specification is the official document that defines how HTTP/2 must behave.

The last stream identifier in the GOAWAY frame contains the highest-numbered stream identifier for which the sender of the GOAWAY frame might have taken some action on or might yet take action on. All streams up to and including the identified stream might have been processed in some way.

In plain words: the GOAWAY frame tells the client which requests the server may already have acted on. If the server crashes without sending it, the client cannot know which requests were processed. As a result, clients may submit duplicate requests for requests that the server has already processed. Imagine ordering a coffee, the shop's till crashing before it prints your receipt, and you ordering again because you are not sure the first order counted. You might get two coffees, or be charged twice.

Fix

The report does not describe a fix or a code change.

Variants to test

  • Send HEADERS without END_HEADERS followed by one or more CONTINUATION frames, then close the TCP connection abruptly, against other Node.js HTTP/2 deployments. A positive result is the Assertion failed: (current_nghttp2_memory_) == (0) message and an aborted process.
  • Repeat the same sequence over TLS rather than h2c, since the report states the technique should work against any Node.js server with extra code. A positive result is the same crash.

Glossary

  • API: a set of functions one piece of software offers to another, like a menu you order from.
  • Assertion: a check in code that something must be true, and that the program should stop if it is not.
  • CHECK / CHECK_EQ: Node.js macros for fatal assertions; CHECK_EQ checks that two values are equal.
  • Client: the program that sends requests, such as a browser or a script.
  • CONTINUATION frame: an HTTP/2 frame that carries the remaining pieces of a header block when the first HEADERS frame was not enough.
  • Core dump: a snapshot of a program's memory written by the operating system when the program crashes.
  • Counter: a number kept in a program to track something, here the memory nghttp2 has allocated.
  • Denial of service (DoS): an attack that makes a service unavailable to its legitimate users.
  • Destructor: code that runs automatically when an object is destroyed and its memory freed.
  • END_HEADERS flag: a marker on an HTTP/2 frame saying it is the last piece of the headers.
  • Frame: a small unit of data in HTTP/2; everything is broken into frames.
  • Garbage collection: automatic reclaiming of memory that is no longer in use.
  • GOAWAY frame: HTTP/2's shutdown notice, telling the client the server is closing and which requests it may have handled.
  • Goroutine: Go's lightweight unit of concurrent work, like a separate task running at the same time.
  • h2c: HTTP/2 over a cleartext connection, without TLS encryption.
  • HEADERS frame: the HTTP/2 frame that carries a request's or response's headers.
  • HTTP/2: a version of the protocol browsers and servers use to exchange web pages and data, designed to be faster than HTTP/1.1.
  • Http2Session: the Node.js object representing one HTTP/2 conversation over one connection.
  • Last-Stream-ID: the parameter in a GOAWAY frame giving the highest-numbered stream the server may have acted on.
  • Library: ready-made code a program uses instead of writing everything itself.
  • Logs: records a server keeps of what happened.
  • LTS: long-term support, a version of software maintained for a long period.
  • nghttp2: the library Node.js uses underneath to speak HTTP/2.
  • Node.js: a program that runs JavaScript on a server.
  • Packet: a small chunk of data sent over a network.
  • Payload: the data an attacker sends to carry out an attack.
  • Port: a numbered door on a computer where a service listens.
  • Proof of concept: a demonstration program that proves a bug is real.
  • Race condition: a bug where two things happen at nearly the same time and the order in which they finish changes the outcome.
  • Rate-limiting: restricting how many requests one source may make in a period.
  • Server: the program that waits for and answers requests from clients.
  • Session: one conversation between a client and a server over one connection.
  • Stack trace: a list of function calls showing how a program reached a particular point, like a receipt of the chain of events.
  • Stream: a logical channel inside an HTTP/2 connection, one per request and response pair.
  • TCP: the underlying network connection protocol that HTTP/2 runs on.
  • UTF-8: a standard way to represent characters as bytes.
  • V8: the JavaScript engine inside Node.js that runs JavaScript code.

More by bart

View all

5 more disclosed reports, best first.

More from Node.js

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.