From 4643c63fc73e1e5a8374a00a6fa92b28ea45885f Mon Sep 17 00:00:00 2001 From: Nick Soggin Date: Mon, 5 Mar 2018 19:29:58 -0500 Subject: [PATCH] docs, errors, http: disallow setEncoding on incoming packets added ERR_HTTP_INCOMING_SOCKET_ENCODING error and error docs throw ERR_HTTP_INCOMING_SOCKET_ENCODING error when incoming request socket encoding is manipulated error report detailed in nodejs#18118 Fixes: nodejs#18118 Ref: nodejs#18178 --- doc/api/errors.md | 6 ++++++ lib/_http_server.js | 2 +- lib/internal/errors.js | 3 +++ test/parallel/test-http-socket-encoding-error.js | 2 +- 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/doc/api/errors.md b/doc/api/errors.md index 62a62d76656223..5889e6e66a70cd 100644 --- a/doc/api/errors.md +++ b/doc/api/errors.md @@ -794,6 +794,12 @@ An invalid symlink type was passed to the [`fs.symlink()`][] or An attempt was made to add more headers after the headers had already been sent. + +### ERR_HTTP_INCOMING_SOCKET_ENCODING + +An attempt was made to manipulate the encoding of an incoming request packet. +This is not allowed (RFC2616). + ### ERR_HTTP_INVALID_HEADER_VALUE diff --git a/lib/_http_server.js b/lib/_http_server.js index 2bd8bbd226d9a6..25c23288a09f3d 100644 --- a/lib/_http_server.js +++ b/lib/_http_server.js @@ -685,7 +685,7 @@ function onSocketPause() { } function socketSetEncoding() { - throw new errors.Error('ERR_METHOD_NOT_IMPLEMENTED', 'setEncoding'); + throw new errors.Error('ERR_HTTP_INCOMING_SOCKET_ENCODING', 'setEncoding'); } function unconsume(parser, socket) { diff --git a/lib/internal/errors.js b/lib/internal/errors.js index f8073d15fe8d49..426c154fb19557 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -762,6 +762,9 @@ E('ERR_HTTP2_STREAM_SELF_DEPENDENCY', E('ERR_HTTP2_UNSUPPORTED_PROTOCOL', 'protocol "%s" is unsupported.', Error); E('ERR_HTTP_HEADERS_SENT', 'Cannot %s headers after they are sent to the client', Error); +E('ERR_HTTP_INCOMING_SOCKET_ENCODING', + 'Incoming socket encoding is not allowed (RFC 2616)', + Error); E('ERR_HTTP_INVALID_HEADER_VALUE', 'Invalid value "%s" for header "%s"', TypeError); E('ERR_HTTP_INVALID_STATUS_CODE', 'Invalid status code: %s', RangeError); diff --git a/test/parallel/test-http-socket-encoding-error.js b/test/parallel/test-http-socket-encoding-error.js index cfb96f4f81bc2e..58a22b9fb6400e 100644 --- a/test/parallel/test-http-socket-encoding-error.js +++ b/test/parallel/test-http-socket-encoding-error.js @@ -8,7 +8,7 @@ const server = http.createServer().listen(0, connectToServer); server.on('connection', (socket) => { common.expectsError(() => socket.setEncoding(''), { - code: 'ERR_METHOD_NOT_IMPLEMENTED', + code: 'ERR_HTTP_INCOMING_SOCKET_ENCODING', type: Error });