From 805bf40bfdc4747acd69b16112d693508685136c Mon Sep 17 00:00:00 2001 From: Szymon Marczak Date: Sun, 2 Sep 2018 12:07:20 +0200 Subject: [PATCH] http2: don't expose the original socket through the socket proxy Refs: https://github.com/nodejs/node/pull/22486 Backport-PR-URL: https://github.com/nodejs/node/pull/22850 PR-URL: https://github.com/nodejs/node/pull/22650 Reviewed-By: Matteo Collina Reviewed-By: Luigi Pinca Reviewed-By: Anatoli Papirovski Reviewed-By: James M Snell --- lib/internal/http2/core.js | 14 +++++++++-- test/parallel/test-http2-socket-proxy.js | 11 ++++++++ .../test-http2-unbound-socket-proxy.js | 25 ------------------- 3 files changed, 23 insertions(+), 27 deletions(-) diff --git a/lib/internal/http2/core.js b/lib/internal/http2/core.js index 9aa7a0e2a2f79e..575e4152c94228 100644 --- a/lib/internal/http2/core.js +++ b/lib/internal/http2/core.js @@ -630,7 +630,9 @@ const proxySocketHandler = { get(session, prop) { switch (prop) { case 'setTimeout': - return session.setTimeout.bind(session); + case 'ref': + case 'unref': + return session[prop].bind(session); case 'destroy': case 'emit': case 'end': @@ -638,6 +640,9 @@ const proxySocketHandler = { case 'read': case 'resume': case 'write': + case 'setEncoding': + case 'setKeepAlive': + case 'setNoDelay': throw new errors.Error('ERR_HTTP2_NO_SOCKET_MANIPULATION'); default: const socket = session[kSocket]; @@ -656,7 +661,9 @@ const proxySocketHandler = { set(session, prop, value) { switch (prop) { case 'setTimeout': - session.setTimeout = value; + case 'ref': + case 'unref': + session[prop] = value; return true; case 'destroy': case 'emit': @@ -665,6 +672,9 @@ const proxySocketHandler = { case 'read': case 'resume': case 'write': + case 'setEncoding': + case 'setKeepAlive': + case 'setNoDelay': throw new errors.Error('ERR_HTTP2_NO_SOCKET_MANIPULATION'); default: const socket = session[kSocket]; diff --git a/test/parallel/test-http2-socket-proxy.js b/test/parallel/test-http2-socket-proxy.js index 17830495addc63..209c49e719c676 100644 --- a/test/parallel/test-http2-socket-proxy.js +++ b/test/parallel/test-http2-socket-proxy.js @@ -38,6 +38,9 @@ server.on('stream', common.mustCall(function(stream, headers) { common.expectsError(() => socket.read, errMsg); common.expectsError(() => socket.resume, errMsg); common.expectsError(() => socket.write, errMsg); + common.expectsError(() => socket.setEncoding, errMsg); + common.expectsError(() => socket.setKeepAlive, errMsg); + common.expectsError(() => socket.setNoDelay, errMsg); common.expectsError(() => (socket.destroy = undefined), errMsg); common.expectsError(() => (socket.emit = undefined), errMsg); @@ -46,10 +49,18 @@ server.on('stream', common.mustCall(function(stream, headers) { common.expectsError(() => (socket.read = undefined), errMsg); common.expectsError(() => (socket.resume = undefined), errMsg); common.expectsError(() => (socket.write = undefined), errMsg); + common.expectsError(() => (socket.setEncoding = undefined), errMsg); + common.expectsError(() => (socket.setKeepAlive = undefined), errMsg); + common.expectsError(() => (socket.setNoDelay = undefined), errMsg); assert.doesNotThrow(() => (socket.on = socket.on)); assert.doesNotThrow(() => (socket.once = socket.once)); + socket.unref(); + assert.strictEqual(socket._handle.hasRef(), false); + socket.ref(); + assert.strictEqual(socket._handle.hasRef(), true); + stream.respond(); socket.writable = 0; diff --git a/test/parallel/test-http2-unbound-socket-proxy.js b/test/parallel/test-http2-unbound-socket-proxy.js index 44f113bac962f7..18881574f2c09b 100644 --- a/test/parallel/test-http2-unbound-socket-proxy.js +++ b/test/parallel/test-http2-unbound-socket-proxy.js @@ -39,31 +39,6 @@ server.listen(0, common.mustCall(() => { }, { code: 'ERR_HTTP2_SOCKET_UNBOUND' }); - common.expectsError(() => { - socket.ref(); - }, { - code: 'ERR_HTTP2_SOCKET_UNBOUND' - }); - common.expectsError(() => { - socket.unref(); - }, { - code: 'ERR_HTTP2_SOCKET_UNBOUND' - }); - common.expectsError(() => { - socket.setEncoding(); - }, { - code: 'ERR_HTTP2_SOCKET_UNBOUND' - }); - common.expectsError(() => { - socket.setKeepAlive(); - }, { - code: 'ERR_HTTP2_SOCKET_UNBOUND' - }); - common.expectsError(() => { - socket.setNoDelay(); - }, { - code: 'ERR_HTTP2_SOCKET_UNBOUND' - }); })); })); }));