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

Restore support for Chromium v78 (#17251)

Support has been restored for Chromium v78. Previously the extension
would crash upon startup.

The main incompatibility was the use of ES2020 operators (the optional
chain and nullish coalesce operators) in the libraries
 `@ethereumjs/util` and `superstruct`. This was resolved by transpiling
those libraries.

After fixing that, the extension no longer crashed but the UI refused
to connect. This was because the UI process was not being identified as
an internal process, because the code responsible for checking that was
relying on the `origin` property of `MessageSender` [1] which wasn't
added until Chromium v80. The check has been updated to use the `url`
property instead, which existed in older versions of Chrome.

Lastly, the content security policy was updated to include the default
content security policy alongside the intended modification. Newer
versions of Chrome will merge the configired CSP with the default, but
older versions required it to be explicitly specified. This should not
result in any functional change.

[1]: https://developer.chrome.com/docs/extensions/reference/runtime/#type-MessageSender
This commit is contained in:
Mark Stacey 2023-01-23 12:36:48 -03:30 committed by GitHub
parent 16851c83ef
commit cb12cb8f5a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 6 deletions

View File

@ -1,5 +1,5 @@
{
"content_security_policy": "frame-ancestors 'none'",
"content_security_policy": "frame-ancestors 'none'; script-src 'self'; object-src 'self'",
"externally_connectable": {
"matches": ["https://metamask.io/*"],
"ids": ["*"]

View File

@ -483,18 +483,17 @@ function setupController(initState, initLangCode) {
let isMetaMaskInternalProcess = false;
const sourcePlatform = getPlatform();
const senderUrl = remotePort.sender?.url
? new URL(remotePort.sender.url)
: null;
if (sourcePlatform === PLATFORM_FIREFOX) {
isMetaMaskInternalProcess = metamaskInternalProcessHash[processName];
} else {
isMetaMaskInternalProcess =
remotePort.sender.origin === `chrome-extension://${browser.runtime.id}`;
senderUrl?.origin === `chrome-extension://${browser.runtime.id}`;
}
const senderUrl = remotePort.sender?.url
? new URL(remotePort.sender.url)
: null;
if (isMetaMaskInternalProcess) {
const portStream = new PortStream(remotePort);
// communication with popup

View File

@ -828,6 +828,17 @@ function setupBundlerDefaults(
// Run TypeScript files through Babel
{ extensions },
],
// Transpile libraries that use ES2020 unsupported by Chrome v78
[
babelify,
{
only: [
'./**/node_modules/@ethereumjs/util',
'./**/node_modules/superstruct',
],
global: true,
},
],
// Inline `fs.readFileSync` files
brfs,
],