Skip to content

Commit

Permalink
lib: http2 compatibility error with connection header
Browse files Browse the repository at this point in the history
Ignoring the connection header and disable the
`ERR_HTTP2_INVALID_CONNECTION_HEADERS` error.

Added a warning log on the compatibility.

Fixes: nodejs#23748
  • Loading branch information
sagitsofan committed Dec 14, 2018
1 parent 8ac6c05 commit 685d968
Showing 1 changed file with 36 additions and 22 deletions.
58 changes: 36 additions & 22 deletions lib/internal/http2/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,43 +246,43 @@ function getDefaultSettings() {
const flags = settingsBuffer[IDX_SETTINGS_FLAGS];

if ((flags & (1 << IDX_SETTINGS_HEADER_TABLE_SIZE)) ===
(1 << IDX_SETTINGS_HEADER_TABLE_SIZE)) {
(1 << IDX_SETTINGS_HEADER_TABLE_SIZE)) {
holder.headerTableSize =
settingsBuffer[IDX_SETTINGS_HEADER_TABLE_SIZE];
}

if ((flags & (1 << IDX_SETTINGS_ENABLE_PUSH)) ===
(1 << IDX_SETTINGS_ENABLE_PUSH)) {
(1 << IDX_SETTINGS_ENABLE_PUSH)) {
holder.enablePush =
settingsBuffer[IDX_SETTINGS_ENABLE_PUSH] === 1;
}

if ((flags & (1 << IDX_SETTINGS_INITIAL_WINDOW_SIZE)) ===
(1 << IDX_SETTINGS_INITIAL_WINDOW_SIZE)) {
(1 << IDX_SETTINGS_INITIAL_WINDOW_SIZE)) {
holder.initialWindowSize =
settingsBuffer[IDX_SETTINGS_INITIAL_WINDOW_SIZE];
}

if ((flags & (1 << IDX_SETTINGS_MAX_FRAME_SIZE)) ===
(1 << IDX_SETTINGS_MAX_FRAME_SIZE)) {
(1 << IDX_SETTINGS_MAX_FRAME_SIZE)) {
holder.maxFrameSize =
settingsBuffer[IDX_SETTINGS_MAX_FRAME_SIZE];
}

if ((flags & (1 << IDX_SETTINGS_MAX_CONCURRENT_STREAMS)) ===
(1 << IDX_SETTINGS_MAX_CONCURRENT_STREAMS)) {
(1 << IDX_SETTINGS_MAX_CONCURRENT_STREAMS)) {
holder.maxConcurrentStreams =
settingsBuffer[IDX_SETTINGS_MAX_CONCURRENT_STREAMS];
}

if ((flags & (1 << IDX_SETTINGS_MAX_HEADER_LIST_SIZE)) ===
(1 << IDX_SETTINGS_MAX_HEADER_LIST_SIZE)) {
(1 << IDX_SETTINGS_MAX_HEADER_LIST_SIZE)) {
holder.maxHeaderListSize =
settingsBuffer[IDX_SETTINGS_MAX_HEADER_LIST_SIZE];
}

if ((flags & (1 << IDX_SETTINGS_ENABLE_CONNECT_PROTOCOL)) ===
(1 << IDX_SETTINGS_ENABLE_CONNECT_PROTOCOL)) {
(1 << IDX_SETTINGS_ENABLE_CONNECT_PROTOCOL)) {
holder.enableConnectProtocol =
settingsBuffer[IDX_SETTINGS_ENABLE_CONNECT_PROTOCOL];
}
Expand Down Expand Up @@ -387,7 +387,6 @@ function getStreamState(stream) {

function isIllegalConnectionSpecificHeader(name, value) {
switch (name) {
case HTTP2_HEADER_CONNECTION:
case HTTP2_HEADER_UPGRADE:
case HTTP2_HEADER_HOST:
case HTTP2_HEADER_HTTP2_SETTINGS:
Expand Down Expand Up @@ -425,7 +424,7 @@ function assertValidPseudoHeaderTrailer(key) {
}

function mapToHeaders(map,
assertValuePseudoHeader = assertValidPseudoHeader) {
assertValuePseudoHeader = assertValidPseudoHeader) {
let ret = '';
let count = 0;
const keys = Object.keys(map);
Expand Down Expand Up @@ -470,15 +469,22 @@ function mapToHeaders(map,
throw err;
ret = `${key}\0${value}\0${ret}`;
count++;
continue;
}
if (isIllegalConnectionSpecificHeader(key, value)) {
throw new ERR_HTTP2_INVALID_CONNECTION_HEADERS(key);
}
if (isArray) {
for (var k = 0; k < value.length; k++) {
const val = String(value[k]);
ret += `${key}\0${val}\0`;
} else {
if (isIllegalConnectionSpecificHeader(key, value)) {
return new ERR_HTTP2_INVALID_CONNECTION_HEADERS(key);
}
if (isArray) {
for (var k = 0; k < value.length; k++) {
const val = String(value[k]);
ret += `${key}\0${val}\0`;
}
count += value.length;
}
else if (key === HTTP2_HEADER_CONNECTION) {
headerMessageWarn(key);
} else {
ret += `${key}\0${value}\0`;
count++;
}
count += value.length;
continue;
Expand All @@ -501,9 +507,9 @@ class NghttpError extends Error {

function assertIsObject(value, name, types = 'Object') {
if (value !== undefined &&
(value === null ||
typeof value !== 'object' ||
Array.isArray(value))) {
(value === null ||
typeof value !== 'object' ||
Array.isArray(value))) {
const err = new ERR_INVALID_ARG_TYPE(name, types, value);
Error.captureStackTrace(err, assertIsObject);
throw err;
Expand All @@ -512,7 +518,7 @@ function assertIsObject(value, name, types = 'Object') {

function assertWithinRange(name, value, min = 0, max = Infinity) {
if (value !== undefined &&
(typeof value !== 'number' || value < min || value > max)) {
(typeof value !== 'number' || value < min || value > max)) {
const err = new ERR_HTTP2_INVALID_SETTING_VALUE.RangeError(name, value);
err.min = min;
err.max = max;
Expand Down Expand Up @@ -581,6 +587,14 @@ function sessionName(type) {
}
}

function headerMessageWarn(key) {
process.emitWarning(
`The provided header "${key}" is not valid, ` +
'and is supported only for compatibility.',
'UnsupportedWarning'
);
}

module.exports = {
assertIsObject,
assertValidPseudoHeaderResponse,
Expand Down

0 comments on commit 685d968

Please sign in to comment.