From cf60c8e1f6f5165965dc4ac29b86d3cd4df3db8c Mon Sep 17 00:00:00 2001 From: Erik Marks <25517051+rekmarks@users.noreply.github.com> Date: Fri, 29 May 2020 10:53:31 -0700 Subject: [PATCH] Stop adding permissions middleware to trusted connections (#8701) * don't add permissions middleware to trusted connections * fix test case --- app/scripts/metamask-controller.js | 11 +++++++---- .../permissions/permissions-controller-test.js | 4 ++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 6fb68b182..cf77ef7ca 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -1548,7 +1548,7 @@ export default class MetamaskController extends EventEmitter { tabId = sender.tab.id } - const engine = this.setupProviderEngine({ origin, location: sender.url, extensionId, tabId }) + const engine = this.setupProviderEngine({ origin, location: sender.url, extensionId, tabId, isInternal }) // setup connection const providerStream = createEngineStream({ engine }) @@ -1581,8 +1581,9 @@ export default class MetamaskController extends EventEmitter { * @param {string} options.location - The full URL of the sender * @param {extensionId} [options.extensionId] - The extension ID of the sender, if the sender is an external extension * @param {tabId} [options.tabId] - The tab ID of the sender - if the sender is within a tab + * @param {boolean} [options.isInternal] - True if called for a connection to an internal process **/ - setupProviderEngine ({ origin, location, extensionId, tabId }) { + setupProviderEngine ({ origin, location, extensionId, tabId, isInternal = false }) { // setup json rpc engine stack const engine = new RpcEngine() const provider = this.provider @@ -1610,8 +1611,10 @@ export default class MetamaskController extends EventEmitter { // filter and subscription polyfills engine.push(filterMiddleware) engine.push(subscriptionManager.middleware) - // permissions - engine.push(this.permissionsController.createMiddleware({ origin, extensionId })) + if (!isInternal) { + // permissions + engine.push(this.permissionsController.createMiddleware({ origin, extensionId })) + } // watch asset engine.push(this.preferencesController.requestWatchAsset.bind(this.preferencesController)) // forward to metamask primary provider diff --git a/test/unit/app/controllers/permissions/permissions-controller-test.js b/test/unit/app/controllers/permissions/permissions-controller-test.js index 2d1de4630..b085e0bf7 100644 --- a/test/unit/app/controllers/permissions/permissions-controller-test.js +++ b/test/unit/app/controllers/permissions/permissions-controller-test.js @@ -102,8 +102,8 @@ describe('permissions controller', function () { assert.deepEqual(cAccounts, [], 'origin should have no accounts') }) - it('does not handle "MetaMask" origin as special case', async function () { - const metamaskAccounts = await permController.getAccounts('MetaMask') + it('does not handle "metamask" origin as special case', async function () { + const metamaskAccounts = await permController.getAccounts('metamask') assert.deepEqual(metamaskAccounts, [], 'origin should have no accounts') }) })