@metamask/snaps-execution-environments 3.5.0 → 4.0.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.
- package/CHANGELOG.md +20 -1
- package/dist/browserify/iframe/bundle.js +5 -5
- package/dist/browserify/iframe/index.html +202 -111
- package/dist/browserify/node-process/bundle.js +205 -114
- package/dist/browserify/node-thread/bundle.js +205 -114
- package/dist/browserify/webview/bundle.js +9 -0
- package/dist/browserify/{offscreen → webview}/index.html +202 -111
- package/dist/browserify/worker-executor/bundle.js +207 -116
- package/dist/browserify/worker-pool/bundle.js +5 -5
- package/dist/browserify/worker-pool/index.html +202 -111
- package/dist/cjs/common/BaseSnapExecutor.js +2 -2
- package/dist/cjs/common/BaseSnapExecutor.js.map +1 -1
- package/dist/cjs/common/commands.js +9 -0
- package/dist/cjs/common/commands.js.map +1 -1
- package/dist/cjs/common/validation.js +14 -0
- package/dist/cjs/common/validation.js.map +1 -1
- package/dist/cjs/index.js +20 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/proxy/ProxySnapExecutor.js +2 -2
- package/dist/cjs/proxy/ProxySnapExecutor.js.map +1 -1
- package/dist/cjs/proxy/index.js +20 -0
- package/dist/cjs/proxy/index.js.map +1 -0
- package/dist/cjs/webview/WebViewExecutorStream.js +121 -0
- package/dist/cjs/webview/WebViewExecutorStream.js.map +1 -0
- package/dist/cjs/{offscreen → webview}/index.js +4 -4
- package/dist/cjs/webview/index.js.map +1 -0
- package/dist/esm/common/BaseSnapExecutor.js +1 -1
- package/dist/esm/common/BaseSnapExecutor.js.map +1 -1
- package/dist/esm/common/commands.js +10 -1
- package/dist/esm/common/commands.js.map +1 -1
- package/dist/esm/common/validation.js +15 -0
- package/dist/esm/common/validation.js.map +1 -1
- package/dist/esm/index.js +3 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/proxy/ProxySnapExecutor.js +2 -2
- package/dist/esm/proxy/ProxySnapExecutor.js.map +1 -1
- package/dist/esm/proxy/index.js +3 -0
- package/dist/esm/proxy/index.js.map +1 -0
- package/dist/esm/webview/WebViewExecutorStream.js +111 -0
- package/dist/esm/webview/WebViewExecutorStream.js.map +1 -0
- package/dist/esm/{offscreen → webview}/index.js +4 -4
- package/dist/esm/webview/index.js.map +1 -0
- package/dist/types/common/validation.d.ts +31 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/proxy/index.d.ts +1 -0
- package/dist/types/webview/WebViewExecutorStream.d.ts +32 -0
- package/package.json +9 -9
- package/dist/browserify/offscreen/bundle.js +0 -9
- package/dist/cjs/offscreen/index.js.map +0 -1
- package/dist/esm/offscreen/index.js.map +0 -1
- /package/dist/types/{offscreen → webview}/index.d.ts +0 -0
|
@@ -100,7 +100,7 @@
|
|
|
100
100
|
// security options are hard-coded at build time
|
|
101
101
|
const {
|
|
102
102
|
scuttleGlobalThis,
|
|
103
|
-
} = {"scuttleGlobalThis":{"enabled":true,"exceptions":["postMessage","removeEventListener","isSecureContext"]}}
|
|
103
|
+
} = {"scuttleGlobalThis":{"enabled":true,"exceptions":["postMessage","removeEventListener","isSecureContext","ReactNativeWebView","JSON","String"]}}
|
|
104
104
|
|
|
105
105
|
function getGlobalRef () {
|
|
106
106
|
if (typeof globalThis !== 'undefined') {
|
|
@@ -12741,8 +12741,207 @@ module.exports = {
|
|
|
12741
12741
|
})()
|
|
12742
12742
|
return module.exports
|
|
12743
12743
|
})()
|
|
12744
|
+
const { scuttle } = // define scuttle
|
|
12745
|
+
(function(){
|
|
12746
|
+
const global = globalRef
|
|
12747
|
+
const exports = {}
|
|
12748
|
+
const module = { exports }
|
|
12749
|
+
;(function(){
|
|
12750
|
+
// START of injected code from scuttle
|
|
12751
|
+
/**
|
|
12752
|
+
* @typedef {object} ScuttleOpts
|
|
12753
|
+
* @property {boolean} enabled - Whether scuttling is enabled or not.
|
|
12754
|
+
* @property {Array<string|RegExp>} exceptions - List of properties to exclude from scuttling.
|
|
12755
|
+
* @property {string} scuttlerName - Name of the scuttler function to use which is expected to be found as a
|
|
12756
|
+
* property on the global object (e.g. if scuttlerName is 'x', scuttler function is obtained from globalThis['x']).
|
|
12757
|
+
*/
|
|
12758
|
+
|
|
12759
|
+
/**
|
|
12760
|
+
* @typedef {object} GlobalRef
|
|
12761
|
+
* @property {Record<string, any>} [globalThis] - Reference to the global object.
|
|
12762
|
+
*/
|
|
12763
|
+
|
|
12764
|
+
const { Object, Array, Error, RegExp, Set, console, Proxy, Reflect } =
|
|
12765
|
+
globalThis
|
|
12766
|
+
|
|
12767
|
+
const {
|
|
12768
|
+
assign,
|
|
12769
|
+
getOwnPropertyNames,
|
|
12770
|
+
getOwnPropertyDescriptor,
|
|
12771
|
+
create,
|
|
12772
|
+
defineProperty,
|
|
12773
|
+
} = Object
|
|
12774
|
+
|
|
12775
|
+
const { isArray, from } = Array
|
|
12776
|
+
|
|
12777
|
+
const { getPrototypeOf } = Reflect
|
|
12778
|
+
|
|
12779
|
+
const { warn } = console
|
|
12780
|
+
|
|
12781
|
+
function generateInvokers(prop) {
|
|
12782
|
+
return { get, set }
|
|
12783
|
+
function set() {
|
|
12784
|
+
warn(
|
|
12785
|
+
`LavaMoat - property "${prop}" of globalThis cannot be set under scuttling mode. ` +
|
|
12786
|
+
'To learn more visit https://github.com/LavaMoat/LavaMoat/pull/360.'
|
|
12787
|
+
)
|
|
12788
|
+
}
|
|
12789
|
+
function get() {
|
|
12790
|
+
throw new Error(
|
|
12791
|
+
`LavaMoat - property "${prop}" of globalThis is inaccessible under scuttling mode. ` +
|
|
12792
|
+
'To learn more visit https://github.com/LavaMoat/LavaMoat/pull/360.'
|
|
12793
|
+
)
|
|
12794
|
+
}
|
|
12795
|
+
}
|
|
12796
|
+
|
|
12797
|
+
/**
|
|
12798
|
+
* Applies scuttling, with the default set of options, including using Snow if passed in as scuttlerFunc.
|
|
12799
|
+
* Scuttle globalThis right after we used it to create the root package compartment.
|
|
12800
|
+
*
|
|
12801
|
+
* @param {GlobalRef} globalRef - Reference to the global object.
|
|
12802
|
+
* @param {ScuttleOpts} opts - Scuttling options.
|
|
12803
|
+
*/
|
|
12804
|
+
function scuttle(globalRef, opts) {
|
|
12805
|
+
const scuttleOpts = generateScuttleOpts(globalRef, opts)
|
|
12806
|
+
|
|
12807
|
+
if (scuttleOpts.enabled) {
|
|
12808
|
+
if (!isArray(scuttleOpts.exceptions)) {
|
|
12809
|
+
throw new Error(
|
|
12810
|
+
`LavaMoat - exceptions must be an array, got ${typeof scuttleOpts.exceptions}`
|
|
12811
|
+
)
|
|
12812
|
+
}
|
|
12813
|
+
scuttleOpts.scuttlerFunc(globalRef, (realm) =>
|
|
12814
|
+
performScuttleGlobalThis(realm, scuttleOpts.exceptions)
|
|
12815
|
+
)
|
|
12816
|
+
}
|
|
12817
|
+
}
|
|
12818
|
+
|
|
12819
|
+
/**
|
|
12820
|
+
* @param {GlobalRef} globalRef - Reference to the global object.
|
|
12821
|
+
* @param {ScuttleOpts|boolean} originalOpts - Scuttling options. Accepts `true` for backwards compatibility.
|
|
12822
|
+
* @returns {ScuttleOpts} - Final scuttling options.
|
|
12823
|
+
*/
|
|
12824
|
+
function generateScuttleOpts(globalRef, originalOpts = create(null)) {
|
|
12825
|
+
const defaultOpts = {
|
|
12826
|
+
enabled: true,
|
|
12827
|
+
exceptions: [],
|
|
12828
|
+
scuttlerName: '',
|
|
12829
|
+
}
|
|
12830
|
+
const opts = assign(
|
|
12831
|
+
create(null),
|
|
12832
|
+
originalOpts === true ? defaultOpts : originalOpts,
|
|
12833
|
+
{
|
|
12834
|
+
scuttlerFunc: (globalRef, scuttle) => scuttle(globalRef),
|
|
12835
|
+
},
|
|
12836
|
+
{
|
|
12837
|
+
exceptions: (originalOpts?.exceptions || defaultOpts.exceptions).map(
|
|
12838
|
+
(e) => toRE(e)
|
|
12839
|
+
),
|
|
12840
|
+
}
|
|
12841
|
+
)
|
|
12842
|
+
if (opts.scuttlerName) {
|
|
12843
|
+
if (!globalRef[opts.scuttlerName]) {
|
|
12844
|
+
throw new Error(
|
|
12845
|
+
`LavaMoat - 'scuttlerName' function "${opts.scuttlerName}" expected on globalRef.` +
|
|
12846
|
+
'To learn more visit https://github.com/LavaMoat/LavaMoat/pull/462.'
|
|
12847
|
+
)
|
|
12848
|
+
}
|
|
12849
|
+
opts.scuttlerFunc = globalRef[opts.scuttlerName]
|
|
12850
|
+
}
|
|
12851
|
+
return opts
|
|
12852
|
+
|
|
12853
|
+
/**
|
|
12854
|
+
* @param {string|RegExp} except - Exception to convert to RegExp.
|
|
12855
|
+
* @returns {string|RegExp} - Converted exception.
|
|
12856
|
+
*/
|
|
12857
|
+
function toRE(except) {
|
|
12858
|
+
// turn scuttleGlobalThis.exceptions regexes strings to actual regexes
|
|
12859
|
+
if (!except.startsWith('/')) {
|
|
12860
|
+
return except
|
|
12861
|
+
}
|
|
12862
|
+
const parts = except.split('/')
|
|
12863
|
+
const pattern = parts.slice(1, -1).join('/')
|
|
12864
|
+
const flags = parts[parts.length - 1]
|
|
12865
|
+
return new RegExp(pattern, flags)
|
|
12866
|
+
}
|
|
12867
|
+
}
|
|
12868
|
+
|
|
12869
|
+
/**
|
|
12870
|
+
* Runs scuttling on the globalRef. Use applyDefaultScuttling for full scope of options.
|
|
12871
|
+
*
|
|
12872
|
+
* @param {GlobalRef} globalRef - Reference to the global object.
|
|
12873
|
+
* @param {Array<string|RegExp>} extraPropsToAvoid - List of additional properties to exclude from scuttling beyond the default ones.
|
|
12874
|
+
*/
|
|
12875
|
+
function performScuttleGlobalThis(globalRef, extraPropsToAvoid = []) {
|
|
12876
|
+
const props = []
|
|
12877
|
+
getPrototypeChain(globalRef).forEach((proto) =>
|
|
12878
|
+
props.push(...getOwnPropertyNames(proto))
|
|
12879
|
+
)
|
|
12880
|
+
|
|
12881
|
+
// support LM,SES exported APIs and polyfills
|
|
12882
|
+
const avoidForLavaMoatCompatibility = ['Compartment', 'Error', 'globalThis']
|
|
12883
|
+
const propsToAvoid = new Set([
|
|
12884
|
+
...avoidForLavaMoatCompatibility,
|
|
12885
|
+
...extraPropsToAvoid,
|
|
12886
|
+
])
|
|
12887
|
+
|
|
12888
|
+
const obj = create(null)
|
|
12889
|
+
props.forEach((prop) => {
|
|
12890
|
+
const { get, set } = generateInvokers(prop)
|
|
12891
|
+
if (shouldAvoidProp(propsToAvoid, prop)) {
|
|
12892
|
+
return
|
|
12893
|
+
}
|
|
12894
|
+
let desc = getOwnPropertyDescriptor(globalRef, prop)
|
|
12895
|
+
if (desc?.configurable === true) {
|
|
12896
|
+
desc = { configurable: false, set, get }
|
|
12897
|
+
} else if (desc?.writable === true) {
|
|
12898
|
+
const p = new Proxy(obj, { getPrototypeOf: get, get, set })
|
|
12899
|
+
desc = { configurable: false, writable: false, value: p }
|
|
12900
|
+
} else {
|
|
12901
|
+
return
|
|
12902
|
+
}
|
|
12903
|
+
defineProperty(globalRef, prop, desc)
|
|
12904
|
+
})
|
|
12905
|
+
}
|
|
12906
|
+
|
|
12907
|
+
/**
|
|
12908
|
+
* @param {Set<string|RegExp>} propsToAvoid - List of properties to exclude from scuttling.
|
|
12909
|
+
* @param {string} prop - Property to check.
|
|
12910
|
+
* @returns {boolean} - Whether the property should be avoided or not.
|
|
12911
|
+
*/
|
|
12912
|
+
const shouldAvoidProp = (propsToAvoid, prop) =>
|
|
12913
|
+
from(propsToAvoid).some(
|
|
12914
|
+
(avoid) =>
|
|
12915
|
+
(typeof avoid === 'string' && avoid === prop) ||
|
|
12916
|
+
(avoid instanceof RegExp && avoid.test(prop))
|
|
12917
|
+
)
|
|
12918
|
+
|
|
12919
|
+
/**
|
|
12920
|
+
* @param {object} value - object to get the prototype chain from.
|
|
12921
|
+
* @returns {Array<object>} - Prototype chain as an array.
|
|
12922
|
+
*/
|
|
12923
|
+
function getPrototypeChain(value) {
|
|
12924
|
+
const protoChain = []
|
|
12925
|
+
let current = value
|
|
12926
|
+
while (current) {
|
|
12927
|
+
if (typeof current !== 'object' && typeof current !== 'function') {
|
|
12928
|
+
break
|
|
12929
|
+
}
|
|
12930
|
+
protoChain.push(current)
|
|
12931
|
+
current = getPrototypeOf(current)
|
|
12932
|
+
}
|
|
12933
|
+
return protoChain
|
|
12934
|
+
}
|
|
12935
|
+
|
|
12936
|
+
module.exports = {
|
|
12937
|
+
scuttle,
|
|
12938
|
+
}
|
|
12939
|
+
|
|
12940
|
+
// END of injected code from scuttle
|
|
12941
|
+
})()
|
|
12942
|
+
return module.exports
|
|
12943
|
+
})()
|
|
12744
12944
|
|
|
12745
|
-
const scuttleOpts = generateScuttleOpts(scuttleGlobalThis)
|
|
12746
12945
|
const moduleCache = new Map()
|
|
12747
12946
|
const packageCompartmentCache = new Map()
|
|
12748
12947
|
const globalStore = new Map()
|
|
@@ -12750,13 +12949,7 @@ module.exports = {
|
|
|
12750
12949
|
const rootPackageName = '$root$'
|
|
12751
12950
|
const rootPackageCompartment = createRootPackageCompartment(globalRef)
|
|
12752
12951
|
|
|
12753
|
-
|
|
12754
|
-
if (scuttleOpts.enabled) {
|
|
12755
|
-
if (!Array.isArray(scuttleOpts.exceptions)) {
|
|
12756
|
-
throw new Error(`LavaMoat - scuttleGlobalThis.exceptions must be an array, got "${typeof scuttleOpts.exceptions}"`)
|
|
12757
|
-
}
|
|
12758
|
-
scuttleOpts.scuttlerFunc(globalRef, realm => performScuttleGlobalThis(realm, scuttleOpts.exceptions))
|
|
12759
|
-
}
|
|
12952
|
+
scuttle(globalRef, scuttleGlobalThis)
|
|
12760
12953
|
|
|
12761
12954
|
const kernel = {
|
|
12762
12955
|
internalRequire,
|
|
@@ -12768,85 +12961,6 @@ module.exports = {
|
|
|
12768
12961
|
Object.freeze(kernel)
|
|
12769
12962
|
return kernel
|
|
12770
12963
|
|
|
12771
|
-
// generate final scuttling options (1) by taking default
|
|
12772
|
-
// options into consideration, (2) turning RE strings into
|
|
12773
|
-
// actual REs and (3) without mutating original opts object
|
|
12774
|
-
function generateScuttleOpts(originalOpts) {
|
|
12775
|
-
const defaultOpts = {
|
|
12776
|
-
enabled: true,
|
|
12777
|
-
exceptions: [],
|
|
12778
|
-
scuttlerName: '',
|
|
12779
|
-
}
|
|
12780
|
-
const opts = Object.assign({},
|
|
12781
|
-
originalOpts === true ? { ... defaultOpts } : { ...originalOpts },
|
|
12782
|
-
{ scuttlerFunc: (globalRef, scuttle) => scuttle(globalRef) },
|
|
12783
|
-
{ exceptions: (originalOpts.exceptions || defaultOpts.exceptions).map(e => toRE(e)) },
|
|
12784
|
-
)
|
|
12785
|
-
if (opts.scuttlerName) {
|
|
12786
|
-
if (!globalRef[opts.scuttlerName]) {
|
|
12787
|
-
throw new Error(
|
|
12788
|
-
`LavaMoat - 'scuttlerName' function "${opts.scuttlerName}" expected on globalRef.` +
|
|
12789
|
-
'To learn more visit https://github.com/LavaMoat/LavaMoat/pull/462.',
|
|
12790
|
-
)
|
|
12791
|
-
}
|
|
12792
|
-
opts.scuttlerFunc = globalRef[opts.scuttlerName]
|
|
12793
|
-
}
|
|
12794
|
-
return opts
|
|
12795
|
-
|
|
12796
|
-
function toRE(except) {
|
|
12797
|
-
// turn scuttleGlobalThis.exceptions regexes strings to actual regexes
|
|
12798
|
-
if (!except.startsWith('/')) {
|
|
12799
|
-
return except
|
|
12800
|
-
}
|
|
12801
|
-
const parts = except.split('/')
|
|
12802
|
-
const pattern = parts.slice(1, -1).join('/')
|
|
12803
|
-
const flags = parts[parts.length - 1]
|
|
12804
|
-
return new RegExp(pattern, flags)
|
|
12805
|
-
}
|
|
12806
|
-
}
|
|
12807
|
-
|
|
12808
|
-
function performScuttleGlobalThis (globalRef, extraPropsToAvoid = []) {
|
|
12809
|
-
const props = []
|
|
12810
|
-
getPrototypeChain(globalRef)
|
|
12811
|
-
.forEach(proto =>
|
|
12812
|
-
props.push(...Object.getOwnPropertyNames(proto)))
|
|
12813
|
-
|
|
12814
|
-
// support LM,SES exported APIs and polyfills
|
|
12815
|
-
const avoidForLavaMoatCompatibility = ['Compartment', 'Error', 'globalThis']
|
|
12816
|
-
const propsToAvoid = new Set([...avoidForLavaMoatCompatibility, ...extraPropsToAvoid])
|
|
12817
|
-
|
|
12818
|
-
const obj = Object.create(null)
|
|
12819
|
-
for (const prop of props) {
|
|
12820
|
-
// eslint-disable-next-line no-inner-declarations
|
|
12821
|
-
function set() {
|
|
12822
|
-
console.warn(
|
|
12823
|
-
`LavaMoat - property "${prop}" of globalThis cannot be set under scuttling mode. ` +
|
|
12824
|
-
'To learn more visit https://github.com/LavaMoat/LavaMoat/pull/360.',
|
|
12825
|
-
)
|
|
12826
|
-
}
|
|
12827
|
-
// eslint-disable-next-line no-inner-declarations
|
|
12828
|
-
function get() {
|
|
12829
|
-
throw new Error(
|
|
12830
|
-
`LavaMoat - property "${prop}" of globalThis is inaccessible under scuttling mode. ` +
|
|
12831
|
-
'To learn more visit https://github.com/LavaMoat/LavaMoat/pull/360.',
|
|
12832
|
-
)
|
|
12833
|
-
}
|
|
12834
|
-
if (shouldAvoidProp(propsToAvoid, prop)) {
|
|
12835
|
-
continue
|
|
12836
|
-
}
|
|
12837
|
-
let desc = Object.getOwnPropertyDescriptor(globalRef, prop)
|
|
12838
|
-
if (desc?.configurable === true) {
|
|
12839
|
-
desc = { configurable: false, set, get }
|
|
12840
|
-
} else if (desc?.writable === true) {
|
|
12841
|
-
const p = new Proxy(obj, { getPrototypeOf: get, get, set } )
|
|
12842
|
-
desc = { configurable: false, writable: false, value: p }
|
|
12843
|
-
} else {
|
|
12844
|
-
continue
|
|
12845
|
-
}
|
|
12846
|
-
Object.defineProperty(globalRef, prop, desc)
|
|
12847
|
-
}
|
|
12848
|
-
}
|
|
12849
|
-
|
|
12850
12964
|
// this function instantiaties a module from a moduleId.
|
|
12851
12965
|
// 1. loads the module metadata and policy
|
|
12852
12966
|
// 2. prepares the execution environment
|
|
@@ -13131,29 +13245,6 @@ module.exports = {
|
|
|
13131
13245
|
return packageConfig
|
|
13132
13246
|
}
|
|
13133
13247
|
|
|
13134
|
-
// util for getting the prototype chain as an array
|
|
13135
|
-
// includes the provided value in the result
|
|
13136
|
-
function getPrototypeChain (value) {
|
|
13137
|
-
const protoChain = []
|
|
13138
|
-
let current = value
|
|
13139
|
-
while (current && (typeof current === 'object' || typeof current === 'function')) {
|
|
13140
|
-
protoChain.push(current)
|
|
13141
|
-
current = Reflect.getPrototypeOf(current)
|
|
13142
|
-
}
|
|
13143
|
-
return protoChain
|
|
13144
|
-
}
|
|
13145
|
-
|
|
13146
|
-
function shouldAvoidProp(propsToAvoid, prop) {
|
|
13147
|
-
for (const avoid of propsToAvoid) {
|
|
13148
|
-
if (avoid instanceof RegExp && avoid.test(prop)) {
|
|
13149
|
-
return true
|
|
13150
|
-
}
|
|
13151
|
-
if (propsToAvoid.has(prop)) {
|
|
13152
|
-
return true
|
|
13153
|
-
}
|
|
13154
|
-
}
|
|
13155
|
-
return false
|
|
13156
|
-
}
|
|
13157
13248
|
}
|
|
13158
13249
|
})()
|
|
13159
13250
|
|