Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove catch for synchronous socket errors and remove validation on nodejs option #2746

Merged
merged 4 commits into from
Mar 11, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"@types/chai-subset": "^1.3.3",
"@types/kerberos": "^1.1.0",
"@types/mocha": "^8.2.0",
"@types/node": "^14.6.4",
"@types/node": "^14.14.31",
"@types/saslprep": "^1.0.0",
"@types/semver": "^7.3.4",
"@typescript-eslint/eslint-plugin": "^4.15.1",
Expand Down
27 changes: 7 additions & 20 deletions src/cmap/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,6 @@ function parseSslOptions(options: ConnectionOptions): TLSConnectionOpts {
}
}

// Override checkServerIdentity behavior
if (!options.checkServerIdentity) {
// Skip the identity check by retuning undefined as per node documents
// https://nodejs.org/api/tls.html#tls_tls_connect_options_callback
result.checkServerIdentity = () => undefined;
} else if (typeof options.checkServerIdentity === 'function') {
result.checkServerIdentity = options.checkServerIdentity;
}
Comment on lines -250 to -257
Copy link
Contributor Author

@nbbeeken nbbeeken Mar 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checkServerIdentity is a nodejs TLS option, and nodejs asserts that it is of type function. I suggest that we don't intervene on a boolean type but allow the option to pass directly to the tls API. @mbroadst Thoughts?

NODE-3141

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems fine for 4.0, but make sure the documentation reflects this, and that your upgrade notes mention it. The change can't be made for 3.x unfortunately.


// Set default sni servername to be the same as host
if (result.servername == null) {
result.servername = result.host;
Expand Down Expand Up @@ -289,18 +280,14 @@ function makeConnection(options: ConnectionOptions, _callback: CallbackWithType<
_callback(err, ret);
};

try {
if (useTLS) {
const tlsSocket = tls.connect(parseSslOptions(options));
if (typeof tlsSocket.disableRenegotiation === 'function') {
tlsSocket.disableRenegotiation();
}
socket = tlsSocket;
} else {
socket = net.createConnection(parseConnectOptions(options));
if (useTLS) {
const tlsSocket = tls.connect(parseSslOptions(options));
if (typeof tlsSocket.disableRenegotiation === 'function') {
tlsSocket.disableRenegotiation();
}
} catch (err) {
return callback(err);
socket = tlsSocket;
} else {
socket = net.createConnection(parseConnectOptions(options));
}

socket.setKeepAlive(keepAlive, keepAliveInitialDelay);
Expand Down
11 changes: 1 addition & 10 deletions src/connection_string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -575,16 +575,6 @@ export const OPTIONS = {
checkKeys: {
type: 'boolean'
},
checkServerIdentity: {
target: 'checkServerIdentity',
transform({
values: [value]
}): boolean | ((hostname: string, cert: Document) => Error | undefined) {
if (typeof value !== 'boolean' && typeof value !== 'function')
throw new MongoParseError('check server identity must be a boolean or custom function');
return value as boolean | ((hostname: string, cert: Document) => Error | undefined);
}
},
compressors: {
default: 'none',
target: 'compressors',
Expand Down Expand Up @@ -1041,6 +1031,7 @@ export const OPTIONS = {
enableTrace: { type: 'any' },
requestCert: { type: 'any' },
rejectUnauthorized: { type: 'any' },
checkServerIdentity: { type: 'any' },
ALPNProtocols: { type: 'any' },
SNICallback: { type: 'any' },
session: { type: 'any' },
Expand Down