From 6657553dc81febba9c6509be6d00e0bb823eee39 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Tue, 21 Jul 2020 20:53:07 +0200 Subject: [PATCH] http: don't write error to socket The state of the connection is unknown at this point and writing to it can corrupt client state before it is aware of an error. --- lib/_http_server.js | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/lib/_http_server.js b/lib/_http_server.js index 88ae7e823f09a6..39df2f3575cc7e 100644 --- a/lib/_http_server.js +++ b/lib/_http_server.js @@ -604,25 +604,12 @@ function onParserTimeout(server, socket) { } const noop = () => {}; -const badRequestResponse = Buffer.from( - `HTTP/1.1 400 ${STATUS_CODES[400]}${CRLF}` + - `Connection: close${CRLF}${CRLF}`, 'ascii' -); -const requestHeaderFieldsTooLargeResponse = Buffer.from( - `HTTP/1.1 431 ${STATUS_CODES[431]}${CRLF}` + - `Connection: close${CRLF}${CRLF}`, 'ascii' -); function socketOnError(e) { // Ignore further errors this.removeListener('error', socketOnError); this.on('error', noop); if (!this.server.emit('clientError', e, this)) { - if (this.writable) { - const response = e.code === 'HPE_HEADER_OVERFLOW' ? - requestHeaderFieldsTooLargeResponse : badRequestResponse; - this.write(response); - } this.destroy(e); } }