Skip to content

Commit 3b3dd7c

Browse files
committed
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. Closes: #18071 Refs: #18127
1 parent 1d253f8 commit 3b3dd7c

File tree

3 files changed

+60
-3
lines changed

3 files changed

+60
-3
lines changed

doc/api/deprecations.md

Lines changed: 15 additions & 0 deletions
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="DEP00XX"></a>
2297+
### DEP00XX: 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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,9 +1235,10 @@ exports.connect = function connect(...args) {
12351235
if (options.servername) {
12361236
if (!ipServernameWarned && net.isIP(options.servername)) {
12371237
process.emitWarning(
1238-
'Setting the TLS ServerName to an IP address is not supported by ' +
1239-
'RFC6066. This will be ignored in a future version.',
1240-
'UnsupportedWarning'
1238+
'Setting the TLS ServerName to an IP address is not permitted by ' +
1239+
'RFC 6066. This will be ignored in a future version.',
1240+
'DeprecationWarning',
1241+
'DEP00XX'
12411242
);
12421243
ipServernameWarned = true;
12431244
}
Lines changed: 41 additions & 0 deletions
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+
'DEP00XX'
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)