Skip to content

Commit

Permalink
http2: don't expose the original socket through the socket proxy
Browse files Browse the repository at this point in the history
Refs: #22486

Backport-PR-URL: #22850
PR-URL: #22650
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
szmarczak authored and BethGriggs committed Oct 16, 2018
1 parent 60f7bfa commit 805bf40
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 27 deletions.
14 changes: 12 additions & 2 deletions lib/internal/http2/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -630,14 +630,19 @@ 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':
case 'pause':
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];
Expand All @@ -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':
Expand All @@ -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];
Expand Down
11 changes: 11 additions & 0 deletions test/parallel/test-http2-socket-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down
25 changes: 0 additions & 25 deletions test/parallel/test-http2-unbound-socket-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
});
}));
}));
}));

0 comments on commit 805bf40

Please sign in to comment.