From 3d46f0c07f37d9a022be83db8d5b9e149e65bdb3 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Fri, 9 Apr 2021 16:43:42 +0200 Subject: [PATCH] fix(shell-api): do not expose internalState as global MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I don’t think this was intentionally exposed as a global (it was because all own properties of the `ShellApi` instance are copied onto the global object). Hide it by making it a non-own property. --- packages/shell-api/src/shell-api.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/shell-api/src/shell-api.ts b/packages/shell-api/src/shell-api.ts index a29f3ead5c..47c3570411 100644 --- a/packages/shell-api/src/shell-api.ts +++ b/packages/shell-api/src/shell-api.ts @@ -22,20 +22,28 @@ import { promisify } from 'util'; import { ClientSideFieldLevelEncryptionOptions } from './field-level-encryption'; import { dirname } from 'path'; +const internalStateSymbol = Symbol.for('@@mongosh.internalState'); + @shellApiClassDefault @hasAsyncChild export default class ShellApi extends ShellApiClass { - readonly internalState: ShellInternalState; + // Use a symbol to make sure this is *not* one of the things copied over into + // the global scope. + [internalStateSymbol]: ShellInternalState; public DBQuery: DBQuery; loadCallNestingLevel: number; constructor(internalState: ShellInternalState) { super(); - this.internalState = internalState; + this[internalStateSymbol] = internalState; this.DBQuery = new DBQuery(); this.loadCallNestingLevel = 0; } + get internalState(): ShellInternalState { + return this[internalStateSymbol]; + } + @directShellCommand use(db: string): any { return this.internalState.currentDb._mongo.use(db);