Http response is not ended although underlying socket is already destroyed
When a Node.js HTTP server's underlying socket is abruptly destroyed, the response object does not emit 'end', 'finish', or 'error' events, leaving the response open. An attacker could cause resource exhaustion or denial of service by keeping file handles or proxy streams open until the server is restarted.
- Disclosed after 5 months
Summary: When node server receives http request and hooks to end, finish and error events are attached on response object to handle cases when response is closed/ended but underlying socket is abruptly terminated then none of those events is fired. This leads to state when response seems to be still alive, although it's internal state of connection is destroyed. So basically after socket is destroyed this event is not propagated to http response object.
Description: This can lead to two states:
-
If response is handled locally it remains open and if used to eg. stream data from file it keeps file handle opened until server is stopped.
-
In case of request proxying another response stream remains open which can lead to DOS on target server where the request is proxyed to. In case of Apache httpd the server stops responding after certain number of such requests if no timeout is configured.
In both cases the system becomes unusable after certain time, based on incoming traffic and remains in this state until restarted.
Steps To Reproduce:
- start node http server (server.js)
- connect with example client (client.js)
- http request will remain active although underlying socket is already destroyed until scheduled timeout kicks in and emits error which triggers attached error handler
Impact:
Attack can possibly lead to open handles exhausting or in case of request proxying to eg. Apache httpd DOS attack.
Supporting Material/References:
Below are details about platform tested and code to reproduce with proxy example in attachments. I have used stream's utility function pipeline to handle emitted events on streams.
Version: v12.8.1 Platform: 4.15.0-58-generic #54~16.04.1-Ubuntu x86_64 GNU/Linux Subsystem: net/http
Impact
DOS attack and resource exhausting.
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 HTTP response object does not listen for the underlying socket's 'close' event, so it never emits 'end', 'finish', or 'error' when the socket is destroyed.
Impact
This could lead to open handles being exhausted or, when proxying to a server like Apache httpd, a denial of service.
What the attacker needed
Node.js HTTP server; ability to abruptly destroy socket
How it was found
- Start the Node.js HTTP server.
- Connect with the example client.
- Observe that the HTTP request remains active even though the underlying socket is destroyed, until a scheduled timeout emits an error.
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.
In a web server, when a client disconnects unexpectedly, the server should clean up the connection. Here, the server's response object never learns that the connection is gone, so it keeps resources open. An attacker could repeatedly cause this to exhaust 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.