Skip to content

http2: add lenient flag for RFC-9113 #58116

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

Merged
merged 7 commits into from
Jun 5, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 9 additions & 1 deletion lib/internal/http2/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ const IDX_OPTIONS_MAX_SESSION_MEMORY = 8;
const IDX_OPTIONS_MAX_SETTINGS = 9;
const IDX_OPTIONS_STREAM_RESET_RATE = 10;
const IDX_OPTIONS_STREAM_RESET_BURST = 11;
const IDX_OPTIONS_FLAGS = 12;
const IDX_OPTIONS_STRICT_HTTP_HEADER_FIELD_VALIDATION = 12;
const IDX_OPTIONS_FLAGS = 13;

function updateOptionsBuffer(options) {
let flags = 0;
Expand Down Expand Up @@ -293,6 +294,13 @@ function updateOptionsBuffer(options) {
optionsBuffer[IDX_OPTIONS_STREAM_RESET_BURST] =
MathMax(1, options.streamResetBurst);
}

if (typeof options.strictHttpFieldValidation === 'boolean') {
flags |= (1 << IDX_OPTIONS_STRICT_HTTP_HEADER_FIELD_VALIDATION);
optionsBuffer[IDX_OPTIONS_STRICT_HTTP_HEADER_FIELD_VALIDATION] =
options.strictHttpHeaderValidation === true ? 0 : 1;
}

optionsBuffer[IDX_OPTIONS_FLAGS] = flags;
}

Expand Down
7 changes: 7 additions & 0 deletions src/node_http2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,13 @@ Http2Options::Http2Options(Http2State* http2_state, SessionType type) {
buffer[IDX_OPTIONS_PEER_MAX_CONCURRENT_STREAMS]);
}

// Validate headers in accordinace to RFC-9113
if (flags & (1 << IDX_OPTIONS_STRICT_HTTP_HEADER_FIELD_VALIDATION)) {
nghttp2_option_set_no_rfc9113_leading_and_trailing_ws_validation(
option,
buffer[IDX_OPTIONS_STRICT_HTTP_HEADER_FIELD_VALIDATION]);
}

// The padding strategy sets the mechanism by which we determine how much
// additional frame padding to apply to DATA and HEADERS frames. Currently
// this is set on a per-session basis, but eventually we may switch to
Expand Down
1 change: 1 addition & 0 deletions src/node_http2_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ namespace http2 {
IDX_OPTIONS_MAX_SETTINGS,
IDX_OPTIONS_STREAM_RESET_RATE,
IDX_OPTIONS_STREAM_RESET_BURST,
IDX_OPTIONS_STRICT_HTTP_HEADER_FIELD_VALIDATION,
IDX_OPTIONS_FLAGS
};

Expand Down
77 changes: 77 additions & 0 deletions test/parallel/test-http2-server-rfc-9113-client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
'use strict';

Check failure on line 1 in test/parallel/test-http2-server-rfc-9113-client.js

View workflow job for this annotation

GitHub Actions / test-linux (ubuntu-24.04)

Command: out/Release/node --test-reporter=./test/common/test-error-reporter.js --test-reporter-destination=stdout /home/runner/work/node/node/node/test/parallel/test-http2-server-rfc-9113-client.js --- TIMEOUT ---

Check failure on line 1 in test/parallel/test-http2-server-rfc-9113-client.js

View workflow job for this annotation

GitHub Actions / test-macOS

Command: out/Release/node --test-reporter=./test/common/test-error-reporter.js --test-reporter-destination=stdout /Users/runner/work/node/node/node/test/parallel/test-http2-server-rfc-9113-client.js --- TIMEOUT ---

Check failure on line 1 in test/parallel/test-http2-server-rfc-9113-client.js

View workflow job for this annotation

GitHub Actions / test-linux (ubuntu-24.04-arm)

Command: out/Release/node --test-reporter=./test/common/test-error-reporter.js --test-reporter-destination=stdout /home/runner/work/node/node/node/test/parallel/test-http2-server-rfc-9113-client.js --- TIMEOUT ---

const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const http2 = require('http2');
const body =
'<html><head></head><body><h1>this is some data</h2></body></html>';

const server = http2.createServer((req, res) => {
res.setHeader('foobar', 'baz ');
res.setHeader('X-POWERED-BY', 'node-test\t');
res.setHeader('x-h2-header', '\tconnection-test');
res.setHeader('x-h2-header-2', ' connection-test');
res.setHeader('x-h2-header-3', 'connection-test ');
res.end(body);
});

const server2 = http2.createServer((req, res) => {
res.setHeader('foobar', 'baz ');
res.setHeader('X-POWERED-BY', 'node-test\t');
res.setHeader('x-h2-header', '\tconnection-test');
res.setHeader('x-h2-header-2', ' connection-test');
res.setHeader('x-h2-header-3', 'connection-test ');
res.end(body);
});

server.listen(0, common.mustCall(() => {
server2.listen(0, common.mustCall(() => {
const client = http2.connect(`http://localhost:${server.address().port}`);
const client2 = http2.connect(`http://localhost:${server2.address().port}`, { strictHttpFieldValidation: false });
const headers = { ':path': '/' };
const req = client.request(headers);

Check failure on line 35 in test/parallel/test-http2-server-rfc-9113-client.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Trailing spaces not allowed
req.setEncoding('utf8');

Check failure on line 37 in test/parallel/test-http2-server-rfc-9113-client.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Trailing spaces not allowed
req.on('response', common.mustCall(function(headers) {
assert.strictEqual(headers.foobar, undefined);
assert.strictEqual(headers['x-powered-by'], undefined);
assert.strictEqual(headers['x-powered-by'], undefined);
assert.strictEqual(headers['x-h2-header'], undefined);
assert.strictEqual(headers['x-h2-header-2'], undefined);
assert.strictEqual(headers['x-h2-header-3'], undefined);
}));

Check failure on line 46 in test/parallel/test-http2-server-rfc-9113-client.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Trailing spaces not allowed
let data = '';
req.on('data', (d) => data += d);

Check failure on line 49 in test/parallel/test-http2-server-rfc-9113-client.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Trailing spaces not allowed
req.on('end', () => {
assert.strictEqual(body, data);
client.close();

Check failure on line 53 in test/parallel/test-http2-server-rfc-9113-client.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Trailing spaces not allowed
const req2 = client2.request(headers);
let data2 = '';
req2.setEncoding('utf8');
req2.on('response', common.mustCall(function(headers) {
assert.strictEqual(headers.foobar, 'baz ');
assert.strictEqual(headers['x-powered-by'], 'node-test\t');
assert.strictEqual(headers['x-h2-header'], '\tconnection-test');
assert.strictEqual(headers['x-h2-header-2'], ' connection-test');
assert.strictEqual(headers['x-h2-header-3'], 'connection-test ');
}));
req2.on('data', (d) => data2 += d);
req2.on('end', () => {
assert.strictEqual(body, data2);
client2.close();
server.close();
});
req2.end();
});

Check failure on line 72 in test/parallel/test-http2-server-rfc-9113-client.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Trailing spaces not allowed
req.end();
}));
}));

server.on('error', common.mustNotCall());
80 changes: 80 additions & 0 deletions test/parallel/test-http2-server-rfc-9113-server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
'use strict';

Check failure on line 1 in test/parallel/test-http2-server-rfc-9113-server.js

View workflow job for this annotation

GitHub Actions / test-linux (ubuntu-24.04)

Command: out/Release/node --test-reporter=./test/common/test-error-reporter.js --test-reporter-destination=stdout /home/runner/work/node/node/node/test/parallel/test-http2-server-rfc-9113-server.js --- TIMEOUT ---

Check failure on line 1 in test/parallel/test-http2-server-rfc-9113-server.js

View workflow job for this annotation

GitHub Actions / test-macOS

Command: out/Release/node --test-reporter=./test/common/test-error-reporter.js --test-reporter-destination=stdout /Users/runner/work/node/node/node/test/parallel/test-http2-server-rfc-9113-server.js --- TIMEOUT ---

Check failure on line 1 in test/parallel/test-http2-server-rfc-9113-server.js

View workflow job for this annotation

GitHub Actions / test-linux (ubuntu-24.04-arm)

Command: out/Release/node --test-reporter=./test/common/test-error-reporter.js --test-reporter-destination=stdout /home/runner/work/node/node/node/test/parallel/test-http2-server-rfc-9113-server.js --- TIMEOUT ---

const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const http2 = require('http2');
const body =
'<html><head></head><body><h1>this is some data</h2></body></html>';

const server = http2.createServer((req, res) => {
assert.strictEqual(req.headers['x-powered-by'], undefined);
assert.strictEqual(req.headers.foobar, undefined);
assert.strictEqual(req.headers['x-h2-header'], undefined);
assert.strictEqual(req.headers['x-h2-header-2'], undefined);
assert.strictEqual(req.headers['x-h2-header-3'], undefined);
assert.strictEqual(req.headers['x-h2-header-4'], undefined);
res.writeHead(200);
res.end(body);
});

const server2 = http2.createServer({ strictHttpFieldValidation: false },(req, res) => {

Check failure on line 22 in test/parallel/test-http2-server-rfc-9113-server.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

A space is required after ','
assert.strictEqual(req.headers.foobar, 'baz ');
assert.strictEqual(req.headers['x-powered-by'], 'node-test\t');
assert.strictEqual(req.headers['x-h2-header'], '\tconnection-test');
assert.strictEqual(req.headers['x-h2-header-2'], ' connection-test');
assert.strictEqual(req.headers['x-h2-header-3'], 'connection-test ');
assert.strictEqual(req.headers['x-h2-header-4'], 'connection-test\t');
res.writeHead(200);
res.end(body);
});

server.listen(0, common.mustCall(() => {
server2.listen(0, common.mustCall(() => {
const client = http2.connect(`http://localhost:${server.address().port}`);
const client2 = http2.connect(`http://localhost:${server2.address().port}`);
const headers = {
':path': '/',

Check failure on line 38 in test/parallel/test-http2-server-rfc-9113-server.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Trailing spaces not allowed
foobar: 'baz ',

Check failure on line 39 in test/parallel/test-http2-server-rfc-9113-server.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Inconsistently quoted property 'foobar' found
'x-powered-by': 'node-test\t',
'x-h2-header': '\tconnection-test',
'x-h2-header-2': ' connection-test',
'x-h2-header-3': 'connection-test ',
'x-h2-header-4': 'connection-test\t'
};

Check failure on line 45 in test/parallel/test-http2-server-rfc-9113-server.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Expected indentation of 4 spaces but found 5
const req = client.request(headers);

req.setEncoding('utf8');

req.on('response', common.mustCall(function(headers) {
assert.strictEqual(headers[':status'], 200);
}));

let data = '';
req.on('data', (d) => data += d);

req.on('end', () => {
assert.strictEqual(body, data);
client.close();

const req2 = client2.request(headers);
let data2 = '';
req2.setEncoding('utf8');
req2.on('response', common.mustCall(function(headers) {
assert.strictEqual(headers[':status'], 200);
}));
req2.on('data', (d) => data2 += d);
req2.on('end', () => {
assert.strictEqual(body, data2);
client2.close();
server.close();
});
req2.end();
});

req.end();
}));
}));

server.on('error', common.mustNotCall());
6 changes: 5 additions & 1 deletion test/parallel/test-http2-util-update-options-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
const IDX_OPTIONS_MAX_SETTINGS = 9;
const IDX_OPTIONS_STREAM_RESET_RATE = 10;
const IDX_OPTIONS_STREAM_RESET_BURST = 11;
const IDX_OPTIONS_FLAGS = 12;
const IDX_OPTIONS_STRICT_HTTP_HEADER_FIELD_VALIDATION = 12;
const IDX_OPTIONS_FLAGS = 13;

{
updateOptionsBuffer({
Expand All @@ -41,6 +42,7 @@
maxSettings: 10,
streamResetRate: 11,
streamResetBurst: 12,
strictHttpHeaderFieldValidation: false
});

strictEqual(optionsBuffer[IDX_OPTIONS_MAX_DEFLATE_DYNAMIC_TABLE_SIZE], 1);
Expand All @@ -55,6 +57,7 @@
strictEqual(optionsBuffer[IDX_OPTIONS_MAX_SETTINGS], 10);
strictEqual(optionsBuffer[IDX_OPTIONS_STREAM_RESET_RATE], 11);
strictEqual(optionsBuffer[IDX_OPTIONS_STREAM_RESET_BURST], 12);
strictEqual(optionsBuffer[IDX_OPTIONS_STRICT_HTTP_HEADER_FIELD_VALIDATION], 1);

Check failure on line 60 in test/parallel/test-http2-util-update-options-buffer.js

View workflow job for this annotation

GitHub Actions / test-linux (ubuntu-24.04)

--- stderr --- node:assert:95 throw new AssertionError(obj); ^ AssertionError [ERR_ASSERTION]: Expected values to be strictly equal: 0 !== 1 at Object.<anonymous> (/home/runner/work/node/node/node/test/parallel/test-http2-util-update-options-buffer.js:60:3) at Module._compile (node:internal/modules/cjs/loader:1734:14) at Object..js (node:internal/modules/cjs/loader:1899:10) at Module.load (node:internal/modules/cjs/loader:1469:32) at Function._load (node:internal/modules/cjs/loader:1286:12) at TracingChannel.traceSync (node:diagnostics_channel:322:14) at wrapModuleLoad (node:internal/modules/cjs/loader:235:24) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:152:5) at node:internal/main/run_main_module:33:47 { generatedMessage: true, code: 'ERR_ASSERTION', actual: 0, expected: 1, operator: 'strictEqual' } Node.js v24.0.0-pre Command: out/Release/node --expose-internals --test-reporter=./test/common/test-error-reporter.js --test-reporter-destination=stdout /home/runner/work/node/node/node/test/parallel/test-http2-util-update-options-buffer.js

Check failure on line 60 in test/parallel/test-http2-util-update-options-buffer.js

View workflow job for this annotation

GitHub Actions / test-macOS

--- stderr --- node:assert:95 throw new AssertionError(obj); ^ AssertionError [ERR_ASSERTION]: Expected values to be strictly equal: 0 !== 1 at Object.<anonymous> (/Users/runner/work/node/node/node/test/parallel/test-http2-util-update-options-buffer.js:60:3) at Module._compile (node:internal/modules/cjs/loader:1734:14) at Object..js (node:internal/modules/cjs/loader:1899:10) at Module.load (node:internal/modules/cjs/loader:1469:32) at Function._load (node:internal/modules/cjs/loader:1286:12) at TracingChannel.traceSync (node:diagnostics_channel:322:14) at wrapModuleLoad (node:internal/modules/cjs/loader:235:24) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:152:5) at node:internal/main/run_main_module:33:47 { generatedMessage: true, code: 'ERR_ASSERTION', actual: 0, expected: 1, operator: 'strictEqual' } Node.js v24.0.0-pre Command: out/Release/node --expose-internals --test-reporter=./test/common/test-error-reporter.js --test-reporter-destination=stdout /Users/runner/work/node/node/node/test/parallel/test-http2-util-update-options-buffer.js

Check failure on line 60 in test/parallel/test-http2-util-update-options-buffer.js

View workflow job for this annotation

GitHub Actions / test-linux (ubuntu-24.04-arm)

--- stderr --- node:assert:95 throw new AssertionError(obj); ^ AssertionError [ERR_ASSERTION]: Expected values to be strictly equal: 0 !== 1 at Object.<anonymous> (/home/runner/work/node/node/node/test/parallel/test-http2-util-update-options-buffer.js:60:3) at Module._compile (node:internal/modules/cjs/loader:1734:14) at Object..js (node:internal/modules/cjs/loader:1899:10) at Module.load (node:internal/modules/cjs/loader:1469:32) at Function._load (node:internal/modules/cjs/loader:1286:12) at TracingChannel.traceSync (node:diagnostics_channel:322:14) at wrapModuleLoad (node:internal/modules/cjs/loader:235:24) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:152:5) at node:internal/main/run_main_module:33:47 { generatedMessage: true, code: 'ERR_ASSERTION', actual: 0, expected: 1, operator: 'strictEqual' } Node.js v24.0.0-pre Command: out/Release/node --expose-internals --test-reporter=./test/common/test-error-reporter.js --test-reporter-destination=stdout /home/runner/work/node/node/node/test/parallel/test-http2-util-update-options-buffer.js

const flags = optionsBuffer[IDX_OPTIONS_FLAGS];

Expand All @@ -69,6 +72,7 @@
ok(flags & (1 << IDX_OPTIONS_MAX_SETTINGS));
ok(flags & (1 << IDX_OPTIONS_STREAM_RESET_RATE));
ok(flags & (1 << IDX_OPTIONS_STREAM_RESET_BURST));
ok(flags & (1 << IDX_OPTIONS_STRICT_HTTP_HEADER_FIELD_VALIDATION));
}

{
Expand Down
Loading