Skip to content

Commit 20a8175

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 59e2975 commit 20a8175

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
@@ -2420,7 +2420,7 @@ properties.
24202420
header compression. The minimum allowed value is 0. The maximum allowed value
24212421
is 2<sup>32</sup>-1. **Default:** `4,096 octets`.
24222422
* `enablePush` {boolean} Specifies `true` if HTTP/2 Push Streams are to be
2423-
permitted on the `Http2Session` instances.
2423+
permitted on the `Http2Session` instances. **Default:** `true`.
24242424
* `initialWindowSize` {number} Specifies the *senders* initial window size
24252425
for stream-level flow control. The minimum allowed value is 0. The maximum
24262426
allowed value is 2<sup>32</sup>-1. **Default:** `65,535 bytes`.
@@ -2440,6 +2440,7 @@ properties.
24402440
Protocol" defined by [RFC 8441][] is to be enabled. This setting is only
24412441
meaningful if sent by the server. Once the `enableConnectProtocol` setting
24422442
has been enabled for a given `Http2Session`, it cannot be disabled.
2443+
**Default:** `false`.
24432444

24442445
All additional properties on the settings object are ignored.
24452446

lib/internal/http2/core.js

+9
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ const {
261261
NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE,
262262
NGHTTP2_SETTINGS_MAX_FRAME_SIZE,
263263
NGHTTP2_SETTINGS_MAX_HEADER_LIST_SIZE,
264+
NGHTTP2_SETTINGS_ENABLE_CONNECT_PROTOCOL,
264265

265266
HTTP2_METHOD_GET,
266267
HTTP2_METHOD_HEAD,
@@ -905,6 +906,7 @@ function pingCallback(cb) {
905906
// 4. maxConcurrentStreams must be a number in the range 0 <= n <= kMaxStreams
906907
// 5. maxHeaderListSize must be a number in the range 0 <= n <= kMaxInt
907908
// 6. enablePush must be a boolean
909+
// 7. enableConnectProtocol must be a boolean
908910
// All settings are optional and may be left undefined
909911
const validateSettings = hideStackFrames((settings) => {
910912
if (settings === undefined) return;
@@ -928,6 +930,11 @@ const validateSettings = hideStackFrames((settings) => {
928930
throw new ERR_HTTP2_INVALID_SETTING_VALUE('enablePush',
929931
settings.enablePush);
930932
}
933+
if (settings.enableConnectProtocol !== undefined &&
934+
typeof settings.enableConnectProtocol !== 'boolean') {
935+
throw new ERR_HTTP2_INVALID_SETTING_VALUE('enableConnectProtocol',
936+
settings.enableConnectProtocol);
937+
}
931938
});
932939

933940
// Creates the internal binding.Http2Session handle for an Http2Session
@@ -3094,6 +3101,8 @@ function getUnpackedSettings(buf, options = {}) {
30943101
case NGHTTP2_SETTINGS_MAX_HEADER_LIST_SIZE:
30953102
settings.maxHeaderListSize = value;
30963103
break;
3104+
case NGHTTP2_SETTINGS_ENABLE_CONNECT_PROTOCOL:
3105+
settings.enableConnectProtocol = value !== 0;
30973106
}
30983107
offset += 4;
30993108
}

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
@@ -301,13 +301,16 @@ void Http2Session::Http2Settings::RefreshDefaults(Environment* env) {
301301
DEFAULT_SETTINGS_MAX_FRAME_SIZE;
302302
buffer[IDX_SETTINGS_MAX_HEADER_LIST_SIZE] =
303303
DEFAULT_SETTINGS_MAX_HEADER_LIST_SIZE;
304+
buffer[IDX_SETTINGS_ENABLE_CONNECT_PROTOCOL] =
305+
DEFAULT_SETTINGS_ENABLE_CONNECT_PROTOCOL;
304306
buffer[IDX_SETTINGS_COUNT] =
305307
(1 << IDX_SETTINGS_HEADER_TABLE_SIZE) |
306308
(1 << IDX_SETTINGS_ENABLE_PUSH) |
307309
(1 << IDX_SETTINGS_MAX_CONCURRENT_STREAMS) |
308310
(1 << IDX_SETTINGS_INITIAL_WINDOW_SIZE) |
309311
(1 << IDX_SETTINGS_MAX_FRAME_SIZE) |
310-
(1 << IDX_SETTINGS_MAX_HEADER_LIST_SIZE);
312+
(1 << IDX_SETTINGS_MAX_HEADER_LIST_SIZE) |
313+
(1 << IDX_SETTINGS_ENABLE_CONNECT_PROTOCOL);
311314
}
312315

313316

@@ -3170,6 +3173,8 @@ void Initialize(Local<Object> target,
31703173
NODE_DEFINE_CONSTANT(constants, DEFAULT_SETTINGS_MAX_CONCURRENT_STREAMS);
31713174
NODE_DEFINE_CONSTANT(constants, DEFAULT_SETTINGS_INITIAL_WINDOW_SIZE);
31723175
NODE_DEFINE_CONSTANT(constants, DEFAULT_SETTINGS_MAX_FRAME_SIZE);
3176+
NODE_DEFINE_CONSTANT(constants, DEFAULT_SETTINGS_MAX_HEADER_LIST_SIZE);
3177+
NODE_DEFINE_CONSTANT(constants, DEFAULT_SETTINGS_ENABLE_CONNECT_PROTOCOL);
31733178
NODE_DEFINE_CONSTANT(constants, MAX_MAX_FRAME_SIZE);
31743179
NODE_DEFINE_CONSTANT(constants, MIN_MAX_FRAME_SIZE);
31753180
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
common.expectsError(() => {
@@ -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)