Skip to content

Commit b5a71a4

Browse files
ZYSzystargos
authored andcommitted
http2: set default enableConnectProtocol to 0
PR-URL: #31174 Refs: https://tools.ietf.org/html/rfc8441#section-9.1 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent 20ecb5d commit b5a71a4

File tree

7 files changed

+68
-21
lines changed

7 files changed

+68
-21
lines changed

doc/api/http2.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -2413,7 +2413,7 @@ properties.
24132413
header compression. The minimum allowed value is 0. The maximum allowed value
24142414
is 2<sup>32</sup>-1. **Default:** `4,096 octets`.
24152415
* `enablePush` {boolean} Specifies `true` if HTTP/2 Push Streams are to be
2416-
permitted on the `Http2Session` instances.
2416+
permitted on the `Http2Session` instances. **Default:** `true`.
24172417
* `initialWindowSize` {number} Specifies the *senders* initial window size
24182418
for stream-level flow control. The minimum allowed value is 0. The maximum
24192419
allowed value is 2<sup>32</sup>-1. **Default:** `65,535 bytes`.
@@ -2433,6 +2433,7 @@ properties.
24332433
Protocol" defined by [RFC 8441][] is to be enabled. This setting is only
24342434
meaningful if sent by the server. Once the `enableConnectProtocol` setting
24352435
has been enabled for a given `Http2Session`, it cannot be disabled.
2436+
**Default:** `false`.
24362437

24372438
All additional properties on the settings object are ignored.
24382439

lib/internal/http2/core.js

+9
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ const {
253253
NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE,
254254
NGHTTP2_SETTINGS_MAX_FRAME_SIZE,
255255
NGHTTP2_SETTINGS_MAX_HEADER_LIST_SIZE,
256+
NGHTTP2_SETTINGS_ENABLE_CONNECT_PROTOCOL,
256257

257258
HTTP2_METHOD_GET,
258259
HTTP2_METHOD_HEAD,
@@ -886,6 +887,7 @@ function pingCallback(cb) {
886887
// 4. maxConcurrentStreams must be a number in the range 0 <= n <= kMaxStreams
887888
// 5. maxHeaderListSize must be a number in the range 0 <= n <= kMaxInt
888889
// 6. enablePush must be a boolean
890+
// 7. enableConnectProtocol must be a boolean
889891
// All settings are optional and may be left undefined
890892
const validateSettings = hideStackFrames((settings) => {
891893
if (settings === undefined) return;
@@ -909,6 +911,11 @@ const validateSettings = hideStackFrames((settings) => {
909911
throw new ERR_HTTP2_INVALID_SETTING_VALUE('enablePush',
910912
settings.enablePush);
911913
}
914+
if (settings.enableConnectProtocol !== undefined &&
915+
typeof settings.enableConnectProtocol !== 'boolean') {
916+
throw new ERR_HTTP2_INVALID_SETTING_VALUE('enableConnectProtocol',
917+
settings.enableConnectProtocol);
918+
}
912919
});
913920

914921
// Creates the internal binding.Http2Session handle for an Http2Session
@@ -3105,6 +3112,8 @@ function getUnpackedSettings(buf, options = {}) {
31053112
case NGHTTP2_SETTINGS_MAX_HEADER_LIST_SIZE:
31063113
settings.maxHeaderListSize = value;
31073114
break;
3115+
case NGHTTP2_SETTINGS_ENABLE_CONNECT_PROTOCOL:
3116+
settings.enableConnectProtocol = value !== 0;
31083117
}
31093118
offset += 4;
31103119
}

lib/internal/http2/util.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ function getDefaultSettings() {
301301
if ((flags & (1 << IDX_SETTINGS_ENABLE_CONNECT_PROTOCOL)) ===
302302
(1 << IDX_SETTINGS_ENABLE_CONNECT_PROTOCOL)) {
303303
holder.enableConnectProtocol =
304-
settingsBuffer[IDX_SETTINGS_ENABLE_CONNECT_PROTOCOL];
304+
settingsBuffer[IDX_SETTINGS_ENABLE_CONNECT_PROTOCOL] === 1;
305305
}
306306

307307
return holder;
@@ -322,7 +322,8 @@ function getSettings(session, remote) {
322322
maxFrameSize: settingsBuffer[IDX_SETTINGS_MAX_FRAME_SIZE],
323323
maxConcurrentStreams: settingsBuffer[IDX_SETTINGS_MAX_CONCURRENT_STREAMS],
324324
maxHeaderListSize: settingsBuffer[IDX_SETTINGS_MAX_HEADER_LIST_SIZE],
325-
enableConnectProtocol: settingsBuffer[IDX_SETTINGS_ENABLE_CONNECT_PROTOCOL]
325+
enableConnectProtocol:
326+
!!settingsBuffer[IDX_SETTINGS_ENABLE_CONNECT_PROTOCOL]
326327
};
327328
}
328329

src/node_http2.cc

+6-1
Original file line numberDiff line numberDiff line change
@@ -297,13 +297,16 @@ void Http2Session::Http2Settings::RefreshDefaults(Environment* env) {
297297
DEFAULT_SETTINGS_MAX_FRAME_SIZE;
298298
buffer[IDX_SETTINGS_MAX_HEADER_LIST_SIZE] =
299299
DEFAULT_SETTINGS_MAX_HEADER_LIST_SIZE;
300+
buffer[IDX_SETTINGS_ENABLE_CONNECT_PROTOCOL] =
301+
DEFAULT_SETTINGS_ENABLE_CONNECT_PROTOCOL;
300302
buffer[IDX_SETTINGS_COUNT] =
301303
(1 << IDX_SETTINGS_HEADER_TABLE_SIZE) |
302304
(1 << IDX_SETTINGS_ENABLE_PUSH) |
303305
(1 << IDX_SETTINGS_MAX_CONCURRENT_STREAMS) |
304306
(1 << IDX_SETTINGS_INITIAL_WINDOW_SIZE) |
305307
(1 << IDX_SETTINGS_MAX_FRAME_SIZE) |
306-
(1 << IDX_SETTINGS_MAX_HEADER_LIST_SIZE);
308+
(1 << IDX_SETTINGS_MAX_HEADER_LIST_SIZE) |
309+
(1 << IDX_SETTINGS_ENABLE_CONNECT_PROTOCOL);
307310
}
308311

309312

@@ -3137,6 +3140,8 @@ void Initialize(Local<Object> target,
31373140
NODE_DEFINE_CONSTANT(constants, DEFAULT_SETTINGS_MAX_CONCURRENT_STREAMS);
31383141
NODE_DEFINE_CONSTANT(constants, DEFAULT_SETTINGS_INITIAL_WINDOW_SIZE);
31393142
NODE_DEFINE_CONSTANT(constants, DEFAULT_SETTINGS_MAX_FRAME_SIZE);
3143+
NODE_DEFINE_CONSTANT(constants, DEFAULT_SETTINGS_MAX_HEADER_LIST_SIZE);
3144+
NODE_DEFINE_CONSTANT(constants, DEFAULT_SETTINGS_ENABLE_CONNECT_PROTOCOL);
31403145
NODE_DEFINE_CONSTANT(constants, MAX_MAX_FRAME_SIZE);
31413146
NODE_DEFINE_CONSTANT(constants, MIN_MAX_FRAME_SIZE);
31423147
NODE_DEFINE_CONSTANT(constants, MAX_INITIAL_WINDOW_SIZE);

src/node_http2.h

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ using performance::PerformanceEntry;
4545
#define DEFAULT_SETTINGS_INITIAL_WINDOW_SIZE 65535
4646
#define DEFAULT_SETTINGS_MAX_FRAME_SIZE 16384
4747
#define DEFAULT_SETTINGS_MAX_HEADER_LIST_SIZE 65535
48+
#define DEFAULT_SETTINGS_ENABLE_CONNECT_PROTOCOL 0
4849
#define MAX_MAX_FRAME_SIZE 16777215
4950
#define MIN_MAX_FRAME_SIZE DEFAULT_SETTINGS_MAX_FRAME_SIZE
5051
#define MAX_INITIAL_WINDOW_SIZE 2147483647

test/parallel/test-http2-binding.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,9 @@ const defaultSettings = {
230230
DEFAULT_SETTINGS_ENABLE_PUSH: 1,
231231
DEFAULT_SETTINGS_MAX_CONCURRENT_STREAMS: 4294967295,
232232
DEFAULT_SETTINGS_INITIAL_WINDOW_SIZE: 65535,
233-
DEFAULT_SETTINGS_MAX_FRAME_SIZE: 16384
233+
DEFAULT_SETTINGS_MAX_FRAME_SIZE: 16384,
234+
DEFAULT_SETTINGS_MAX_HEADER_LIST_SIZE: 65535,
235+
DEFAULT_SETTINGS_ENABLE_CONNECT_PROTOCOL: 0
234236
};
235237

236238
for (const name of Object.keys(constants)) {

test/parallel/test-http2-getpackedsettings.js

+44-16
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ const check = Buffer.from([0x00, 0x01, 0x00, 0x00, 0x10, 0x00,
1111
0x00, 0x05, 0x00, 0x00, 0x40, 0x00,
1212
0x00, 0x04, 0x00, 0x00, 0xff, 0xff,
1313
0x00, 0x06, 0x00, 0x00, 0xff, 0xff,
14-
0x00, 0x02, 0x00, 0x00, 0x00, 0x01]);
14+
0x00, 0x02, 0x00, 0x00, 0x00, 0x01,
15+
0x00, 0x08, 0x00, 0x00, 0x00, 0x00]);
1516
const val = http2.getPackedSettings(http2.getDefaultSettings());
1617
assert.deepStrictEqual(val, check);
1718

@@ -67,12 +68,27 @@ http2.getPackedSettings({ enablePush: false });
6768
});
6869
});
6970

71+
[
72+
1, null, '', Infinity, new Date(), {}, NaN, [false]
73+
].forEach((i) => {
74+
assert.throws(() => {
75+
http2.getPackedSettings({ enableConnectProtocol: i });
76+
}, {
77+
code: 'ERR_HTTP2_INVALID_SETTING_VALUE',
78+
name: 'TypeError',
79+
message: `Invalid value for setting "enableConnectProtocol": ${i}`
80+
});
81+
});
82+
7083
{
7184
const check = Buffer.from([
72-
0x00, 0x01, 0x00, 0x00, 0x00, 0x64, 0x00, 0x03, 0x00, 0x00,
73-
0x00, 0xc8, 0x00, 0x05, 0x00, 0x00, 0x4e, 0x20, 0x00, 0x04,
74-
0x00, 0x00, 0x00, 0x64, 0x00, 0x06, 0x00, 0x00, 0x00, 0x64,
75-
0x00, 0x02, 0x00, 0x00, 0x00, 0x01]);
85+
0x00, 0x01, 0x00, 0x00, 0x00, 0x64,
86+
0x00, 0x03, 0x00, 0x00, 0x00, 0xc8,
87+
0x00, 0x05, 0x00, 0x00, 0x4e, 0x20,
88+
0x00, 0x04, 0x00, 0x00, 0x00, 0x64,
89+
0x00, 0x06, 0x00, 0x00, 0x00, 0x64,
90+
0x00, 0x02, 0x00, 0x00, 0x00, 0x01,
91+
0x00, 0x08, 0x00, 0x00, 0x00, 0x00]);
7692

7793
const packed = http2.getPackedSettings({
7894
headerTableSize: 100,
@@ -81,9 +97,10 @@ http2.getPackedSettings({ enablePush: false });
8197
maxConcurrentStreams: 200,
8298
maxHeaderListSize: 100,
8399
enablePush: true,
100+
enableConnectProtocol: false,
84101
foo: 'ignored'
85102
});
86-
assert.strictEqual(packed.length, 36);
103+
assert.strictEqual(packed.length, 42);
87104
assert.deepStrictEqual(packed, check);
88105
}
89106

@@ -95,10 +112,13 @@ http2.getPackedSettings({ enablePush: false });
95112

96113
{
97114
const packed = Buffer.from([
98-
0x00, 0x01, 0x00, 0x00, 0x00, 0x64, 0x00, 0x03, 0x00, 0x00,
99-
0x00, 0xc8, 0x00, 0x05, 0x00, 0x00, 0x4e, 0x20, 0x00, 0x04,
100-
0x00, 0x00, 0x00, 0x64, 0x00, 0x06, 0x00, 0x00, 0x00, 0x64,
101-
0x00, 0x02, 0x00, 0x00, 0x00, 0x01]);
115+
0x00, 0x01, 0x00, 0x00, 0x00, 0x64,
116+
0x00, 0x03, 0x00, 0x00, 0x00, 0xc8,
117+
0x00, 0x05, 0x00, 0x00, 0x4e, 0x20,
118+
0x00, 0x04, 0x00, 0x00, 0x00, 0x64,
119+
0x00, 0x06, 0x00, 0x00, 0x00, 0x64,
120+
0x00, 0x02, 0x00, 0x00, 0x00, 0x01,
121+
0x00, 0x08, 0x00, 0x00, 0x00, 0x00]);
102122

103123
[1, true, '', [], {}, NaN].forEach((input) => {
104124
assert.throws(() => {
@@ -129,30 +149,38 @@ http2.getPackedSettings({ enablePush: false });
129149
assert.strictEqual(settings.maxConcurrentStreams, 200);
130150
assert.strictEqual(settings.maxHeaderListSize, 100);
131151
assert.strictEqual(settings.enablePush, true);
152+
assert.strictEqual(settings.enableConnectProtocol, false);
132153
}
133154

134155
{
135156
const packed = Buffer.from([
136-
0x00, 0x02, 0x00, 0x00, 0x00, 0x00]);
157+
0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
158+
0x00, 0x08, 0x00, 0x00, 0x00, 0x00]);
137159

138160
const settings = http2.getUnpackedSettings(packed, { validate: true });
139161
assert.strictEqual(settings.enablePush, false);
162+
assert.strictEqual(settings.enableConnectProtocol, false);
140163
}
141164
{
142165
const packed = Buffer.from([
143-
0x00, 0x02, 0x00, 0x00, 0x00, 0x64]);
166+
0x00, 0x02, 0x00, 0x00, 0x00, 0x64,
167+
0x00, 0x08, 0x00, 0x00, 0x00, 0x64]);
144168

145169
const settings = http2.getUnpackedSettings(packed, { validate: true });
146170
assert.strictEqual(settings.enablePush, true);
171+
assert.strictEqual(settings.enableConnectProtocol, true);
147172
}
148173

149174
// Verify that passing {validate: true} does not throw.
150175
{
151176
const packed = Buffer.from([
152-
0x00, 0x01, 0x00, 0x00, 0x00, 0x64, 0x00, 0x03, 0x00, 0x00,
153-
0x00, 0xc8, 0x00, 0x05, 0x00, 0x00, 0x4e, 0x20, 0x00, 0x04,
154-
0x00, 0x00, 0x00, 0x64, 0x00, 0x06, 0x00, 0x00, 0x00, 0x64,
155-
0x00, 0x02, 0x00, 0x00, 0x00, 0x01]);
177+
0x00, 0x01, 0x00, 0x00, 0x00, 0x64,
178+
0x00, 0x03, 0x00, 0x00, 0x00, 0xc8,
179+
0x00, 0x05, 0x00, 0x00, 0x4e, 0x20,
180+
0x00, 0x04, 0x00, 0x00, 0x00, 0x64,
181+
0x00, 0x06, 0x00, 0x00, 0x00, 0x64,
182+
0x00, 0x02, 0x00, 0x00, 0x00, 0x01,
183+
0x00, 0x08, 0x00, 0x00, 0x00, 0x00]);
156184

157185
http2.getUnpackedSettings(packed, { validate: true });
158186
}

0 commit comments

Comments
 (0)