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

http: servername === false should disable SNI #27316

Closed
wants to merge 5 commits into from
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
5 changes: 5 additions & 0 deletions doc/api/https.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ An [`Agent`][] object for HTTPS similar to [`http.Agent`][]. See
Can have the same fields as for [`http.Agent(options)`][], and
* `maxCachedSessions` {number} maximum number of TLS cached sessions.
Use `0` to disable TLS session caching. **Default:** `100`.
* `servername` {string} the value of
[Server Name Indication extension][sni wiki] to be sent to the server. Use
empty string `''` to disable sending the extension.
**Default:** hostname or IP address of the target server.

See [`Session Resumption`][] for infomation about TLS session reuse.

Expand Down Expand Up @@ -406,3 +410,4 @@ headers: max-age=0; pin-sha256="WoiWRyIOVNa9ihaBciRSC7XHjliYS9VwUGOIud4PB18="; p
[`tls.createSecureContext()`]: tls.html#tls_tls_createsecurecontext_options
[`tls.createServer()`]: tls.html#tls_tls_createserver_options_secureconnectionlistener
[`Session Resumption`]: tls.html#tls_session_resumption
[sni wiki]: https://en.wikipedia.org/wiki/Server_Name_Indication
4 changes: 2 additions & 2 deletions lib/_http_agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ Agent.prototype.addRequest = function addRequest(req, options, port/* legacy */,
if (options.socketPath)
options.path = options.socketPath;

if (!options.servername)
if (!options.servername && options.servername !== '')
options.servername = calculateServerName(options, req);

const name = this.getName(options);
Expand Down Expand Up @@ -198,7 +198,7 @@ Agent.prototype.createSocket = function createSocket(req, options, cb) {
if (options.socketPath)
options.path = options.socketPath;

if (!options.servername)
if (!options.servername && options.servername !== '')
options.servername = calculateServerName(options, req);

const name = this.getName(options);
Expand Down
21 changes: 17 additions & 4 deletions test/parallel/test-https-agent-sni.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,21 @@ let waiting = TOTAL;
const server = https.Server(options, function(req, res) {
if (--waiting === 0) server.close();

res.writeHead(200, {
'x-sni': req.socket.servername
});
const servername = req.socket.servername;

if (servername !== false) {
res.setHeader('x-sni', servername);
}

res.end('hello world');
});

server.listen(0, function() {
function expectResponse(id) {
return common.mustCall(function(res) {
res.resume();
assert.strictEqual(res.headers['x-sni'], `sni.${id}`);
assert.strictEqual(res.headers['x-sni'],
id === false ? undefined : `sni.${id}`);
});
}

Expand All @@ -46,4 +50,13 @@ server.listen(0, function() {
rejectUnauthorized: false
}, expectResponse(j));
}
https.get({
agent: agent,

indutny marked this conversation as resolved.
Show resolved Hide resolved
path: '/',
port: this.address().port,
host: '127.0.0.1',
servername: '',
rejectUnauthorized: false
}, expectResponse(false));
});