Skip to content

Commit

Permalink
http: don't write error to socket
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ronag committed Jul 21, 2020
1 parent 2c05bee commit 6657553
Showing 1 changed file with 0 additions and 13 deletions.
13 changes: 0 additions & 13 deletions lib/_http_server.js
Expand Up @@ -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);
}
}
Expand Down

0 comments on commit 6657553

Please sign in to comment.