Skip to content
DoS Disclosed report Intermediate CVE-2020-8251

Denial of Service by resource exhaustion CWE-400 due to unfinished HTTP/1.1 requests

Node.js servers with default timeout settings can be kept busy by clients that open connections and send requests very slowly, never completing them. An attacker can open many such connections to exhaust the server's connection limit and cause a denial of service.

shogun_panda Follow

Originally disclosed on HackerOne

Bounty$250 Critical 9.3 View original
  • Triaged in 54 days
  • Fixed in 4 months
  • Paid in 11 months
  • Disclosed after 5 months

Summary: Node.js is vulnerable to HTTP denial of service (DOS) attacks based on delayed requests submission which can make the server unable to accept new connections.

Description:

An attacker can open an arbitrary number of HTTP connections and keep the server busy by never completing the request phase.

Node.js only has two requests timeouts:

  1. server.timeout that controls the maximum number of milliseconds the socket can be idle. This also includes the server processing time.
  2. server.headersTimeout (Added in Node 11.3.0), that controls the maximum number of milliseconds allowed to receive the full request headers before timing out.

Handling of request bodies is specific to the application code and core Node.js never consumes or parses the request bodies.

Currently, the body parsing and handling is performed by the following modules:

All of the modules above are vulnerable to the attack.

If part of the body is already sent, the body parsing modules above can be patched to impose a request body sending timeout and therefore mitigate the attack.

The application unfortunately can not completely handle this attack. If the attacker never starts sending the body after completing the submission of the headers, the application code is never invoked.

Prior to Node.js 13.0.0, the default timeout for a request was 2 minutes, which is a countermeasure against this attack. Starting with Node.js 13.0.0 instead, the default timeout has been changed to be 0 (which means no timeout) in order to address serverless deployments where long running requests are needed. Since the socket is never considered idle, the application is completely vulnerable to the attack.

While server.headersTimeout is able to detect a slow request, it is only effective if the delay happens during the headers phase (like in Slowloris attacks). If the attacker delays the start of the headers, the start of body sending or sends the body very slow without resulting in an idle socket, the attack is not detected.

In the long run an unprotected server will have a lot of pending requests to handle. At some point it will reach the open connections limit and therefore will not be able to serve additional requests, resulting in a Denial of Service.

Steps To Reproduce:

  1. From one or more attacking sources, open one or more HTTP connections to the target server
  2. For each of the connection in step 1 2.1. (Optional) Wait a certain amount of time before sending the first request header. 2.2 Send all request headers with regular pausing. 2.3 (Optional) Wait a certain amount of time before sending the body data. 2.4. Send the request body with regular pausing.

All the substeps must be performed by sending periodically the smallest amount of data with the highest delay such that the server does not detect an idle socket. For Node 13.0.0 and above there is no idle timeout by default, so the attacker can wait an arbitrary time. For Node.js prior to 13.0.0, at least one byte each 2 minutes must be sent.

We have tested the following test cases:

  1. Connection established, none or partial headers sent then sending is paused: If server.timeout is not 0, then idle detection is triggered and closes the connection with no response. With the default timeout of 0 in Node.js 13.0.0 and above, the server is completely vulnerable to the attack.
  2. Connection established, headers sent with long delays: server.headersTimeout is triggered and closes the connection with no response.
  3. Connection established, headers sent and sending is paused before starting the body: If server.timeout is not 0, then idle detection is triggered and closes the connection with no response. With the default timeout of 0 in Node.js 13.0.0 and above, the server is completely vulnerable to the attack.
  4. Connection established, headers sent, body sent with long delays: server.timeout is not able to detect the attack and the server is completely vulnerable to the attack.

What follows is a sample code which reproduces the problem.

JavaScript
const { createConnection } = require('net')

let start
let response = ''
let body = ''.padEnd(4096, '123')

const client = createConnection({ port: parseInt(process.argv[2], 10) }, () => {
  start = process.hrtime.bigint()

  // Send all the headers quickly so that server.headersTimeout is not triggered
  client.write('POST / HTTP/1.1\r\n')
  client.write('Content-Type: text/plain\r\n')
  client.write(`Content-Length: ${Buffer.byteLength(body)}\r\n`)
  client.write(`\r\n`)

  // Send the body very slower but in away that the server.timeout is not triggered
  let i = 0
  let interval = setInterval(() => {
    client.write(body[i])
    i++

    // Done sending, end the request
    if (i === body.length) {
      clearInterval(interval)
      client.write(`\r\n\r\n`)
    }
  }, 60000)
})

client.on('data', data => {
  response += data
  client.end()
})

client.on('close', () => {
  const duration = Number(process.hrtime.bigint() - start) / 1e9

  console.log(`Receive the following response (${response.length} bytes) in ${duration.toFixed(3)} s:\n\n`)
  console.log(response)
})

Once executed, the client will not receive a response before 4096 minutes. If multiple parallel execution of the code above targets the same server, it will result in service denial.

Impact

This attack has very low complexity and can easily trigger a DDOS on an unprotected server.

Supporting Material/References:

We have written a patch for Node.js (PR 33304) which introduces a new http.Server option called requestTimeout with a default value in milliseconds of 120000 (2 minutes).

When requestTimeout is a positive value, the server will start a new timer set to expire in requestTimeout milliseconds when a new connection is established. The timer is also set again if new requests after the first are received on the socket (this handles pipelining and keep-alive cases). The timer is cancelled in the following case:

  1. When the request body is completely received by the server.
  2. When the response is completed. This handles the case where the application responds to the client without consuming the request body.
  3. When the connection is upgraded, like in the WebSocket case.

If the timer expires, then the server responds with status code 408 and closes the connection. This prevents the DOS attack.

Acknowledgement

This research was conducted and co-authored by me and Matteo Collina and has been sponsored by NearForm

Impact

If an attacker execute a significative amount of requests on a target server without completing any, the server at some point will reach the allowed number of open connections and will not be able to serve any further request, resulting in a Denial of Service.

The original report as published on HackerOne, by shogun_panda. 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. 8 min read.

Context

Node.js ships an HTTP server whose request lifecycle is governed by a small number of timeouts. The report examines how those timeouts interact with the way Node.js handles request bodies, and shows that a client which never finishes a request can hold a connection open indefinitely on a default Node.js 13.0.0 or later server. The result is resource exhaustion (CWE-400) and, once enough connections are held, a denial of service.

The target is the core Node.js HTTP server (https://github.com/nodejs/node). The relevant feature is the set of request timeouts exposed on http.Server, and the fact that core Node.js never consumes or parses request bodies itself: body handling is delegated to application code and third-party modules.

Setup

The report describes the attack against a Node.js HTTP server and gives a reproduction client written against the net module, so no special account or role is needed. The preconditions that matter are the Node.js version and the timeout configuration:

  • Prior to Node.js 13.0.0, the default request timeout was 2 minutes, which acts as a countermeasure against the attack.
  • Starting with Node.js 13.0.0, the default timeout was changed to 0, meaning no timeout, to accommodate serverless deployments that need long-running requests.
  • server.headersTimeout was added in Node 11.3.0 and limits the time allowed to receive the full request headers.
  • server.timeout limits how long the socket may be idle, and that idle window also includes server processing time.

The reproduction client is run with a port number as its argument, for example against a local test server.

Finding it

The researcher started from the observation that Node.js only has two request timeouts, server.timeout and server.headersTimeout, and that neither covers the whole request. server.timeout measures socket idleness, not total request duration, and server.headersTimeout only applies to the headers phase. Because core Node.js never consumes or parses request bodies, nothing in the core enforces a deadline on body transmission.

Body parsing is performed by application-level modules, and the report lists the following as vulnerable to the attack:

  • fastify
  • restify
  • busboy, used by fastify-multipart and multer
  • raw-body, used by body-parser

If part of the body has already been sent, those body parsing modules can be patched to impose a request body sending timeout and thereby mitigate the attack. The application, however, cannot completely handle the attack on its own: if the attacker never starts sending the body after completing the submission of the headers, the application code is never invoked, so there is nothing for the application to time out.

The second observation is version-dependent. Since the socket is never considered idle while the client trickles data, and since Node.js 13.0.0 and above default the timeout to 0, the application is completely vulnerable. server.headersTimeout can detect a slow request only if the delay happens during the headers phase, as in Slowloris. If the attacker delays the start of the headers, delays the start of body sending, or sends the body very slowly without ever letting the socket go idle, the attack is not detected.

Exploitation

The attack is described as a sequence of steps rather than a single request.

Step 1: Open connections

From one or more attacking sources, open one or more HTTP connections to the target server.

Step 2: Hold each connection open

For each connection opened in step 1:

  1. (Optional) Wait a certain amount of time before sending the first request header.
  2. Send all request headers with regular pausing.
  3. (Optional) Wait a certain amount of time before sending the body data.
  4. Send the request body with regular pausing.

Every substep must be performed by periodically sending the smallest amount of data with the highest delay such that the server does not detect an idle socket. On Node.js 13.0.0 and above there is no idle timeout by default, so the attacker can wait an arbitrary time. On Node.js prior to 13.0.0, at least one byte every 2 minutes must be sent.

Test cases

The researcher tested four cases:

Case Behaviour
Connection established, none or partial headers sent, then sending paused If server.timeout is not 0, idle detection triggers and closes the connection with no response. With the default timeout of 0 in Node.js 13.0.0 and above, the server is completely vulnerable.
Connection established, headers sent with long delays server.headersTimeout triggers and closes the connection with no response.
Connection established, headers sent, sending paused before the body starts If server.timeout is not 0, idle detection triggers and closes the connection with no response. With the default timeout of 0 in Node.js 13.0.0 and above, the server is completely vulnerable.
Connection established, headers sent, body sent with long delays server.timeout cannot detect the attack and the server is completely vulnerable.

Reproduction client

The report provides a sample client that reproduces the problem:

JavaScript
const { createConnection } = require('net')

let start
let response = ''
let body = ''.padEnd(4096, '123')

const client = createConnection({ port: parseInt(process.argv[2], 10) }, () => {
  start = process.hrtime.bigint()

  // Send all the headers quickly so that server.headersTimeout is not triggered
  client.write('POST / HTTP/1.1\r\n')
  client.write('Content-Type: text/plain\r\n')
  client.write(`Content-Length: ${Buffer.byteLength(body)}\r\n`)
  client.write(`\r\n`)

  // Send the body very slower but in away that the server.timeout is not triggered
  let i = 0
  let interval = setInterval(() => {
    client.write(body[i])
    i++

    // Done sending, end the request
    if (i === body.length) {
      clearInterval(interval)
      client.write(`\r\n\r\n`)
    }
  }, 60000)
})

client.on('data', data => {
  response += data
  client.end()
})

client.on('close', () => {
  const duration = Number(process.hrtime.bigint() - start) / 1e9

  console.log(`Receive the following response (${response.length} bytes) in ${duration.toFixed(3)} s:\n\n`)
  console.log(response)
})

The client opens a raw TCP connection and writes the request line, Content-Type and Content-Length headers immediately, followed by the blank line that terminates the headers. Sending the headers quickly keeps server.headersTimeout from firing. It then writes one byte of the body every 60 seconds, which keeps the socket from ever being considered idle and therefore keeps server.timeout from firing. The body is 4096 bytes, so the client will not receive a response before 4096 minutes. If multiple parallel executions of the code target the same server, it results in service denial.

Root cause

The design gap is that no timeout in core Node.js bounds the total lifetime of a request. server.timeout is an idle timeout, so any periodic byte defeats it, and server.headersTimeout only covers the headers phase. Since core Node.js never consumes or parses request bodies, the application is not invoked until the body is available, so application-level body parsing timeouts cannot help when the body never starts. The change of the default timeout to 0 in Node.js 13.0.0 removed the 2-minute countermeasure that had previously limited the attack on default configurations.

Impact

An attacker can open an arbitrary number of HTTP connections and keep the server busy by never completing the request phase. In the long run an unprotected server accumulates pending requests; at some point it reaches the open connections limit and can no longer serve additional requests, resulting in a denial of service. The attack has very low complexity and can easily trigger a DDoS on an unprotected server. The impact statement notes that if an attacker executes a significant amount of requests on a target server without completing any, the server will eventually reach the allowed number of open connections and will not be able to serve any further request.

Fix

The researcher wrote a patch for Node.js (PR 33304) that introduces a new http.Server option called requestTimeout, with a default value in milliseconds of 120000 (2 minutes).

When requestTimeout is a positive value, the server starts a new timer set to expire in requestTimeout milliseconds when a new connection is established. The timer is set again if new requests after the first are received on the socket, which handles pipelining and keep-alive cases. The timer is cancelled in the following cases:

  1. When the request body is completely received by the server.
  2. When the response is completed, which handles the case where the application responds to the client without consuming the request body.
  3. When the connection is upgraded, as in the WebSocket case.

If the timer expires, the server responds with status code 408 and closes the connection, which prevents the DoS attack.

Variants to test

  • Slow body transmission against a default Node.js 13.0.0 or later server: a positive result is a connection that stays open far beyond any configured timeout while the client trickles one byte at a time.
  • Headers sent quickly, body never started: a positive result is a connection held open with no application code invoked and no response, on a server whose server.timeout is 0.
  • Delayed start of headers: a positive result is a connection that survives past server.headersTimeout because the delay occurs before the headers phase begins.
  • Pipelined or keep-alive requests on the same socket: a positive result is a socket that keeps accepting new requests without the per-request timer being reset in a way that bounds total lifetime.
  • Application-level body parsers (fastify, restify, busboy via fastify-multipart or multer, raw-body via body-parser): a positive result is a request whose body is partially sent and then stalled without the parser imposing a sending timeout.

Hunting notes

This class of bug tends to hide wherever a server exposes an idle-based timeout rather than a total-request timeout, and wherever request bodies are handled outside the core framework. During recon, the signals are a Node.js 13.0.0 or later default configuration, a server.timeout of 0, and body parsing delegated to application modules. The report states that a single client receives no response before 4096 minutes and that multiple parallel executions against the same server will result in service denial.

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

What happened, in plain words

Node.js is a program that lets developers run JavaScript on a server instead of only inside a browser. One of the things it can do is act as a web server: it listens for connections from browsers and other programs and answers their requests. This report is about a way to make such a server stop answering anyone at all, without breaking into it and without needing any password.

The trick is simple in principle. A normal visitor asks for a page, the server replies, and the connection is closed or reused. An attacker can instead open a connection and then send the request so slowly, or leave it half finished for so long, that the server keeps waiting. Every waiting connection occupies one of the server's limited slots. Fill all the slots with connections that never finish, and new visitors cannot get in. That is a denial of service: the service is still running, but nobody can use it.

The report calls this resource exhaustion, classified as CWE-400 (uncontrolled resource consumption). The research was co-authored by the report's author and Matteo Collina, and sponsored by NearForm.

To follow the rest, you need a few everyday ideas:

  • A server is like a shop counter with a limited number of clerks. Each clerk can serve one customer at a time.
  • A connection is one customer standing at a counter. It stays occupied until the conversation ends.
  • A request is what the customer asks for. It has two parts: the headers (a short label saying what is wanted, like "I would like a large coffee") and the body (the actual content, like the money or a filled-in form).
  • A timeout is the shop's rule for giving up on a customer who goes silent: after a while, the clerk serves someone else.

The whole bug lives in how those timeout rules are written.

Context

Node.js includes a built-in web server. Its behaviour is controlled by a small number of timeout settings. The report looks at how those settings interact with the way Node.js handles the body of a request, and shows that a client which never finishes a request can keep a connection open forever on a default Node.js 13.0.0 or later server. The result is resource exhaustion and, once enough connections are held, a denial of service.

The target is the core Node.js web server, hosted at https://github.com/nodejs/node. The feature in question is the set of request timeouts on the server object, plus one important design fact: the core of Node.js never reads or interprets request bodies itself. That job is left to the application and to add-on modules.

Think of it this way: the core server is the doorman who takes your name at the entrance. Reading the form you filled in is somebody else's job, further inside. If you never hand over the form, the doorman waits, and the person inside never even learns you exist.

Setup

The report describes the attack against a Node.js web server and provides a small reproduction program written against the net module, which is the part of Node.js that deals with raw network connections. No special account or role is needed to try it; you only need to be able to run the program and point it at a server.

What matters is the Node.js version and the timeout configuration:

  • Before Node.js 13.0.0, the default request timeout was 2 minutes. That acted as a defence against this attack: a silent connection was eventually dropped.
  • Starting with Node.js 13.0.0, the default timeout was changed to 0, which means no timeout at all. The reason given is serverless deployments, where requests are expected to run for a long time.
  • server.headersTimeout was added in Node 11.3.0. It limits how long the server will wait to receive the complete set of request headers.
  • server.timeout limits how long the connection may sit idle, and that idle window also includes time the server spends processing.

The reproduction program is run with a port number as its argument, for example against a local test server. A port is like a numbered door on the server machine; the program needs to know which door to knock on.

Finding it

The researcher started from a simple observation: Node.js has only two request timeouts, server.timeout and server.headersTimeout, and neither one covers the whole request.

  • server.timeout measures idleness, not total duration. A customer who says one word every minute is never silent, so the clerk never gives up, even though the conversation could go on for hours.
  • server.headersTimeout only applies while the headers are arriving. Once the headers are in, it has nothing more to say.

And because the core of Node.js never reads request bodies, nothing in the core puts a deadline on how long the body may take to arrive.

Reading bodies is done by modules that sit on top of the core, in the application layer. The report lists the following as vulnerable to the attack:

  • fastify
  • restify
  • busboy, used by fastify-multipart and multer
  • raw-body, used by body-parser

If part of the body has already been sent, those body-reading modules can be patched to impose a sending timeout on the body, which mitigates the attack. But the application cannot fully defend itself. If the attacker sends the headers and then never starts the body, the application code is never invoked at all, so there is nothing for the application to time out. The doorman is still waiting, and the person inside has not been called.

The second observation depends on the version. Because the connection is never considered idle while the client trickles data, and because Node.js 13.0.0 and above default the timeout to 0, the application is completely vulnerable. server.headersTimeout can catch a slow request only when the delay happens during the headers phase, as in the classic Slowloris attack. If the attacker delays the start of the headers, delays the start of the body, or sends the body very slowly without ever letting the connection go idle, the attack goes unnoticed.

Slowloris, for context, is the well-known older attack where a client sends headers a tiny piece at a time to keep many connections open. This report is about the gaps that remain even when Slowloris-style header delays are handled.

Exploitation

The attack is described as a sequence of steps rather than a single request.

Step 1: Open connections

From one or more attacking sources, open one or more HTTP connections to the target server. Each connection is one clerk occupied at the counter.

Step 2: Hold each connection open

For each connection opened in step 1:

  1. (Optional) Wait a certain amount of time before sending the first request header.
  2. Send all request headers with regular pausing.
  3. (Optional) Wait a certain amount of time before sending the body data.
  4. Send the request body with regular pausing.

Every substep must be performed by periodically sending the smallest amount of data with the highest delay such that the server does not detect an idle connection. On Node.js 13.0.0 and above there is no idle timeout by default, so the attacker can wait an arbitrary time. On Node.js before 13.0.0, at least one byte every 2 minutes must be sent. One byte is a single character; it is the smallest possible nudge to prove you are still there.

Test cases

The researcher tested four cases:

Case Behaviour
Connection established, none or partial headers sent, then sending paused If server.timeout is not 0, idle detection triggers and closes the connection with no response. With the default timeout of 0 in Node.js 13.0.0 and above, the server is completely vulnerable.
Connection established, headers sent with long delays server.headersTimeout triggers and closes the connection with no response.
Connection established, headers sent, sending paused before the body starts If server.timeout is not 0, idle detection triggers and closes the connection with no response. With the default timeout of 0 in Node.js 13.0.0 and above, the server is completely vulnerable.
Connection established, headers sent, body sent with long delays server.timeout cannot detect the attack and the server is completely vulnerable.

Reading the table: the first and third cases are stopped only when an idle timeout exists. The second case is stopped by the headers timeout. The fourth case, a body that arrives very slowly, is stopped by neither, which is the heart of the report.

Reproduction client

The report provides a sample client that reproduces the problem:

JavaScript
const { createConnection } = require('net')

let start
let response = ''
let body = ''.padEnd(4096, '123')

const client = createConnection({ port: parseInt(process.argv[2], 10) }, () => {
  start = process.hrtime.bigint()

  // Send all the headers quickly so that server.headersTimeout is not triggered
  client.write('POST / HTTP/1.1\r\n')
  client.write('Content-Type: text/plain\r\n')
  client.write(`Content-Length: ${Buffer.byteLength(body)}\r\n`)
  client.write(`\r\n`)

  // Send the body very slower but in away that the server.timeout is not triggered
  let i = 0
  let interval = setInterval(() => {
    client.write(body[i])
    i++

    // Done sending, end the request
    if (i === body.length) {
      clearInterval(interval)
      client.write(`\r\n\r\n`)
    }
  }, 60000)
})

client.on('data', data => {
  response += data
  client.end()
})

client.on('close', () => {
  const duration = Number(process.hrtime.bigint() - start) / 1e9

  console.log(`Receive the following response (${response.length} bytes) in ${duration.toFixed(3)} s:\n\n`)
  console.log(response)
})

Line by line, in plain words:

  • const { createConnection } = require('net') loads the net module and pulls out its createConnection function. This is the tool for opening a raw network connection, below the level of a browser.
  • let start will hold the moment the connection begins, so the program can later report how long everything took.
  • let response = '' is an empty text box where any reply from the server will be collected.
  • let body = ''.padEnd(4096, '123') builds the body: an empty string padded to 4096 characters using the pattern 123. So the body is 4096 bytes long. This is the content the client pretends to send.
  • const client = createConnection({ port: parseInt(process.argv[2], 10) }, () => { opens a connection to the port given as the first command-line argument. parseInt(..., 10) turns that text into a number. The function that follows runs once the connection is established.
  • start = process.hrtime.bigint() records the current high-precision time, so the duration can be measured later.
  • The four client.write(...) lines send the request line and headers immediately: POST / HTTP/1.1, then Content-Type: text/plain, then Content-Length set to the body length, then an empty line. That empty line is the signal that the headers are finished. Sending them quickly is deliberate: it keeps server.headersTimeout from firing, because the headers arrive well within its limit.
  • let i = 0 is a counter for how many body bytes have been sent so far.
  • let interval = setInterval(() => { ... }, 60000) sets up a repeating action every 60000 milliseconds, which is 60 seconds. This is the trick that keeps the connection from ever looking idle.
  • client.write(body[i]) sends exactly one byte of the body on each tick.
  • i++ moves the counter forward.
  • The if (i === body.length) block checks whether the whole body has now been sent. If so, it stops the repeating action with clearInterval(interval) and writes \r\n\r\n to finish the request.
  • client.on('data', data => { ... }) runs whenever the server sends something back. It appends the data to response and then closes the client side with client.end().
  • client.on('close', () => { ... }) runs when the connection closes. It computes the elapsed time in seconds and prints how many bytes came back and how long it took, followed by the response itself.

The client opens a raw connection and writes the request line, Content-Type and Content-Length headers immediately, followed by the blank line that ends the headers. Sending the headers quickly keeps server.headersTimeout from firing. It then writes one byte of the body every 60 seconds, which keeps the connection from ever being considered idle and therefore keeps server.timeout from firing. The body is 4096 bytes, so the client will not receive a response before 4096 minutes. If several copies of the program run in parallel against the same server, the result is service denial.

Root cause

The design gap is that no timeout in the core of Node.js bounds the total lifetime of a request. server.timeout is an idle timeout, so any periodic byte defeats it. server.headersTimeout only covers the headers phase. And because the core never reads request bodies, the application is not called until the body is available, so application-level body timeouts cannot help when the body never starts. Changing the default timeout to 0 in Node.js 13.0.0 removed the 2-minute defence that had previously limited the attack on default configurations.

In shop terms: the clerk is told to give up on silent customers, but never told to give up on customers who keep talking slowly. And the person who actually fills the order is only called once the form is complete, so they never get the chance to set their own limit.

Impact

An attacker can open an arbitrary number of HTTP connections and keep the server busy by never completing the request phase. Over time an unprotected server accumulates pending requests. At some point it reaches its limit on open connections and can no longer serve additional requests, which is a denial of service. The attack has very low complexity and can easily trigger a DDoS on an unprotected server. The impact statement adds that if an attacker executes a significant amount of requests on a target server without completing any, the server will eventually reach the allowed number of open connections and will not be able to serve any further request.

DDoS here means distributed denial of service: the same trick run from many sources at once, so the server is overwhelmed faster.

Fix

The researcher wrote a patch for Node.js (PR 33304) that introduces a new http.Server option called requestTimeout, with a default value in milliseconds of 120000, which is 2 minutes.

When requestTimeout is a positive value, the server starts a new timer set to expire in requestTimeout milliseconds when a new connection is established. The timer is set again if new requests after the first arrive on the same connection, which handles pipelining and keep-alive cases. Pipelining means sending several requests one after another on one connection without waiting for each reply; keep-alive means reusing one connection for many requests instead of opening a new one each time.

The timer is cancelled in the following cases:

  1. When the request body is completely received by the server.
  2. When the response is completed, which handles the case where the application responds to the client without reading the request body.
  3. When the connection is upgraded, as in the WebSocket case. An upgrade is when a connection switches from ordinary web traffic to another protocol, such as WebSocket, which keeps a two-way channel open.

If the timer expires, the server responds with status code 408 and closes the connection, which prevents the DoS attack. Status code 408 means "Request Timeout": the server is saying it waited long enough.

In shop terms, the fix is a stopwatch that starts when the customer arrives and is not reset by slow talking. If the whole order is not done within two minutes, the clerk politely says "time's up" and serves the next person.

Variants to test

  • Slow body transmission against a default Node.js 13.0.0 or later server: a positive result is a connection that stays open far beyond any configured timeout while the client trickles one byte at a time.
  • Headers sent quickly, body never started: a positive result is a connection held open with no application code invoked and no response, on a server whose server.timeout is 0.
  • Delayed start of headers: a positive result is a connection that survives past server.headersTimeout because the delay occurs before the headers phase begins.
  • Pipelined or keep-alive requests on the same connection: a positive result is a connection that keeps accepting new requests without the per-request timer being reset in a way that bounds total lifetime.
  • Application-level body parsers (fastify, restify, busboy via fastify-multipart or multer, raw-body via body-parser): a positive result is a request whose body is partially sent and then stalled without the parser imposing a sending timeout.

Hunting notes

This class of bug tends to hide wherever a server offers an idle-based timeout instead of a total-request timeout, and wherever request bodies are handled outside the core framework. During recon, the signals are a Node.js 13.0.0 or later default configuration, a server.timeout of 0, and body reading delegated to application modules. The report states that a single client receives no response before 4096 minutes and that multiple parallel executions against the same server will result in service denial.

Glossary

  • Node.js: a runtime that lets JavaScript run outside a browser, commonly used to build web servers.
  • HTTP: the language browsers and servers use to exchange requests and responses.
  • Server: a program that listens for connections and answers requests.
  • Connection: an open channel between a client and a server, occupying a slot until it closes.
  • Request: a message asking the server to do something, made of headers and an optional body.
  • Headers: the short labels at the start of a request describing what is being asked and how.
  • Body: the actual content of a request, such as form data or a file.
  • Timeout: a rule that gives up on something after a set amount of time.
  • Idle timeout: a timeout that only counts time when nothing at all is being sent, so any periodic byte resets it.
  • server.timeout: the Node.js setting that limits how long a connection may be idle, including server processing time.
  • server.headersTimeout: the Node.js setting, added in Node 11.3.0, that limits how long the server waits for the complete request headers.
  • requestTimeout: the new Node.js setting proposed in the fix, defaulting to 120000 milliseconds, that bounds the total lifetime of a request.
  • net module: the part of Node.js used to open raw network connections.
  • Port: a numbered door on a machine that a server listens on.
  • Byte: a single unit of data, roughly one character.
  • Body parser: an add-on module that reads and interprets request bodies, such as fastify, restify, busboy, raw-body, body-parser, multer and fastify-multipart.
  • Denial of service (DoS): making a service unavailable to its legitimate users.
  • DDoS: a denial of service launched from many sources at once.
  • Resource exhaustion (CWE-400): using up a limited resource, such as connection slots, until nothing is left.
  • Slowloris: an older attack that keeps many connections open by sending headers very slowly.
  • Pipelining: sending several requests on one connection without waiting for each reply.
  • Keep-alive: reusing one connection for multiple requests.
  • Upgrade: switching a connection from HTTP to another protocol, such as WebSocket.
  • WebSocket: a protocol that keeps a two-way channel open between client and server.
  • Status code 408: the HTTP reply meaning "Request Timeout".
  • CVSS: a standard scoring system for the severity of a vulnerability; 9.3 is in the critical range.
  • CWE: a catalogue of common weakness types; CWE-400 is uncontrolled resource consumption.
  • Serverless: a deployment style where code runs on demand and requests may legitimately take a long time, which motivated the change of the default timeout to 0.

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.