Skip to content

Commit 731934c

Browse files
committed
improve skip logic
1 parent 0b68686 commit 731934c

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

lib/core/uri_parser.js

Lines changed: 8 additions & 3 deletions
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,9 +429,9 @@ function parseQueryString(query, options) {
424429
}
425430

426431
const normalizedKey = key.toLowerCase();
427-
// skip parsing for tls/ssl values to avoid issues with Windows file paths (containing colons)
428-
const skipParse = /^(?:ssl|tls)/.test(normalizedKey);
429-
const parsedValue = skipParse ? value : parseQueryStringItemValue(normalizedKey, value);
432+
const parsedValue = FILE_PATH_OPTIONS.has(normalizedKey)
433+
? value
434+
: parseQueryStringItemValue(normalizedKey, value);
430435
applyConnectionStringOption(result, normalizedKey, parsedValue, options);
431436
}
432437

0 commit comments

Comments
 (0)