From c274615d462b9a12cba5471462c6faaf63d874c5 Mon Sep 17 00:00:00 2001 From: Dan Aprahamian Date: Mon, 18 Nov 2019 12:34:30 -0500 Subject: [PATCH] fix(encryption): autoEncryption must error on mongodb < 4.2 Fixes NODE-2334 --- lib/core/wireprotocol/command.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/core/wireprotocol/command.js b/lib/core/wireprotocol/command.js index bb7637ed8a..f395b91b27 100644 --- a/lib/core/wireprotocol/command.js +++ b/lib/core/wireprotocol/command.js @@ -9,6 +9,7 @@ const databaseNamespace = require('./shared').databaseNamespace; const isTransactionCommand = require('../transactions').isTransactionCommand; const applySession = require('../sessions').applySession; const MongoNetworkError = require('../error').MongoNetworkError; +const maxWireVersion = require('../utils').maxWireVersion; function isClientEncryptionEnabled(server) { return server.autoEncrypter; @@ -27,6 +28,12 @@ function command(server, ns, cmd, options, callback) { return; } + const wireVersion = maxWireVersion(server); + if (typeof wireVersion !== 'number' || wireVersion < 8) { + callback(new MongoError('Auto-encryption requires a minimum MongoDB version of 4.2')); + return; + } + _cryptCommand(server, ns, cmd, options, callback); }