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

https: do not automatically use invalid servername #28209

Closed
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
12 changes: 10 additions & 2 deletions doc/api/https.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,23 @@ An [`Agent`][] object for HTTPS similar to [`http.Agent`][]. See
[`https.request()`][] for more information.

### new Agent([options])

<!-- YAML
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/28209
description: do not automatically set servername if the target host was
specified using an IP address.
-->
* `options` {Object} Set of configurable options to set on the agent.
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.
**Default:** hostname of the target server, unless the target server
is specified using an IP address, in which case the default is `''` (no
extension).

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

Expand Down
3 changes: 3 additions & 0 deletions lib/_http_agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,9 @@ function calculateServerName(options, req) {
servername = hostHeader.split(':', 1)[0];
}
}
// Don't implicitly set invalid (IP) servernames.
if (net.isIP(servername))
servername = '';
return servername;
}

Expand Down
3 changes: 3 additions & 0 deletions test/parallel/test-https-simple.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ if (!common.hasCrypto)
const assert = require('assert');
const https = require('https');

// Assert that the IP-as-servername deprecation warning does not occur.
process.on('warning', common.mustNotCall());

const options = {
key: fixtures.readKey('agent1-key.pem'),
cert: fixtures.readKey('agent1-cert.pem')
Expand Down