Skip to content

Commit 2e421ff

Browse files
apapirovskijasnell
authored andcommitted
http2: correct behaviour for enablePush unpack
The only valid values for enablePush are 0 and 1. If validation is requested, we should verify that it wasn't set to another value rather than casting to Boolean regardless of value. PR-URL: #15167 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent 4d68064 commit 2e421ff

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

lib/internal/http2/core.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2535,7 +2535,7 @@ function getUnpackedSettings(buf, options = {}) {
25352535
settings.headerTableSize = value;
25362536
break;
25372537
case NGHTTP2_SETTINGS_ENABLE_PUSH:
2538-
settings.enablePush = Boolean(value);
2538+
settings.enablePush = value;
25392539
break;
25402540
case NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS:
25412541
settings.maxConcurrentStreams = value;
@@ -2557,6 +2557,9 @@ function getUnpackedSettings(buf, options = {}) {
25572557
assertWithinRange('headerTableSize',
25582558
settings.headerTableSize,
25592559
0, 2 ** 32 - 1);
2560+
assertWithinRange('enablePush',
2561+
settings.enablePush,
2562+
0, 1);
25602563
assertWithinRange('initialWindowSize',
25612564
settings.initialWindowSize,
25622565
0, 2 ** 32 - 1);
@@ -2569,13 +2572,10 @@ function getUnpackedSettings(buf, options = {}) {
25692572
assertWithinRange('maxHeaderListSize',
25702573
settings.maxHeaderListSize,
25712574
0, 2 ** 32 - 1);
2572-
if (settings.enablePush !== undefined &&
2573-
typeof settings.enablePush !== 'boolean') {
2574-
const err = new errors.TypeError('ERR_HTTP2_INVALID_SETTING_VALUE',
2575-
'enablePush', settings.enablePush);
2576-
err.actual = settings.enablePush;
2577-
throw err;
2578-
}
2575+
}
2576+
2577+
if (settings.enablePush !== undefined) {
2578+
settings.enablePush = !!settings.enablePush;
25792579
}
25802580

25812581
return settings;

test/parallel/test-http2-getpackedsettings.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,27 @@ assert.doesNotThrow(() => http2.getPackedSettings({ enablePush: false }));
126126
assert.strictEqual(settings.enablePush, true);
127127
}
128128

129+
//should throw if enablePush is not 0 or 1
130+
{
131+
const packed = Buffer.from([
132+
0x00, 0x02, 0x00, 0x00, 0x00, 0x00]);
133+
134+
const settings = http2.getUnpackedSettings(packed, { validate: true });
135+
assert.strictEqual(settings.enablePush, false);
136+
}
137+
{
138+
const packed = Buffer.from([
139+
0x00, 0x02, 0x00, 0x00, 0x00, 0x64]);
140+
141+
assert.throws(() => {
142+
http2.getUnpackedSettings(packed, { validate: true });
143+
}, common.expectsError({
144+
code: 'ERR_HTTP2_INVALID_SETTING_VALUE',
145+
type: RangeError,
146+
message: 'Invalid value for setting "enablePush": 100'
147+
}));
148+
}
149+
129150
//check for what happens if passing {validate: true} and no errors happen
130151
{
131152
const packed = Buffer.from([

0 commit comments

Comments
 (0)