Skip to content

Commit 4cdecc5

Browse files
szmarczaktargos
authored andcommitted
http2: don't expose the original socket through the socket proxy
Refs: #22486 PR-URL: #22650 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 2ca2199 commit 4cdecc5

File tree

3 files changed

+23
-27
lines changed

3 files changed

+23
-27
lines changed

lib/internal/http2/core.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -646,14 +646,19 @@ const proxySocketHandler = {
646646
get(session, prop) {
647647
switch (prop) {
648648
case 'setTimeout':
649-
return session.setTimeout.bind(session);
649+
case 'ref':
650+
case 'unref':
651+
return session[prop].bind(session);
650652
case 'destroy':
651653
case 'emit':
652654
case 'end':
653655
case 'pause':
654656
case 'read':
655657
case 'resume':
656658
case 'write':
659+
case 'setEncoding':
660+
case 'setKeepAlive':
661+
case 'setNoDelay':
657662
throw new ERR_HTTP2_NO_SOCKET_MANIPULATION();
658663
default:
659664
const socket = session[kSocket];
@@ -672,7 +677,9 @@ const proxySocketHandler = {
672677
set(session, prop, value) {
673678
switch (prop) {
674679
case 'setTimeout':
675-
session.setTimeout = value;
680+
case 'ref':
681+
case 'unref':
682+
session[prop] = value;
676683
return true;
677684
case 'destroy':
678685
case 'emit':
@@ -681,6 +688,9 @@ const proxySocketHandler = {
681688
case 'read':
682689
case 'resume':
683690
case 'write':
691+
case 'setEncoding':
692+
case 'setKeepAlive':
693+
case 'setNoDelay':
684694
throw new ERR_HTTP2_NO_SOCKET_MANIPULATION();
685695
default:
686696
const socket = session[kSocket];

test/parallel/test-http2-socket-proxy.js

+11
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ server.on('stream', common.mustCall(function(stream, headers) {
4242
common.expectsError(() => socket.read, errMsg);
4343
common.expectsError(() => socket.resume, errMsg);
4444
common.expectsError(() => socket.write, errMsg);
45+
common.expectsError(() => socket.setEncoding, errMsg);
46+
common.expectsError(() => socket.setKeepAlive, errMsg);
47+
common.expectsError(() => socket.setNoDelay, errMsg);
4548

4649
common.expectsError(() => (socket.destroy = undefined), errMsg);
4750
common.expectsError(() => (socket.emit = undefined), errMsg);
@@ -50,11 +53,19 @@ server.on('stream', common.mustCall(function(stream, headers) {
5053
common.expectsError(() => (socket.read = undefined), errMsg);
5154
common.expectsError(() => (socket.resume = undefined), errMsg);
5255
common.expectsError(() => (socket.write = undefined), errMsg);
56+
common.expectsError(() => (socket.setEncoding = undefined), errMsg);
57+
common.expectsError(() => (socket.setKeepAlive = undefined), errMsg);
58+
common.expectsError(() => (socket.setNoDelay = undefined), errMsg);
5359

5460
// Resetting the socket listeners to their own value should not throw.
5561
socket.on = socket.on; // eslint-disable-line no-self-assign
5662
socket.once = socket.once; // eslint-disable-line no-self-assign
5763

64+
socket.unref();
65+
assert.strictEqual(socket._handle.hasRef(), false);
66+
socket.ref();
67+
assert.strictEqual(socket._handle.hasRef(), true);
68+
5869
stream.respond();
5970

6071
socket.writable = 0;

test/parallel/test-http2-unbound-socket-proxy.js

-25
Original file line numberDiff line numberDiff line change
@@ -39,31 +39,6 @@ server.listen(0, common.mustCall(() => {
3939
}, {
4040
code: 'ERR_HTTP2_SOCKET_UNBOUND'
4141
});
42-
common.expectsError(() => {
43-
socket.ref();
44-
}, {
45-
code: 'ERR_HTTP2_SOCKET_UNBOUND'
46-
});
47-
common.expectsError(() => {
48-
socket.unref();
49-
}, {
50-
code: 'ERR_HTTP2_SOCKET_UNBOUND'
51-
});
52-
common.expectsError(() => {
53-
socket.setEncoding();
54-
}, {
55-
code: 'ERR_HTTP2_SOCKET_UNBOUND'
56-
});
57-
common.expectsError(() => {
58-
socket.setKeepAlive();
59-
}, {
60-
code: 'ERR_HTTP2_SOCKET_UNBOUND'
61-
});
62-
common.expectsError(() => {
63-
socket.setNoDelay();
64-
}, {
65-
code: 'ERR_HTTP2_SOCKET_UNBOUND'
66-
});
6742
}));
6843
}));
6944
}));

0 commit comments

Comments
 (0)