-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Fix LavaMoat build failures and restore RegExp OOM mitigation
LavaMoat was updated recently, but the patch we had of `lavamoat-core` was not updated with it. This restores the changes made in that patch. Note that the old patch still exists because we're still using the older version of `lavamoat-core` for the `lavamoat-viz` tool. The patch had three changes; the third was upstreamed already so it was not required, but the first two (RegExp cache and skipping policy write) were still required. Fixes #29482
- Loading branch information
Showing
3 changed files
with
70 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
diff --git a/src/loadPolicy.js b/src/loadPolicy.js | ||
index b3053356c739a5f351fd4e271b67e31ee00bb4dc..7daebe4104ce5d799f90068516b1d0aaa58546c0 100644 | ||
--- a/src/loadPolicy.js | ||
+++ b/src/loadPolicy.js | ||
@@ -101,10 +101,9 @@ async function loadPolicyAndApplyOverrides({ | ||
|
||
const finalPolicy = mergePolicy(policy, policyOverride) | ||
|
||
- // TODO: Only write if merge results in changes. | ||
- // Would have to make a deep equal check on whole policy, which is a waste of time. | ||
- // mergePolicy() should be able to do it in one pass. | ||
- await fs.writeFile(policyPath, jsonStringifySortedPolicy(finalPolicy)) | ||
+ // Skip policy write step to prevent intermittent build failures | ||
+ // The extension validates the policy in a separate step, we don't need it | ||
+ // to be written to disk here. | ||
|
||
return finalPolicy | ||
} | ||
diff --git a/src/scuttle.js b/src/scuttle.js | ||
index c096a1fbf0bfe8a8f22290852881598f74fff4b1..97f5d1cd09d19f8be1de6a5956d2c39f51058ba0 100644 | ||
--- a/src/scuttle.js | ||
+++ b/src/scuttle.js | ||
@@ -98,6 +98,10 @@ function generateScuttleOpts(globalRef, originalOpts = create(null)) { | ||
} | ||
opts.scuttlerFunc = globalRef[opts.scuttlerName] | ||
} | ||
+ | ||
+ // cache regular expressions to work around https://github.com/MetaMask/metamask-extension/issues/21006 | ||
+ const regexCache = new Map() | ||
+ | ||
return opts | ||
|
||
/** | ||
@@ -109,10 +113,15 @@ function generateScuttleOpts(globalRef, originalOpts = create(null)) { | ||
if (!except.startsWith('/')) { | ||
return except | ||
} | ||
+ if (regexCache.has(except)) { | ||
+ return regexCache.get(except) | ||
+ } | ||
const parts = except.split('/') | ||
const pattern = parts.slice(1, -1).join('/') | ||
const flags = parts[parts.length - 1] | ||
- return new RegExp(pattern, flags) | ||
+ const re = new RegExp(pattern, flags) | ||
+ regexCache.set(except, re) | ||
+ return re | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -225,6 +225,7 @@ | |
"[email protected]": "^7.5.4", | ||
"@trezor/schema-utils@npm:1.0.2": "patch:@trezor/schema-utils@npm%3A1.0.2#~/.yarn/patches/@trezor-schema-utils-npm-1.0.2-7dd48689b2.patch", | ||
"lavamoat-core@npm:^15.1.1": "patch:lavamoat-core@npm%3A15.1.1#~/.yarn/patches/lavamoat-core-npm-15.1.1-51fbe39988.patch", | ||
"lavamoat-core@npm:^16.2.2": "patch:lavamoat-core@npm%3A16.2.2#~/.yarn/patches/lavamoat-core-npm-16.2.2-e361ff1f8a.patch", | ||
"@metamask/snaps-sdk": "^6.14.0", | ||
"@swc/[email protected]": "^0.1.6", | ||
"@babel/core": "patch:@babel/core@npm%3A7.25.9#~/.yarn/patches/@babel-core-npm-7.25.9-4ae3bff7f3.patch", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters