From a7e2aab4ac49063e49843737328ed3d45dd57be3 Mon Sep 17 00:00:00 2001 From: iskore Date: Sat, 3 Feb 2018 21:49:14 -0500 Subject: [PATCH] http: setEncoding override for incoming packets added override to socket.setEncoding to not allow encoding changes for incoming HTTP requests added tests to ensure method throws JavaScript error because an HTTP buffer must be in US-ASCII, this function should not be allowed and should throw an Error currently, the process encounters a fatal v8 error and crashes error report detailed in [issue #18118](nodejs#18118) Fixes: nodejs#18118 Ref: nodejs#18178 --- lib/_http_server.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/_http_server.js b/lib/_http_server.js index 498800dd1ee445..2bd8bbd226d9a6 100644 --- a/lib/_http_server.js +++ b/lib/_http_server.js @@ -383,6 +383,7 @@ function connectionListenerInternal(server, socket) { // Override on to unconsume on `data`, `readable` listeners socket.on = socketOnWrap; + socket.setEncoding = socketSetEncoding; // We only consume the socket if it has never been consumed before. if (socket._handle) { @@ -683,6 +684,10 @@ function onSocketPause() { } } +function socketSetEncoding() { + throw new errors.Error('ERR_METHOD_NOT_IMPLEMENTED', 'setEncoding'); +} + function unconsume(parser, socket) { if (socket._handle) { if (parser._consumed)