Fix for CVE-2018-12122 can be bypassed via keep-alive requests
The fix for CVE-2018-12122 introduced a headersTimeout that destroys sockets if headers are not fully received in time, but the timestamp used to enforce this is not reset for subsequent requests on a keep-alive connection. An attacker could send headers slowly on a keep-alive connection to bypass the timeout and potentially cause a denial of service.
- Disclosed after 14 months
Summary: Fix for CVE-2018-12122 can be bypassed via keep-alive requests
Description:
I'm not a security expert, neither I'm familiar with Node.js core, so please forgive me if this report is inaccurate (and in that case, sorry for your time).
While investigating the issue #515I checked out the fix to Fix for CVE-2018-12122 in node 8.14.0 and - according to my tests - the fix can be bypassed using a keep-alive connection.
The core of the fix is to introduce headersTimeout, which is a timeout that destroy the socket if all headers are not received within that timeout. As far as I can see from this changeset, the parser.parsingHeadersStart timestamp is set on connectionListenerInternal(), reset to zero once the full request headers are received (this is used as a short circuit in onParserExecute()) , but it's never set againt to a timestamp once a subsequent request on the same keep-alive connection is received.
Steps To Reproduce
- Run an HTTP server and lower
headersTimeoutto 10s for simplicity (faster to test)
const http = require("http");
const server = http.createServer((req, res) => {
res.writeHead(200);
res.end();
});
server.headersTimeout = 10000;
server.keepAliveTimeout = 60000;
server.listen(4050);
-
Connect with
telnet localhost 4050 -
Send the first request, typing...
GET / HTTP/1.1
Connection: keep-alive
- Then, once the server response is received, send only the first line of the subsequent request on the same connection:
GET / HTTP/1.1
- Wait longer than the headersTimeout and send a second header
Host: localhost
- Wait more time, if you want send further headers, and finally a newline to signal the end of the headers request. The server will not destroy the socket / close the connection after 10s (or whatever
headersTimeoutis set to), but will successfully reply.
Impact
To my understanding, it has the same impact of CVE-2018-12122, but I may also be terribly wrong.
Supporting Material/References:
N/A
Impact
It may DoS a Node.js application.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the parser.parsingHeadersStart timestamp is only set when a connection is first established and not reset for subsequent requests on the same keep-alive connection, so the headersTimeout check is skipped.
Impact
It may allow a denial of service against a Node.js application by keeping connections open longer than intended.
What the attacker needed
Node.js server with headersTimeout set; Attacker can open a keep-alive connection
How it was found
- Run an HTTP server with a low headersTimeout (e.g., 10 seconds).
- Connect to the server using telnet.
- Send a first request with Connection: keep-alive.
- After receiving the response, send only the first line of a second request.
- Wait longer than headersTimeout, then send another header.
- Wait more, send further headers, and finally end the headers; the server does not close the connection and replies successfully.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A web server has a timeout to stop slow clients from holding connections open too long. This report shows that after the first request, the timer is not restarted for later requests on the same connection, so a client can keep sending data slowly without being disconnected. That could let an attacker tie up server resources.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.