Skip to content

Commit 9b2ffff

Browse files
Rodger Combsoyyd
Rodger Combs
authored andcommitted
tls: emit a warning when servername is an IP address
Setting the TLS ServerName to an IP address is not permitted by RFC6066. This will be ignored in a future version. Refs: #18127 PR-URL: #23329 Fixes: #18071 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]>
1 parent c347e77 commit 9b2ffff

File tree

3 files changed

+69
-1
lines changed

3 files changed

+69
-1
lines changed

doc/api/deprecations.md

+15
Original file line numberDiff line numberDiff line change
@@ -2293,6 +2293,20 @@ Type: Runtime
22932293
Please use `Server.prototype.setSecureContext()` instead.
22942294
22952295
2296+
<a id="DEP0123"></a>
2297+
### DEP0123: setting the TLS ServerName to an IP address
2298+
<!-- YAML
2299+
changes:
2300+
- version: REPLACEME
2301+
pr-url: https://github.com/nodejs/node/pull/REPLACEME
2302+
description: Runtime deprecation.
2303+
-->
2304+
2305+
Type: Runtime
2306+
2307+
Setting the TLS ServerName to an IP address is not permitted by
2308+
[RFC 6066][]. This will be ignored in a future version.
2309+
22962310
[`--pending-deprecation`]: cli.html#cli_pending_deprecation
22972311
[`Buffer.allocUnsafeSlow(size)`]: buffer.html#buffer_class_method_buffer_allocunsafeslow_size
22982312
[`Buffer.from(array)`]: buffer.html#buffer_class_method_buffer_from_array
@@ -2393,3 +2407,4 @@ Please use `Server.prototype.setSecureContext()` instead.
23932407
[legacy `urlObject`]: url.html#url_legacy_urlobject
23942408
[NIST SP 800-38D]: https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf
23952409
[WHATWG URL API]: url.html#url_the_whatwg_url_api
2410+
[RFC 6066]: https://tools.ietf.org/html/rfc6066#section-3

lib/_tls_wrap.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ const kSNICallback = Symbol('snicallback');
5959

6060
const noop = () => {};
6161

62+
let ipServernameWarned = false;
63+
6264
function onhandshakestart(now) {
6365
debug('onhandshakestart');
6466

@@ -1240,8 +1242,18 @@ exports.connect = function connect(...args) {
12401242
if (options.session)
12411243
socket.setSession(options.session);
12421244

1243-
if (options.servername)
1245+
if (options.servername) {
1246+
if (!ipServernameWarned && net.isIP(options.servername)) {
1247+
process.emitWarning(
1248+
'Setting the TLS ServerName to an IP address is not permitted by ' +
1249+
'RFC 6066. This will be ignored in a future version.',
1250+
'DeprecationWarning',
1251+
'DEP0123'
1252+
);
1253+
ipServernameWarned = true;
1254+
}
12441255
socket.setServername(options.servername);
1256+
}
12451257

12461258
if (options.socket)
12471259
socket._start();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const fixtures = require('../common/fixtures');
5+
6+
if (!common.hasCrypto)
7+
common.skip('missing crypto');
8+
9+
const tls = require('tls');
10+
11+
// This test expects `tls.connect()` to emit a warning when
12+
// `servername` of options is an IP address.
13+
common.expectWarning(
14+
'DeprecationWarning',
15+
'Setting the TLS ServerName to an IP address is not permitted by ' +
16+
'RFC 6066. This will be ignored in a future version.',
17+
'DEP0123'
18+
);
19+
20+
{
21+
const options = {
22+
key: fixtures.readKey('agent1-key.pem'),
23+
cert: fixtures.readKey('agent1-cert.pem')
24+
};
25+
26+
const server = tls.createServer(options, function(s) {
27+
s.end('hello');
28+
}).listen(0, function() {
29+
const client = tls.connect({
30+
port: this.address().port,
31+
rejectUnauthorized: false,
32+
servername: '127.0.0.1',
33+
}, function() {
34+
client.end();
35+
});
36+
});
37+
38+
server.on('connection', common.mustCall(function(socket) {
39+
server.close();
40+
}));
41+
}

0 commit comments

Comments
 (0)