Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http2: stricter settings validation #26811

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions lib/internal/http2/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,11 @@ function pingCallback(cb) {
// 6. enablePush must be a boolean
// All settings are optional and may be left undefined
function validateSettings(settings) {
settings = { ...settings };
if (settings === undefined) {
const err = new ERR_INVALID_ARG_TYPE('settings', 'object', settings);
Error.captureStackTrace(err, 'validateSettings');
throw err;
}
assertWithinRange('headerTableSize',
settings.headerTableSize,
0, kMaxInt);
Expand All @@ -813,7 +817,6 @@ function validateSettings(settings) {
Error.captureStackTrace(err, 'validateSettings');
throw err;
}
return settings;
}

// Creates the internal binding.Http2Session handle for an Http2Session
Expand Down Expand Up @@ -1152,15 +1155,15 @@ class Http2Session extends EventEmitter {
if (this.destroyed)
throw new ERR_HTTP2_INVALID_SESSION();
assertIsObject(settings, 'settings');
settings = validateSettings(settings);
validateSettings(settings);

if (callback && typeof callback !== 'function')
throw new ERR_INVALID_CALLBACK();
debug(`Http2Session ${sessionName(this[kType])}: sending settings`);

this[kState].pendingAck++;

const settingsFn = submitSettings.bind(this, settings, callback);
const settingsFn = submitSettings.bind(this, { ...settings }, callback);
if (this.connecting) {
this.once('connect', settingsFn);
return;
Expand Down Expand Up @@ -2830,7 +2833,8 @@ function createServer(options, handler) {
// HTTP2-Settings header frame.
function getPackedSettings(settings) {
assertIsObject(settings, 'settings');
updateSettingsBuffer(validateSettings(settings));
validateSettings(settings);
updateSettingsBuffer({ ...settings });
return binding.packSettings();
}

Expand Down
6 changes: 4 additions & 2 deletions test/parallel/test-http2-getpackedsettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@ http2.getPackedSettings({ enablePush: false });

// Check for not passing settings.
{
const packed = http2.getPackedSettings();
assert.strictEqual(packed.length, 0);
assert.throws(
() => http2.getPackedSettings(),
{ code: 'ERR_INVALID_ARG_TYPE' }
);
}

{
Expand Down