diff --git a/lib/core/auth/mongodb_aws.js b/lib/core/auth/mongodb_aws.js index af19d6dc0d..492b573e61 100644 --- a/lib/core/auth/mongodb_aws.js +++ b/lib/core/auth/mongodb_aws.js @@ -9,6 +9,7 @@ const url = require('url'); let aws4; try { + // Ensure you always wrap an optional require in the try block NODE-3199 aws4 = require('aws4'); } catch (e) { // don't do anything; diff --git a/lib/core/auth/scram.js b/lib/core/auth/scram.js index 7eca32dda3..2d1787810c 100644 --- a/lib/core/auth/scram.js +++ b/lib/core/auth/scram.js @@ -11,6 +11,7 @@ const Binary = BSON.Binary; let saslprep; try { + // Ensure you always wrap an optional require in the try block NODE-3199 saslprep = require('saslprep'); } catch (e) { // don't do anything; diff --git a/lib/core/index.js b/lib/core/index.js index cf3bbfed7b..b01be2ad25 100644 --- a/lib/core/index.js +++ b/lib/core/index.js @@ -5,6 +5,7 @@ const require_optional = require('optional-require')(require); const EJSON = require('./utils').retrieveEJSON(); try { + // Ensure you always wrap an optional require in the try block NODE-3199 // Attempt to grab the native BSON parser const BSONNative = require_optional('bson-ext'); // If we got the native parser, use it instead of the diff --git a/lib/core/utils.js b/lib/core/utils.js index 631c4a9b3b..0940619efa 100644 --- a/lib/core/utils.js +++ b/lib/core/utils.js @@ -27,6 +27,7 @@ function retrieveKerberos() { let kerberos; try { + // Ensure you always wrap an optional require in the try block NODE-3199 kerberos = requireOptional('kerberos'); } catch (err) { if (err.code === 'MODULE_NOT_FOUND') { diff --git a/lib/encrypter.js b/lib/encrypter.js index 4f0155d361..ecf69babbf 100644 --- a/lib/encrypter.js +++ b/lib/encrypter.js @@ -3,8 +3,10 @@ const MongoClient = require('./mongo_client'); const BSON = require('./core/connection/utils').retrieveBSON(); const MongoError = require('./core/error').MongoError; +let mongodbClientEncryption = undefined; try { - require.resolve('mongodb-client-encryption'); + // Ensure you always wrap an optional require in the try block NODE-3199 + mongodbClientEncryption = require('mongodb-client-encryption'); } catch (err) { throw new MongoError( 'Auto-encryption requested, but the module is not installed. ' + @@ -12,13 +14,16 @@ try { ); } -const mongodbClientEncryption = require('mongodb-client-encryption'); -if (typeof mongodbClientEncryption.extension !== 'function') { +if ( + mongodbClientEncryption === undefined || + typeof mongodbClientEncryption.extension !== 'function' +) { throw new MongoError( 'loaded version of `mongodb-client-encryption` does not have property `extension`. ' + 'Please make sure you are loading the correct version of `mongodb-client-encryption`' ); } + const AutoEncrypter = mongodbClientEncryption.extension(require('../index')).AutoEncrypter; const kInternalClient = Symbol('internalClient'); diff --git a/package-lock.json b/package-lock.json index 6677f69392..0a3a8eaf2d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -722,9 +722,9 @@ } }, "caniuse-lite": { - "version": "1.0.30001243", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001243.tgz", - "integrity": "sha512-vNxw9mkTBtkmLFnJRv/2rhs1yufpDfCkBZexG3Y0xdOH2Z/eE/85E4Dl5j1YUN34nZVsSp6vVRFQRrez9wJMRA==", + "version": "1.0.30001245", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001245.tgz", + "integrity": "sha512-768fM9j1PKXpOCKws6eTo3RHmvTUsG9UrpT4WoREFeZgJBTi4/X9g565azS/rVUGtqb8nt7FjLeF5u4kukERnA==", "dev": true }, "catharsis": { @@ -1318,9 +1318,9 @@ } }, "electron-to-chromium": { - "version": "1.3.771", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.771.tgz", - "integrity": "sha512-zHMomTqkpnAD9W5rhXE1aiU3ogGFrqWzdvM4C6222SREiqsWQb2w0S7P2Ii44qCaGimmAP1z+OydllM438uJyA==", + "version": "1.3.778", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.778.tgz", + "integrity": "sha512-Lw04qJaPtWdq0d7qKHJTgkam+FhFi3hm/scf1EyqJWdjO3ZIGUJhNmZJRXWb7yb/bRYXQyVGSpa9RqVpjjWMQw==", "dev": true }, "emoji-regex": { @@ -2303,9 +2303,9 @@ "dev": true }, "is-core-module": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.4.0.tgz", - "integrity": "sha512-6A2fkfq1rfeQZjxrZJGerpLCTHRNEBiSgnu0+obeJpEPZRUooHgsizvzv0ZjJwOz3iWIHdJtVWJ/tmPr3D21/A==", + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.5.0.tgz", + "integrity": "sha512-TXCMSDsEHMEEZ6eCA8rwRDbLu55MRGmrctljsBX/2v1d9/GzqHOxW5c5oPSgrUt2vBFXebu9rGqckXGPWOlYpg==", "dev": true, "requires": { "has": "^1.0.3" @@ -3310,9 +3310,9 @@ "dev": true }, "object-inspect": { - "version": "1.10.3", - "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.10.3.tgz", - "integrity": "sha512-e5mCJlSH7poANfC8z8S9s9S2IN5/4Zb3aZ33f5s8YqoazCFzNLloLU8r5VCG+G7WoqLvAAZoVMcy3tp/3X0Plw==", + "version": "1.11.0", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.11.0.tgz", + "integrity": "sha512-jp7ikS6Sd3GxQfZJPyH3cjcbJF6GZPClgdV+EFygjFLQ5FmW/dRUnTd9PQ9k0JhoNDabWFbpF1yCdSWCC6gexg==", "dev": true }, "object-keys": { @@ -4110,9 +4110,9 @@ "dev": true }, "standard-version": { - "version": "9.3.0", - "resolved": "https://registry.npmjs.org/standard-version/-/standard-version-9.3.0.tgz", - "integrity": "sha512-cYxxKXhYfI3S9+CA84HmrJa9B88H56V5FQ302iFF2TNwJukJCNoU8FgWt+11YtwKFXRkQQFpepC2QOF7aDq2Ow==", + "version": "9.3.1", + "resolved": "https://registry.npmjs.org/standard-version/-/standard-version-9.3.1.tgz", + "integrity": "sha512-5qMxXw/FxLouC5nANyx/5RY1kiorJx9BppUso8gN07MG64q2uLRmrPb4KfXp3Ql4s/gxjZwZ89e0FwxeLubGww==", "dev": true, "requires": { "chalk": "^2.4.2", @@ -4359,9 +4359,9 @@ }, "dependencies": { "ajv": { - "version": "8.6.1", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.6.1.tgz", - "integrity": "sha512-42VLtQUOLefAvKFAQIxIZDaThq6om/PrfP0CYk3/vn+y4BMNkKnbli8ON2QCiHov4KkzOSJ/xSoBJdayiiYvVQ==", + "version": "8.6.2", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.6.2.tgz", + "integrity": "sha512-9807RlWAgT564wT+DjeyU5OFMPjmzxVobvDFmNAhY+5zD6A2ly3jDp6sgnfyDtlIQ+7H97oc/DGCzzfu9rjw9w==", "dev": true, "requires": { "fast-deep-equal": "^3.1.1",