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

Fix: Invalid HTTP/2 origin set when servername is empty #39919 #39934

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion lib/internal/http2/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -3098,7 +3098,7 @@ function initializeTLSOptions(options, servername) {
options.ALPNProtocols = ['h2'];
if (options.allowHTTP1 === true)
ArrayPrototypePush(options.ALPNProtocols, 'http/1.1');
if (servername !== undefined && options.servername === undefined)
if (servername !== undefined && !options.servername)
Narasimha1997 marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

@lpinca lpinca Aug 31, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know it makes sense for http2 but for https the empty string is used to disable the SNI extension. I wonder if the same should be done here.

cc: @nodejs/http2

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Yeah that makes sense. This PR is based in what the issue poster has expected to be the intended behaviour. If you confirm SNI should be disabled, I would be happy to make these changes.

options.servername = servername;
return options;
}
Expand Down
42 changes: 42 additions & 0 deletions test/internet/test-http2-https-origin-string-correctness.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
'use strict';

// Ref: https://github.com/nodejs/node/issues/39919

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

const assert = require('assert');
const http2 = require('http2');

function _verifyOriginSet(session, originString) {
session.once('remoteSettings', () => {
assert.strictEqual(typeof session.originSet, 'object');
assert.strictEqual(session.originSet.length, 1);
assert.strictEqual(session.originSet[0], originString);
session.close();
});
session.once('error', (error) => {
assert.strictEqual(error.code, 'ECONNREFUSED');
session.close();
});
}

function withServerName() {
const session = http2.connect('https://1.1.1.1', { servername: 'cloudflare-dns.com' });
Copy link
Member

@lpinca lpinca Aug 31, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This requires an external connection. Is it possible to use localhost? See #39011.

Edit: This is not a blocker. The test is under test/internet so it should be ok as is.

_verifyOriginSet(session, 'https://cloudflare-dns.com');
}

function withEmptyServerName() {
const session = http2.connect('https://1.1.1.1', { servername: '' });
_verifyOriginSet(session, 'https://1.1.1.1');
}

function withoutServerName() {
const session = http2.connect('https://1.1.1.1');
_verifyOriginSet(session, 'https://1.1.1.1');
}

withServerName();
withEmptyServerName();
withoutServerName();