Slowloris, body parsing
The body-parser library does not enforce a timeout on slow request bodies, so an attacker can keep a connection open by sending one byte per second. This can exhaust server resources and cause a denial of service.
Originally disclosed on HackerOne
- Triaged in 4 months
- Fixed in 7 months
- Paid in 13 months
- Disclosed after 8 months
Summary: [add summary of the vulnerability] Attackers can cause a Denial of Service by sending HTTP request body data extremely slowly to keep a connection open by maintaining activity, and use resources over an extended period.
Description: [add more details about this vulnerability]
Body data is sent one byte at a time, slowly, in a HTTP request. The connection stays open, hogging resources. There is no builtin feature that can make this trigger a timeout, as long as the bytes are sent at an interval lower than the server.timeout value if it is set. May not technically be a Node.js bug since it doesn't handle parsing of the body, but the typically body parsing library (e.g. https://www.npmjs.com/package/body-parser) does not implement any feature to mitigate the vulnerability.
Steps To Reproduce:
(Add details for how we can reproduce the issue)
- Start a HTTP server and set the server timeout to 2 seconds.
- Add a library that parses the request body.
- Open a connection to the server.
- Send a HTTP header.
- Send the body, 1 byte per second.
Impact: [add why this issue matters]
See summary.
Supporting Material/References:
Code to reproduce
const bodyParser = require('body-parser');
const express = require('express');
const net = require('net');
const http = require('http');
async function run() {
const expressApp = express();
expressApp.use(bodyParser.json());
expressApp.use(async (req, res) => {
res.send({body: req.body});
});
const server = http.createServer(expressApp);
setInterval(() => {
console.log(server.connections);
}, 1000);
server.keepAliveTimeout = 2000;
server.timeout = 2000;
await new Promise(resolve => {
server.listen(3000, '127.0.0.1', () => {
resolve();
});
});
const client = new net.Socket();
const length = 5000;
const msg = `GET / HTTP/1.1
Host: localhost:3000
Accept: */*
Content-Type: application/json
Content-Length: ${length}
["`;
client.connect(3000, '127.0.0.1', async function () {
client.write(msg);
for (let i = 0; i < length - 4; i++) {
await new Promise(resolve => {
setTimeout(resolve, 1000);
});
client.write('' + (i % 10));
}
client.write('"]');
});
}
run();
Impact
Attackers can cause a Denial of Service by sending HTTP request body data extremely slowly to keep a connection open and use resources over an extended period.
Context
Node.js is the runtime at the centre of this report, and the asset is the Node.js repository itself. The behaviour under discussion is not in Node's HTTP parser but in how a connection carrying a request body is kept alive. Node's HTTP server exposes a server.timeout setting, and the report describes what happens when a client sends body data slowly enough that each byte arrives within that timeout window.
The researcher is explicit about the scope: this may not technically be a Node.js bug, because Node does not parse the request body itself. The typical body parsing library, body-parser, does not implement any feature to mitigate the issue either. The weakness is classified as uncontrolled resource consumption, and the report was rated low severity with a 250 USD bounty.
Setup
The reproduction uses a small Express application with body-parser mounted as JSON middleware, wrapped in a Node http server. The server is configured with a two second timeout:
server.keepAliveTimeout = 2000;
server.timeout = 2000;
The client is a raw net.Socket, not a browser or an HTTP library, so the researcher controls exactly when each byte is written. The server listens on [redacted]:3000 and the client connects to the same address. No accounts, roles or special versions are involved; the precondition is simply a server that parses request bodies and has a timeout configured.
Finding it
The observation is that body data can be sent one byte at a time, slowly, in an HTTP request. The connection stays open and hogs resources. There is no builtin feature that can make this trigger a timeout, as long as the bytes are sent at an interval lower than the server.timeout value if it is set. In other words, the timeout measures inactivity, and a client that keeps trickling bytes never becomes inactive.
Exploitation
Step 1: Start an HTTP server with a two second timeout
The server is created from the Express app and given both a keep-alive timeout and a general timeout of 2000 milliseconds. A one second interval logs server.connections so the open connection count can be watched.
Step 2: Add a library that parses the request body
bodyParser.json() is mounted before the handler, so the request body is consumed by the parser. The handler simply echoes the parsed body back:
expressApp.use(bodyParser.json());
expressApp.use(async (req, res) => {
res.send({body: req.body});
});
Step 3: Open a connection to the server
A raw TCP socket is created and connected to port 3000 on localhost:
const client = new net.Socket();
client.connect(3000, '[redacted]', async function () {
Step 4: Send an HTTP header
The client writes a request head declaring a JSON body of 5000 bytes, then opens a JSON array with [":
The request declares a JSON body of 5000 bytes via Content-Length. The body begins with [".
Step 5: Send the body, one byte per second
The loop waits one second before each write and sends a single digit, cycling through i % 10, until length - 4 bytes have been sent. It then closes the JSON with "]:
for (let i = 0; i < length - 4; i++) {
await new Promise(resolve => {
setTimeout(resolve, 1000);
});
client.write('' + (i % 10));
}
client.write('"]');
Each byte arrives inside the two second timeout, so the connection is not considered idle. The report does not include a captured response or a measurement of how long the connection survived; the supporting material is the reproduction code itself.
Root cause
The report says bytes sent at an interval below server.timeout do not trigger a timeout. As long as bytes keep arriving at an interval below server.timeout, the connection is active and the timer does not fire. Node does not parse the body, so it has no notion of a request body that is progressing too slowly, and body-parser does not implement any feature to mitigate the vulnerability. The report notes there is no builtin feature that makes this trigger a timeout.
Impact
An attacker can cause a denial of service by sending HTTP request body data extremely slowly to keep a connection open and use resources over an extended period. The report frames this in terms of connections and resources rather than a specific number of connections needed or a measured effect on a particular deployment, and it hedges on whether the behaviour should be considered a Node.js bug at all.
Fix
The report does not describe a fix or a change made in response. It only notes the gap: Node has no builtin feature that makes a slow body trigger a timeout, and the typical body parsing library does not mitigate it.
Variants to test
- Slow headers rather than a slow body: send the request line and headers one fragment at a time, each within the configured timeout, and watch whether the connection count stays elevated.
- Slow body against a different parser: repeat the same trickle with another body parsing middleware or framework to see whether any of them enforce a total request duration rather than an idle timeout.
- Timeout boundary testing: vary the interval between bytes around the configured
server.timeoutvalue to find where the server does close the connection. A positive result is a connection that survives many multiples of the timeout. - Keep-alive interaction: check whether
keepAliveTimeoutchanges anything once the body has been fully received, since the report sets both values but only exercises the body phase.
Hunting notes
This kind of issue hides wherever a server accepts a request body and relies on an idle timeout as its only protection. The signal during recon is a target that advertises a timeout setting and a body parsing layer, with no evidence of a maximum request duration. The report provides reproduction steps: a server with a two second timeout and a client that writes one byte per second.
What happened, in plain words
Imagine a restaurant that only clears a table when nobody has touched it for two minutes. A customer who takes one tiny sip of water every ninety seconds can sit there all evening, and the table is never freed for anyone else. That is the idea behind this report: a web server that only closes a connection when it has been quiet for a while can be kept open indefinitely by a client that keeps sending a trickle of data, just under the quiet threshold.
The report describes how a Node.js HTTP server using body-parser can be held open this way. The client sends the body of a request one byte per second. Each byte arrives within the server's two second timeout, so the connection is not considered idle.
A few terms before we go further:
- Node.js is a program that lets people run JavaScript outside a browser, typically to build web servers and other network services. The asset here is the Node.js project's own code repository.
- A server is a program that waits for other computers to connect and asks for something, then answers.
- A connection is the open channel between a client (for example a browser) and a server. While it is open, the server keeps some memory and bookkeeping for it.
- A request body is the part of a request that carries data, for example the contents of a form or a JSON document. The headers are the short lines at the top of the request that describe it (what address is wanted, what kind of data is being sent, how long the body is).
- JSON is a plain text format for structured data, built from objects
{}, arrays[], strings in quotes and numbers. It is very common in web APIs. - An API (application programming interface) is the set of addresses and rules a service offers so other programs can talk to it. A web API is usually reached over HTTP, the same protocol a browser uses.
- A timeout is a limit on how long the server will wait for something. Here it is an inactivity timeout: it fires when nothing has arrived for a set period, not when a request has taken too long overall.
- A denial of service (DoS) is an attack that stops a service from working properly for legitimate users, usually by consuming its resources (connections, memory, CPU) so there is nothing left for them.
- Uncontrolled resource consumption is the formal name for that class of weakness: the program uses up a resource without any limit on how much an attacker can make it use.
Context
Node.js is the runtime at the centre of this report, and the asset is the Node.js repository itself. The behaviour under discussion is not in Node's HTTP parser but in how a connection carrying a request body is kept alive. Node's HTTP server exposes a server.timeout setting, and the report describes what happens when a client sends body data slowly enough that each byte arrives within that timeout window.
The researcher is explicit about the scope: this may not technically be a Node.js bug, because Node does not parse the request body itself. Parsing means reading the raw bytes and turning them into usable data, for example turning the text ["a"] into a list containing the string a. Node hands the raw body to whatever library the application has chosen. The typical body parsing library, body-parser, does not implement any feature to mitigate the issue either. The weakness is classified as uncontrolled resource consumption, and the report was rated low severity with a 250 USD bounty.
Setup
The reproduction uses a small Express application with body-parser mounted as JSON middleware, wrapped in a Node http server. Express is a popular framework for building web servers in Node.js; middleware is a piece of code that runs on every request before your own handler, and can inspect or transform the request. The server is configured with a two second timeout:
server.keepAliveTimeout = 2000;
server.timeout = 2000;
Both values are in milliseconds, so 2000 means two seconds. server.timeout is the general inactivity timeout for a connection. keepAliveTimeout is a related setting for how long an idle connection is kept open between requests, so that a client can reuse it instead of opening a new one.
The client is a raw net.Socket, not a browser or an HTTP library, so the researcher controls exactly when each byte is written. A socket is the programmatic handle on one end of a network connection; writing to it sends bytes, and you decide the timing yourself. A browser would never let you send a request body one byte per second, which is why the reproduction uses a socket directly. The server listens on [redacted]:3000 and the client connects to the same address. [redacted] is the loopback address, meaning "this same computer", so everything stays local. No accounts, roles or special versions are involved; the precondition is simply a server that parses request bodies and has a timeout configured.
Finding it
The observation is that body data can be sent one byte at a time, slowly, in an HTTP request. The connection stays open and hogs resources. There is no builtin feature that can make this trigger a timeout, as long as the bytes are sent at an interval lower than the server.timeout value if it is set. In other words, the timeout measures inactivity, and a client that keeps trickling bytes never becomes inactive.
Exploitation
Step 1: Start an HTTP server with a two second timeout
The server is created from the Express app and given both a keep-alive timeout and a general timeout of 2000 milliseconds. A one second interval logs server.connections so the open connection count can be watched. A one second interval logs server.connections.
Step 2: Add a library that parses the request body
bodyParser.json() is mounted before the handler, so the request body is consumed by the parser. The handler simply echoes the parsed body back:
expressApp.use(bodyParser.json());
expressApp.use(async (req, res) => {
res.send({body: req.body});
});
Line by line: expressApp.use(bodyParser.json()) tells Express to run the JSON body parser on every incoming request, so the raw bytes are read and turned into a JavaScript value. expressApp.use(async (req, res) => { ... }) registers the handler that runs after the parser, receiving the request req and the response res. res.send({body: req.body}) sends back a JSON object whose body field is whatever the parser produced. The parser is included because it reads the request body.
Step 3: Open a connection to the server
A raw TCP socket is created and connected to port 3000 on localhost:
const client = new net.Socket();
client.connect(3000, '[redacted]', async function () {
new net.Socket() creates an empty socket object. client.connect(3000, '[redacted]', ...) opens a TCP connection to port 3000 on the local machine, and the function passed as the third argument runs once the connection is established. TCP is the underlying transport that HTTP runs on; opening it directly lets the client write arbitrary bytes at arbitrary times.
Step 4: Send an HTTP header
The client writes a request head declaring a JSON body of 5000 bytes, then opens a JSON array with [":
Line by line: GET / HTTP/1.1 is the request line, asking for the path / using HTTP version 1.1. Host: localhost:3000 says which host and port the request is for. Accept: */* says the client will accept any response content type. Content-Type: application/json declares that the body is JSON. Content-Length: 5000 says the body will be exactly 5000 bytes long. The blank line separates the headers from the body, and [" is the first two bytes of the body.
The request declares a JSON body of 5000 bytes via Content-Length. The body begins with [".
Step 5: Send the body, one byte per second
The loop waits one second before each write and sends a single digit, cycling through i % 10, until length - 4 bytes have been sent. It then closes the JSON with "]:
for (let i = 0; i < length - 4; i++) {
await new Promise(resolve => {
setTimeout(resolve, 1000);
});
client.write('' + (i % 10));
}
client.write('"]');
Line by line: for (let i = 0; i < length - 4; i++) counts from zero up to length - 4, which is 4996 iterations. await new Promise(resolve => { setTimeout(resolve, 1000); }) pauses for one second before each iteration, so one byte is sent per second. client.write('' + (i % 10)) sends a single character, the digit i % 10, which cycles 0, 1, 2, ... 9, 0, 1 and so on. client.write('"]') finally sends the two closing characters, completing the JSON array and the declared 5000 bytes.
Each byte arrives inside the two second timeout, so the connection is not considered idle. The report does not include a captured response or a measurement of how long the connection survived; the supporting material is the reproduction code itself.
Root cause
The report says bytes sent at an interval below server.timeout do not trigger a timeout. As long as bytes keep arriving at an interval below server.timeout, the connection is active and the timer does not fire. Node does not parse the body, so it has no notion of a request body that is progressing too slowly, and body-parser does not implement any feature to mitigate the vulnerability. The report notes there is no builtin feature that makes this trigger a timeout.
Impact
An attacker can cause a denial of service by sending HTTP request body data extremely slowly to keep a connection open and use resources over an extended period. The report frames this in terms of connections and resources rather than a specific number of connections needed or a measured effect on a particular deployment, and it hedges on whether the behaviour should be considered a Node.js bug at all.
Fix
The report does not describe a fix or a change made in response. It only notes the gap: Node has no builtin feature that makes a slow body trigger a timeout, and the typical body parsing library does not mitigate it.
Variants to test
- Slow headers rather than a slow body: send the request line and headers one fragment at a time, each within the configured timeout, and watch whether the connection count stays elevated.
- Slow body against a different parser: repeat the same trickle with another body parsing middleware or framework to see whether any of them enforce a total request duration rather than an idle timeout.
- Timeout boundary testing: vary the interval between bytes around the configured
server.timeoutvalue to find where the server does close the connection. A positive result is a connection that survives many multiples of the timeout. - Keep-alive interaction: check whether
keepAliveTimeoutchanges anything once the body has been fully received, since the report sets both values but only exercises the body phase.
Hunting notes
This kind of issue hides wherever a server accepts a request body and relies on an idle timeout as its only protection. The signal during recon is a target that advertises a timeout setting and a body parsing layer, with no evidence of a maximum request duration. The report provides reproduction steps: a server with a two second timeout and a client that writes one byte per second.
Glossary
- Node.js: a runtime that runs JavaScript outside a browser, commonly used to build web servers.
- Server: a program that waits for connections from other computers and answers their requests.
- Client: the program that connects to a server and sends requests.
- Connection: the open channel between a client and a server, which the server keeps track of while it is open.
- HTTP: the protocol browsers and servers use to exchange requests and responses.
- TCP: the lower-level transport that HTTP runs on, carrying bytes between two machines.
- Socket: the programmatic handle on one end of a network connection, which you can write bytes to.
- Request body: the part of a request that carries data, such as a JSON document.
- Headers: the short lines at the top of a request or response that describe it.
- JSON: a plain text format for structured data, built from objects, arrays, strings and numbers.
- API: the set of addresses and rules a service offers so other programs can talk to it.
- Timeout: a limit on how long the server waits for something, here for inactivity rather than total duration.
- Inactivity timeout: a timeout that fires only when nothing has arrived for a set period.
- Keep-alive: keeping a connection open between requests so it can be reused.
server.timeout: Node's general inactivity timeout setting for a connection, in milliseconds.keepAliveTimeout: the setting for how long an idle connection is kept open between requests.- Express: a popular framework for building web servers in Node.js.
- Middleware: code that runs on every request before your own handler, and can inspect or transform it.
body-parser: a common library that reads a request body and turns it into usable data.- Parsing: reading raw bytes and turning them into usable structured data.
- Denial of service (DoS): an attack that stops a service working for legitimate users by consuming its resources.
- Uncontrolled resource consumption: a weakness where a program uses up a resource without any limit on how much an attacker can make it use.
- Loopback address (
[redacted]): the address that means "this same computer". - Recon: the early phase of looking at a target to understand what it runs and where weaknesses might be.
- Severity: a rating of how serious a vulnerability is, here low.
- Bounty: a payment made to a researcher for reporting a valid vulnerability.