1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Fix Sentry in LavaMoat contexts (#15672)

Our Sentry setup relies upon application state, but it wasn't able to
access it in LavaMoat builds because it's running in a separate
Compartment.

A patch has been introduced to the LavaMoat runtime to allow the root
Compartment to mutate the `rootGlobals` object, which is accessible
from outside the compartment as well. This lets us expose application
state to our Sentry integration.
This commit is contained in:
Mark Stacey 2022-08-23 09:42:50 -04:00 committed by GitHub
parent 22552a0152
commit d55507615c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 3 deletions

View File

@ -786,7 +786,10 @@ browser.runtime.onInstalled.addListener(({ reason }) => {
}); });
function setupSentryGetStateGlobal(store) { function setupSentryGetStateGlobal(store) {
global.getSentryState = function () { if (!global.rootGlobals) {
global.rootGlobals = {};
}
global.rootGlobals.getSentryState = function () {
const fullState = store.getState(); const fullState = store.getState();
const debugState = maskObject({ metamask: fullState }, SENTRY_STATE); const debugState = maskObject({ metamask: fullState }, SENTRY_STATE);
return { return {

View File

@ -3,5 +3,5 @@ import setupSentry from './lib/setupSentry';
// setup sentry error reporting // setup sentry error reporting
global.sentry = setupSentry({ global.sentry = setupSentry({
release: process.env.METAMASK_VERSION, release: process.env.METAMASK_VERSION,
getState: () => global.getSentryState?.() || {}, getState: () => global.rootGlobals?.getSentryState?.() || {},
}); });

View File

@ -13,3 +13,19 @@ index eb41a0a..3f891ea 100644
// deps, // deps,
// source: sourceMeta.code // source: sourceMeta.code
} }
diff --git a/node_modules/@lavamoat/lavapack/src/runtime.js b/node_modules/@lavamoat/lavapack/src/runtime.js
index 58f76f3..53df0e7 100644
--- a/node_modules/@lavamoat/lavapack/src/runtime.js
+++ b/node_modules/@lavamoat/lavapack/src/runtime.js
@@ -11160,6 +11160,11 @@ function makePrepareRealmGlobalFromConfig ({ createFunctionWrapper }) {
rootPackageCompartment.globalThis[ref] = rootPackageCompartment.globalThis
}
+ // Allow root compartment to expose things to the initial execution environment of the realm.
+ // This is intended to support passing data to shims run before lockdown.
+ globalThis.rootGlobals = {}
+ rootPackageCompartment.globalThis.rootGlobals = globalThis.rootGlobals
+
// save the compartment for use by other modules in the package
packageCompartmentCache.set(rootPackageName, rootPackageCompartment)

View File

@ -191,7 +191,10 @@ function setupDebuggingHelpers(store) {
}); });
return state; return state;
}; };
window.getSentryState = function () { if (!window.rootGlobals) {
window.rootGlobals = {};
}
window.rootGlobals.getSentryState = function () {
const fullState = store.getState(); const fullState = store.getState();
const debugState = maskObject(fullState, SENTRY_STATE); const debugState = maskObject(fullState, SENTRY_STATE);
return { return {