Skip to content

Commit 3736bf1

Browse files
committed
fix(NODE-3109): prevent servername from being IP
servername should only ever be a hostname. Add a condition to check if the host is an IP and skip auto setting the servername.
1 parent 86bddf1 commit 3736bf1

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

lib/core/connection/connect.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ function parseSslOptions(family, options) {
243243
}
244244

245245
// Set default sni servername to be the same as host
246-
if (result.servername == null) {
246+
if (result.servername == null && !net.isIP(result.host)) {
247247
result.servername = result.host;
248248
}
249249

test/manual/tls_support.test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
'use strict';
22
const MongoClient = require('../..').MongoClient;
3+
const expect = require('chai').expect;
4+
const util = require('util');
5+
const dns = require('dns');
6+
const dnsLookup = util.promisify(dns.lookup);
37

48
const REQUIRED_ENV = ['MONGODB_URI', 'SSL_KEY_FILE', 'SSL_CA_FILE'];
59

@@ -28,6 +32,24 @@ describe('TLS Support', function() {
2832
.join('&')}`
2933
)
3034
);
35+
36+
it('should ignore ip addresses in servername', function() {
37+
const hostname = connectionString.match(/mongodb:\/\/(.+):/);
38+
return dnsLookup(hostname)
39+
.then(res => {
40+
const client = new MongoClient(connectionString.replace(hostname, res[0].address), {
41+
tls: true
42+
});
43+
return client.connect();
44+
})
45+
.then(client => {
46+
const connections = client.topology.connections();
47+
48+
for (const connection of connections) {
49+
expect(connection.options.servername).to.not.exist;
50+
}
51+
});
52+
});
3153
});
3254

3355
function makeConnectionTest(connectionString, clientOptions) {

0 commit comments

Comments
 (0)