Skip to content

Commit 81299d0

Browse files
committed
fix: dont parse tls/ssl file paths in uri
1 parent 625f7c6 commit 81299d0

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

lib/core/uri_parser.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ const ReadPreference = require('./topologies/read_preference');
1111
*/
1212
const HOSTS_RX = /(mongodb(?:\+srv|)):\/\/(?: (?:[^:]*) (?: : ([^@]*) )? @ )?([^/?]*)(?:\/|)(.*)/;
1313

14+
// Options that reference file paths should not be parsed
15+
const FILE_PATH_OPTIONS = new Set(
16+
['sslCA', 'sslCert', 'sslKey', 'tlsCAFile', 'tlsCertificateKeyFile'].map(key => key.toLowerCase())
17+
);
18+
1419
/**
1520
* Determines whether a provided address matches the provided parent domain in order
1621
* to avoid certain attack vectors.
@@ -424,7 +429,9 @@ function parseQueryString(query, options) {
424429
}
425430

426431
const normalizedKey = key.toLowerCase();
427-
const parsedValue = parseQueryStringItemValue(normalizedKey, value);
432+
const parsedValue = FILE_PATH_OPTIONS.has(normalizedKey)
433+
? value
434+
: parseQueryStringItemValue(normalizedKey, value);
428435
applyConnectionStringOption(result, normalizedKey, parsedValue, options);
429436
}
430437

test/manual/tls_support.test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ describe('TLS Support', function() {
2020
makeConnectionTest(connectionString, tlsSettings)
2121
);
2222

23-
const queryString = Object.keys(tlsSettings)
24-
.map(key => `${key}=${tlsSettings[key]}`)
25-
.join('&');
26-
console.log({ tlsSettings, url: `${connectionString}?${queryString}` });
2723
it(
2824
'should connect with tls via url options',
29-
makeConnectionTest(`${connectionString}?${queryString}`)
25+
makeConnectionTest(
26+
`${connectionString}?${Object.keys(tlsSettings)
27+
.map(key => `${key}=${tlsSettings[key]}`)
28+
.join('&')}`
29+
)
3030
);
3131
});
3232

0 commit comments

Comments
 (0)