@metamask/snaps-execution-environments 0.37.3-flask.1 → 0.38.1-flask.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -95,8 +95,7 @@
95
95
  // security options are hard-coded at build time
96
96
  const {
97
97
  scuttleGlobalThis,
98
- scuttleGlobalThisExceptions,
99
- } = {"scuttleGlobalThis":true,"scuttleGlobalThisExceptions":["postMessage","removeEventListener","isSecureContext"]}
98
+ } = {"scuttleGlobalThis":{"enabled":true,"exceptions":["postMessage","removeEventListener","isSecureContext"]}}
100
99
 
101
100
  function getGlobalRef () {
102
101
  if (typeof globalThis !== 'undefined') {
@@ -2525,7 +2524,7 @@ const evadeHtmlCommentTest= (src)=>{
2525
2524
  // /////////////////////////////////////////////////////////////////////////////
2526
2525
  $h‍_once.evadeHtmlCommentTest(evadeHtmlCommentTest);
2527
2526
  const importPattern= new FERAL_REG_EXP(
2528
- '(^|[^.])\\bimport(\\s*(?:\\(|/[/*]))',
2527
+ '(^|[^.]|\\.\\.\\.)\\bimport(\\s*(?:\\(|/[/*]))',
2529
2528
  'g');
2530
2529
 
2531
2530
 
@@ -10963,7 +10962,6 @@ function observeImports(map, importName, importIndex) {
10963
10962
  globalThisRefs,
10964
10963
  // security options
10965
10964
  scuttleGlobalThis,
10966
- scuttleGlobalThisExceptions,
10967
10965
  debugMode,
10968
10966
  runWithPrecompiledModules,
10969
10967
  reportStatsHook,
@@ -10991,7 +10989,6 @@ function observeImports(map, importName, importIndex) {
10991
10989
  getExternalCompartment,
10992
10990
  globalThisRefs,
10993
10991
  scuttleGlobalThis,
10994
- scuttleGlobalThisExceptions,
10995
10992
  debugMode,
10996
10993
  runWithPrecompiledModules,
10997
10994
  reportStatsHook,
@@ -11010,8 +11007,7 @@ function observeImports(map, importName, importIndex) {
11010
11007
  prepareModuleInitializerArgs,
11011
11008
  getExternalCompartment,
11012
11009
  globalThisRefs = ['globalThis'],
11013
- scuttleGlobalThis = false,
11014
- scuttleGlobalThisExceptions = [],
11010
+ scuttleGlobalThis = {},
11015
11011
  debugMode = false,
11016
11012
  runWithPrecompiledModules = false,
11017
11013
  reportStatsHook = () => {},
@@ -11557,6 +11553,7 @@ module.exports = {
11557
11553
  return module.exports
11558
11554
  })()
11559
11555
 
11556
+ const scuttleOpts = generateScuttleOpts(scuttleGlobalThis)
11560
11557
  const moduleCache = new Map()
11561
11558
  const packageCompartmentCache = new Map()
11562
11559
  const globalStore = new Map()
@@ -11565,22 +11562,11 @@ module.exports = {
11565
11562
  const rootPackageCompartment = createRootPackageCompartment(globalRef)
11566
11563
 
11567
11564
  // scuttle globalThis right after we used it to create the root package compartment
11568
- if (scuttleGlobalThis) {
11569
- if (!Array.isArray(scuttleGlobalThisExceptions)) {
11570
- throw new Error(`LavaMoat - scuttleGlobalThisExceptions must be an array, got "${typeof scuttleGlobalThisExceptions}"`)
11565
+ if (scuttleOpts.enabled) {
11566
+ if (!Array.isArray(scuttleOpts.exceptions)) {
11567
+ throw new Error(`LavaMoat - scuttleGlobalThis.exceptions must be an array, got "${typeof scuttleOpts.exceptions}"`)
11571
11568
  }
11572
- // turn scuttleGlobalThisExceptions regexes strings to actual regexes
11573
- for (let i = 0; i < scuttleGlobalThisExceptions.length; i++) {
11574
- const prop = scuttleGlobalThisExceptions[i]
11575
- if (!prop.startsWith('/')) {
11576
- continue
11577
- }
11578
- const parts = prop.split('/')
11579
- const pattern = parts.slice(1, -1).join('/')
11580
- const flags = parts[parts.length - 1]
11581
- scuttleGlobalThisExceptions[i] = new RegExp(pattern, flags)
11582
- }
11583
- performScuttleGlobalThis(globalRef, scuttleGlobalThisExceptions)
11569
+ scuttleOpts.scuttlerFunc(globalRef, realm => performScuttleGlobalThis(realm, scuttleOpts.exceptions))
11584
11570
  }
11585
11571
 
11586
11572
  const kernel = {
@@ -11593,6 +11579,43 @@ module.exports = {
11593
11579
  Object.freeze(kernel)
11594
11580
  return kernel
11595
11581
 
11582
+ // generate final scuttling options (1) by taking default
11583
+ // options into consideration, (2) turning RE strings into
11584
+ // actual REs and (3) without mutating original opts object
11585
+ function generateScuttleOpts(originalOpts) {
11586
+ const defaultOpts = {
11587
+ enabled: true,
11588
+ exceptions: [],
11589
+ scuttlerName: '',
11590
+ }
11591
+ const opts = Object.assign({},
11592
+ originalOpts === true ? { ... defaultOpts } : { ...originalOpts },
11593
+ { scuttlerFunc: (globalRef, scuttle) => scuttle(globalRef) },
11594
+ { exceptions: (originalOpts.exceptions || defaultOpts.exceptions).map(e => toRE(e)) },
11595
+ )
11596
+ if (opts.scuttlerName) {
11597
+ if (!globalRef[opts.scuttlerName]) {
11598
+ throw new Error(
11599
+ `LavaMoat - 'scuttlerName' function "${opts.scuttlerName}" expected on globalRef.` +
11600
+ 'To learn more visit https://github.com/LavaMoat/LavaMoat/pull/462.',
11601
+ )
11602
+ }
11603
+ opts.scuttlerFunc = globalRef[opts.scuttlerName]
11604
+ }
11605
+ return opts
11606
+
11607
+ function toRE(except) {
11608
+ // turn scuttleGlobalThis.exceptions regexes strings to actual regexes
11609
+ if (!except.startsWith('/')) {
11610
+ return except
11611
+ }
11612
+ const parts = except.split('/')
11613
+ const pattern = parts.slice(1, -1).join('/')
11614
+ const flags = parts[parts.length - 1]
11615
+ return new RegExp(pattern, flags)
11616
+ }
11617
+ }
11618
+
11596
11619
  function performScuttleGlobalThis (globalRef, extraPropsToAvoid = new Array()) {
11597
11620
  const props = new Array()
11598
11621
  getPrototypeChain(globalRef)
@@ -11995,7 +12018,6 @@ module.exports = {
11995
12018
  globalRef,
11996
12019
  globalThisRefs,
11997
12020
  scuttleGlobalThis,
11998
- scuttleGlobalThisExceptions,
11999
12021
  debugMode,
12000
12022
  runWithPrecompiledModules,
12001
12023
  reportStatsHook,