GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — http2: validate non-link headers in writeEarlyHints by mcollina · Pull Request #62017 · nodejs/node

http2: validate non-link headers in writeEarlyHints #62017

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.

Sign up for GitHub

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
nodejs-github-bot merged 1 commit into nodejs:main from mcollina:http-early-hints-validate-headers
May 15, 2026

Uh oh!

There was an error while loading. Please reload this page.

Merged

http2: validate non-link headers in writeEarlyHints #62017

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
1 commit
Select commit
ee38509
http2: validate non-link headers in writeEarlyHints
mcollina Feb 26, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

Some comments aren't visible on the classic Files Changed page.

There are no files selected for viewing

6 changes: 5 additions & 1 deletion 6 lib/internal/http2/compat.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,11 @@ class Http2ServerResponse extends Stream {

for (const key of ObjectKeys(hints)) {
if (key !== 'link') {
headers[key] = hints[key];
const name = key.trim().toLowerCase();
assertValidHeader(name, hints[key]);
if (!checkIsHttpToken(name))
throw new ERR_INVALID_HTTP_TOKEN('Header name', name);
headers[name] = hints[key];
}
}

Expand Down
60 changes: 60 additions & 0 deletions 60 test/parallel/test-http2-compat-write-early-hints-invalid-header.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
'use strict';

const common = require('../common');
if (!common.hasCrypto) common.skip('missing crypto');

const assert = require('node:assert');
const http2 = require('node:http2');
const debug = require('node:util').debuglog('test');

const testResBody = 'response content';

{
const server = http2.createServer();

server.on('request', common.mustCall((req, res) => {
debug('Server sending early hints...');

assert.throws(() => {
res.writeEarlyHints({
'link': '</styles.css>; rel=preload; as=style',
'x\rbad': 'value',
});
}, (err) => err.code === 'ERR_INVALID_HTTP_TOKEN');

assert.throws(() => {
res.writeEarlyHints({
'link': '</styles.css>; rel=preload; as=style',
'x-custom': undefined,
});
}, (err) => err.code === 'ERR_HTTP2_INVALID_HEADER_VALUE');

debug('Server sending full response...');
res.end(testResBody);
}));

server.listen(0);

server.on('listening', common.mustCall(() => {
const client = http2.connect(`http://localhost:${server.address().port}`);
const req = client.request();

debug('Client sending request...');

req.on('headers', common.mustNotCall());

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

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

req.on('end', common.mustCall(() => {
debug('Got full response.');
assert.strictEqual(data, testResBody);
client.close();
server.close();
}));
}));
}
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.