ses 0.15.12 → 0.15.13
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 +10 -0
- package/dist/lockdown.cjs +45 -47
- package/dist/lockdown.mjs +45 -47
- package/dist/lockdown.umd.js +45 -47
- package/dist/lockdown.umd.min.js +1 -1
- package/dist/ses.cjs +45 -47
- package/dist/ses.mjs +45 -47
- package/dist/ses.umd.js +45 -47
- package/dist/ses.umd.min.js +1 -1
- package/package.json +6 -6
- package/src/compartment-evaluate.js +1 -1
- package/src/compartment-shim.js +1 -1
- package/src/make-safe-evaluator.js +17 -17
- package/src/scope-handler.js +26 -28
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,16 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
### [0.15.13](https://github.com/endojs/endo/compare/ses@0.15.12...ses@0.15.13) (2022-04-13)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* Revert dud release ([c8a7101](https://github.com/endojs/endo/commit/c8a71017d8d7af10a97909c9da9c5c7e59aed939))
|
|
12
|
+
* **ses:** Prevent hypothetical stack bumping to get unsafe eval ([3c64cde](https://github.com/endojs/endo/commit/3c64cdea5b410a053520dc29de04c43350a38e1a)), closes [#956](https://github.com/endojs/endo/issues/956)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
6
16
|
### [0.15.12](https://github.com/endojs/endo/compare/ses@0.15.11...ses@0.15.12) (2022-04-12)
|
|
7
17
|
|
|
8
18
|
|
package/dist/lockdown.cjs
CHANGED
|
@@ -1603,7 +1603,8 @@ const getScopeConstants= (globalObject, localObject= {})=> {
|
|
|
1603
1603
|
})
|
|
1604
1604
|
,
|
|
1605
1605
|
// === functors[7] ===
|
|
1606
|
-
(({ imports: $h_imports, liveVar: $h_live, onceVar: $h_once, }) => { let FERAL_EVAL,Proxy,String,TypeError,create,freeze,getOwnPropertyDescriptor,getOwnPropertyDescriptors,globalThis,immutableObject,objectHasOwnProperty,reflectGet,reflectSet,assert;$h_imports([["./commons.js", [["FERAL_EVAL", [$h_a => (FERAL_EVAL = $h_a)]],["Proxy", [$h_a => (Proxy = $h_a)]],["String", [$h_a => (String = $h_a)]],["TypeError", [$h_a => (TypeError = $h_a)]],["create", [$h_a => (create = $h_a)]],["freeze", [$h_a => (freeze = $h_a)]],["getOwnPropertyDescriptor", [$h_a => (getOwnPropertyDescriptor = $h_a)]],["getOwnPropertyDescriptors", [$h_a => (getOwnPropertyDescriptors = $h_a)]],["globalThis", [$h_a => (globalThis = $h_a)]],["immutableObject", [$h_a => (immutableObject = $h_a)]],["objectHasOwnProperty", [$h_a => (objectHasOwnProperty = $h_a)]],["reflectGet", [$h_a => (reflectGet = $h_a)]],["reflectSet", [$h_a => (reflectSet = $h_a)]]]],["./error/assert.js", [["assert", [$h_a => (assert = $h_a)]]]]]);
|
|
1606
|
+
(({ imports: $h_imports, liveVar: $h_live, onceVar: $h_once, }) => { let FERAL_EVAL,Proxy,String,TypeError,create,freeze,getOwnPropertyDescriptor,getOwnPropertyDescriptors,globalThis,immutableObject,objectHasOwnProperty,reflectGet,reflectSet,seal,assert;$h_imports([["./commons.js", [["FERAL_EVAL", [$h_a => (FERAL_EVAL = $h_a)]],["Proxy", [$h_a => (Proxy = $h_a)]],["String", [$h_a => (String = $h_a)]],["TypeError", [$h_a => (TypeError = $h_a)]],["create", [$h_a => (create = $h_a)]],["freeze", [$h_a => (freeze = $h_a)]],["getOwnPropertyDescriptor", [$h_a => (getOwnPropertyDescriptor = $h_a)]],["getOwnPropertyDescriptors", [$h_a => (getOwnPropertyDescriptors = $h_a)]],["globalThis", [$h_a => (globalThis = $h_a)]],["immutableObject", [$h_a => (immutableObject = $h_a)]],["objectHasOwnProperty", [$h_a => (objectHasOwnProperty = $h_a)]],["reflectGet", [$h_a => (reflectGet = $h_a)]],["reflectSet", [$h_a => (reflectSet = $h_a)]],["seal", [$h_a => (seal = $h_a)]]]],["./error/assert.js", [["assert", [$h_a => (assert = $h_a)]]]]]);
|
|
1607
|
+
|
|
1607
1608
|
|
|
1608
1609
|
|
|
1609
1610
|
|
|
@@ -1658,23 +1659,21 @@ const alwaysThrowHandler= new Proxy(
|
|
|
1658
1659
|
*/
|
|
1659
1660
|
const createScopeHandler= (
|
|
1660
1661
|
globalObject,
|
|
1661
|
-
|
|
1662
|
+
globalLexicals= {},
|
|
1662
1663
|
{ sloppyGlobalsMode= false}= {})=>
|
|
1663
1664
|
{
|
|
1664
1665
|
// This flag allow us to determine if the eval() call is an done by the
|
|
1665
1666
|
// compartment's code or if it is user-land invocation, so we can react
|
|
1666
1667
|
// differently.
|
|
1667
|
-
|
|
1668
|
+
// Using a flag on an object with a single mutable property allows a safe
|
|
1669
|
+
// evaluator to signal to the scope proxy without consuming a stack frame.
|
|
1670
|
+
// Consuming a stack frame could possibly allow an attacker to control the
|
|
1671
|
+
// stack depth before calling `evaluate` to cause a RangeError before this
|
|
1672
|
+
// flag can be reset, leaving the unsafe evaluator available.
|
|
1673
|
+
const scopeController= {
|
|
1674
|
+
allowNextEvalToBeUnsafe: false};
|
|
1668
1675
|
|
|
1669
|
-
|
|
1670
|
-
allowNextEvalToBeUnsafe= true;
|
|
1671
|
-
};
|
|
1672
|
-
|
|
1673
|
-
const resetOneUnsafeEvalNext= ()=> {
|
|
1674
|
-
const wasSet= allowNextEvalToBeUnsafe;
|
|
1675
|
-
allowNextEvalToBeUnsafe= false;
|
|
1676
|
-
return wasSet;
|
|
1677
|
-
};
|
|
1676
|
+
seal(scopeController);
|
|
1678
1677
|
|
|
1679
1678
|
const scopeProxyHandlerProperties= {
|
|
1680
1679
|
get(_shadow, prop) {
|
|
@@ -1687,20 +1686,20 @@ const createScopeHandler= (
|
|
|
1687
1686
|
// the 'with' context.
|
|
1688
1687
|
if( prop=== 'eval') {
|
|
1689
1688
|
// test that it is true rather than merely truthy
|
|
1690
|
-
if( allowNextEvalToBeUnsafe=== true) {
|
|
1689
|
+
if( scopeController.allowNextEvalToBeUnsafe=== true) {
|
|
1691
1690
|
// revoke before use
|
|
1692
|
-
allowNextEvalToBeUnsafe= false;
|
|
1691
|
+
scopeController.allowNextEvalToBeUnsafe= false;
|
|
1693
1692
|
return FERAL_EVAL;
|
|
1694
1693
|
}
|
|
1695
1694
|
// fall through
|
|
1696
1695
|
}
|
|
1697
1696
|
|
|
1698
|
-
// Properties of the
|
|
1699
|
-
if( prop in
|
|
1697
|
+
// Properties of the globalLexicals.
|
|
1698
|
+
if( prop in globalLexicals) {
|
|
1700
1699
|
// Use reflect to defeat accessors that could be present on the
|
|
1701
|
-
//
|
|
1700
|
+
// globalLexicals object itself as `this`.
|
|
1702
1701
|
// This is done out of an overabundance of caution, as the SES shim
|
|
1703
|
-
// only use the
|
|
1702
|
+
// only use the globalLexicals carry globalLexicals and live binding
|
|
1704
1703
|
// traps.
|
|
1705
1704
|
// The globalLexicals are captured as a snapshot of what's passed to
|
|
1706
1705
|
// the Compartment constructor, wherein all accessors and setters are
|
|
@@ -1709,7 +1708,7 @@ const createScopeHandler= (
|
|
|
1709
1708
|
// make use of their receiver.
|
|
1710
1709
|
// Live binding traps provide no avenue for user code to observe the
|
|
1711
1710
|
// receiver.
|
|
1712
|
-
return reflectGet(
|
|
1711
|
+
return reflectGet(globalLexicals, prop, globalObject);
|
|
1713
1712
|
}
|
|
1714
1713
|
|
|
1715
1714
|
// Properties of the global.
|
|
@@ -1717,17 +1716,17 @@ const createScopeHandler= (
|
|
|
1717
1716
|
},
|
|
1718
1717
|
|
|
1719
1718
|
set(_shadow, prop, value) {
|
|
1720
|
-
// Properties of the
|
|
1721
|
-
if( prop in
|
|
1722
|
-
const desc= getOwnPropertyDescriptor(
|
|
1719
|
+
// Properties of the globalLexicals.
|
|
1720
|
+
if( prop in globalLexicals) {
|
|
1721
|
+
const desc= getOwnPropertyDescriptor(globalLexicals, prop);
|
|
1723
1722
|
if( objectHasOwnProperty(desc, 'value')) {
|
|
1724
1723
|
// Work around a peculiar behavior in the specs, where
|
|
1725
1724
|
// value properties are defined on the receiver.
|
|
1726
|
-
return reflectSet(
|
|
1725
|
+
return reflectSet(globalLexicals, prop, value);
|
|
1727
1726
|
}
|
|
1728
1727
|
// Ensure that the 'this' value on setters resolves
|
|
1729
|
-
// to the safeGlobal, not to the
|
|
1730
|
-
return reflectSet(
|
|
1728
|
+
// to the safeGlobal, not to the globalLexicals object.
|
|
1729
|
+
return reflectSet(globalLexicals, prop, value, globalObject);
|
|
1731
1730
|
}
|
|
1732
1731
|
|
|
1733
1732
|
// Properties of the global.
|
|
@@ -1770,8 +1769,8 @@ const createScopeHandler= (
|
|
|
1770
1769
|
// !!!!! WARNING: DANGER ZONE !!!!!!
|
|
1771
1770
|
return(
|
|
1772
1771
|
sloppyGlobalsMode||
|
|
1773
|
-
allowNextEvalToBeUnsafe&& prop=== 'eval'||
|
|
1774
|
-
prop in
|
|
1772
|
+
scopeController.allowNextEvalToBeUnsafe&& prop=== 'eval'||
|
|
1773
|
+
prop in globalLexicals||
|
|
1775
1774
|
prop in globalObject||
|
|
1776
1775
|
prop in globalThis);
|
|
1777
1776
|
|
|
@@ -1811,8 +1810,7 @@ const createScopeHandler= (
|
|
|
1811
1810
|
|
|
1812
1811
|
|
|
1813
1812
|
return {
|
|
1814
|
-
|
|
1815
|
-
resetOneUnsafeEvalNext,
|
|
1813
|
+
scopeController,
|
|
1816
1814
|
scopeHandler};
|
|
1817
1815
|
|
|
1818
1816
|
};$h_once.createScopeHandler(createScopeHandler);
|
|
@@ -2141,8 +2139,6 @@ const applyTransforms= (source, transforms)=> {
|
|
|
2141
2139
|
|
|
2142
2140
|
const { details: d}= assert;
|
|
2143
2141
|
|
|
2144
|
-
// TODO: rename localObject to scopeObject
|
|
2145
|
-
|
|
2146
2142
|
/**
|
|
2147
2143
|
* makeSafeEvaluator()
|
|
2148
2144
|
* Build the low-level operation used by all evaluators:
|
|
@@ -2150,24 +2146,24 @@ const { details: d}= assert;
|
|
|
2150
2146
|
*
|
|
2151
2147
|
* @param {Object} options
|
|
2152
2148
|
* @param {Object} options.globalObject
|
|
2153
|
-
* @param {Object} [options.
|
|
2149
|
+
* @param {Object} [options.globalLexicals]
|
|
2154
2150
|
* @param {Array<Transform>} [options.globalTransforms]
|
|
2155
2151
|
* @param {bool} [options.sloppyGlobalsMode]
|
|
2156
2152
|
* @param {WeakSet} [options.knownScopeProxies]
|
|
2157
2153
|
*/
|
|
2158
2154
|
const makeSafeEvaluator= ({
|
|
2159
2155
|
globalObject,
|
|
2160
|
-
|
|
2156
|
+
globalLexicals= {},
|
|
2161
2157
|
globalTransforms= [],
|
|
2162
2158
|
sloppyGlobalsMode= false,
|
|
2163
2159
|
knownScopeProxies= new WeakSet()}=
|
|
2164
2160
|
{})=> {
|
|
2165
|
-
const {
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2161
|
+
const { scopeHandler, scopeController}= createScopeHandler(
|
|
2162
|
+
globalObject,
|
|
2163
|
+
globalLexicals,
|
|
2164
|
+
{
|
|
2165
|
+
sloppyGlobalsMode});
|
|
2166
|
+
|
|
2171
2167
|
|
|
2172
2168
|
const { proxy: scopeProxy, revoke: revokeScopeProxy}= proxyRevocable(
|
|
2173
2169
|
immutableObject,
|
|
@@ -2181,7 +2177,7 @@ const makeSafeEvaluator= ({
|
|
|
2181
2177
|
let evaluate;
|
|
2182
2178
|
const makeEvaluate= ()=> {
|
|
2183
2179
|
if( !evaluate) {
|
|
2184
|
-
const constants= getScopeConstants(globalObject,
|
|
2180
|
+
const constants= getScopeConstants(globalObject, globalLexicals);
|
|
2185
2181
|
const evaluateFactory= makeEvaluateFactory(constants);
|
|
2186
2182
|
evaluate= apply(evaluateFactory, scopeProxy, []);
|
|
2187
2183
|
}
|
|
@@ -2203,7 +2199,7 @@ const makeSafeEvaluator= ({
|
|
|
2203
2199
|
mandatoryTransforms]);
|
|
2204
2200
|
|
|
2205
2201
|
|
|
2206
|
-
|
|
2202
|
+
scopeController.allowNextEvalToBeUnsafe= true;
|
|
2207
2203
|
let err;
|
|
2208
2204
|
try {
|
|
2209
2205
|
// Ensure that "this" resolves to the safe global.
|
|
@@ -2213,13 +2209,15 @@ const makeSafeEvaluator= ({
|
|
|
2213
2209
|
err= e;
|
|
2214
2210
|
throw e;
|
|
2215
2211
|
}finally {
|
|
2216
|
-
|
|
2212
|
+
const unsafeEvalWasStillExposed= scopeController.allowNextEvalToBeUnsafe;
|
|
2213
|
+
scopeController.allowNextEvalToBeUnsafe= false;
|
|
2214
|
+
if( unsafeEvalWasStillExposed) {
|
|
2217
2215
|
// Barring a defect in the SES shim, the scope proxy should allow the
|
|
2218
2216
|
// powerful, unsafe `eval` to be used by `evaluate` exactly once, as the
|
|
2219
2217
|
// very first name that it attempts to access from the lexical scope.
|
|
2220
|
-
// A defect in the SES shim could throw an exception after
|
|
2221
|
-
// `
|
|
2222
|
-
// internally.
|
|
2218
|
+
// A defect in the SES shim could throw an exception after we set
|
|
2219
|
+
// `scopeController.allowNextEvalToBeUnsafe` and before `evaluate`
|
|
2220
|
+
// calls `eval` internally.
|
|
2223
2221
|
// If we get here, SES is very broken.
|
|
2224
2222
|
// This condition is one where this vat is now hopelessly confused, and
|
|
2225
2223
|
// the vat as a whole should be aborted.
|
|
@@ -2300,7 +2298,7 @@ const provideCompartmentEvaluator= (compartmentFields, options)=> {
|
|
|
2300
2298
|
|
|
2301
2299
|
({ safeEvaluate}= makeSafeEvaluator({
|
|
2302
2300
|
globalObject,
|
|
2303
|
-
localObject,
|
|
2301
|
+
globalLexicals: localObject,
|
|
2304
2302
|
globalTransforms,
|
|
2305
2303
|
sloppyGlobalsMode,
|
|
2306
2304
|
knownScopeProxies}));
|
|
@@ -5417,7 +5415,7 @@ const makeCompartmentConstructor= (
|
|
|
5417
5415
|
const knownScopeProxies= new WeakSet();
|
|
5418
5416
|
const { safeEvaluate}= makeSafeEvaluator({
|
|
5419
5417
|
globalObject,
|
|
5420
|
-
|
|
5418
|
+
globalLexicals,
|
|
5421
5419
|
globalTransforms,
|
|
5422
5420
|
sloppyGlobalsMode: false,
|
|
5423
5421
|
knownScopeProxies});
|
package/dist/lockdown.mjs
CHANGED
|
@@ -1603,7 +1603,8 @@ const getScopeConstants= (globalObject, localObject= {})=> {
|
|
|
1603
1603
|
})
|
|
1604
1604
|
,
|
|
1605
1605
|
// === functors[7] ===
|
|
1606
|
-
(({ imports: $h_imports, liveVar: $h_live, onceVar: $h_once, }) => { let FERAL_EVAL,Proxy,String,TypeError,create,freeze,getOwnPropertyDescriptor,getOwnPropertyDescriptors,globalThis,immutableObject,objectHasOwnProperty,reflectGet,reflectSet,assert;$h_imports([["./commons.js", [["FERAL_EVAL", [$h_a => (FERAL_EVAL = $h_a)]],["Proxy", [$h_a => (Proxy = $h_a)]],["String", [$h_a => (String = $h_a)]],["TypeError", [$h_a => (TypeError = $h_a)]],["create", [$h_a => (create = $h_a)]],["freeze", [$h_a => (freeze = $h_a)]],["getOwnPropertyDescriptor", [$h_a => (getOwnPropertyDescriptor = $h_a)]],["getOwnPropertyDescriptors", [$h_a => (getOwnPropertyDescriptors = $h_a)]],["globalThis", [$h_a => (globalThis = $h_a)]],["immutableObject", [$h_a => (immutableObject = $h_a)]],["objectHasOwnProperty", [$h_a => (objectHasOwnProperty = $h_a)]],["reflectGet", [$h_a => (reflectGet = $h_a)]],["reflectSet", [$h_a => (reflectSet = $h_a)]]]],["./error/assert.js", [["assert", [$h_a => (assert = $h_a)]]]]]);
|
|
1606
|
+
(({ imports: $h_imports, liveVar: $h_live, onceVar: $h_once, }) => { let FERAL_EVAL,Proxy,String,TypeError,create,freeze,getOwnPropertyDescriptor,getOwnPropertyDescriptors,globalThis,immutableObject,objectHasOwnProperty,reflectGet,reflectSet,seal,assert;$h_imports([["./commons.js", [["FERAL_EVAL", [$h_a => (FERAL_EVAL = $h_a)]],["Proxy", [$h_a => (Proxy = $h_a)]],["String", [$h_a => (String = $h_a)]],["TypeError", [$h_a => (TypeError = $h_a)]],["create", [$h_a => (create = $h_a)]],["freeze", [$h_a => (freeze = $h_a)]],["getOwnPropertyDescriptor", [$h_a => (getOwnPropertyDescriptor = $h_a)]],["getOwnPropertyDescriptors", [$h_a => (getOwnPropertyDescriptors = $h_a)]],["globalThis", [$h_a => (globalThis = $h_a)]],["immutableObject", [$h_a => (immutableObject = $h_a)]],["objectHasOwnProperty", [$h_a => (objectHasOwnProperty = $h_a)]],["reflectGet", [$h_a => (reflectGet = $h_a)]],["reflectSet", [$h_a => (reflectSet = $h_a)]],["seal", [$h_a => (seal = $h_a)]]]],["./error/assert.js", [["assert", [$h_a => (assert = $h_a)]]]]]);
|
|
1607
|
+
|
|
1607
1608
|
|
|
1608
1609
|
|
|
1609
1610
|
|
|
@@ -1658,23 +1659,21 @@ const alwaysThrowHandler= new Proxy(
|
|
|
1658
1659
|
*/
|
|
1659
1660
|
const createScopeHandler= (
|
|
1660
1661
|
globalObject,
|
|
1661
|
-
|
|
1662
|
+
globalLexicals= {},
|
|
1662
1663
|
{ sloppyGlobalsMode= false}= {})=>
|
|
1663
1664
|
{
|
|
1664
1665
|
// This flag allow us to determine if the eval() call is an done by the
|
|
1665
1666
|
// compartment's code or if it is user-land invocation, so we can react
|
|
1666
1667
|
// differently.
|
|
1667
|
-
|
|
1668
|
+
// Using a flag on an object with a single mutable property allows a safe
|
|
1669
|
+
// evaluator to signal to the scope proxy without consuming a stack frame.
|
|
1670
|
+
// Consuming a stack frame could possibly allow an attacker to control the
|
|
1671
|
+
// stack depth before calling `evaluate` to cause a RangeError before this
|
|
1672
|
+
// flag can be reset, leaving the unsafe evaluator available.
|
|
1673
|
+
const scopeController= {
|
|
1674
|
+
allowNextEvalToBeUnsafe: false};
|
|
1668
1675
|
|
|
1669
|
-
|
|
1670
|
-
allowNextEvalToBeUnsafe= true;
|
|
1671
|
-
};
|
|
1672
|
-
|
|
1673
|
-
const resetOneUnsafeEvalNext= ()=> {
|
|
1674
|
-
const wasSet= allowNextEvalToBeUnsafe;
|
|
1675
|
-
allowNextEvalToBeUnsafe= false;
|
|
1676
|
-
return wasSet;
|
|
1677
|
-
};
|
|
1676
|
+
seal(scopeController);
|
|
1678
1677
|
|
|
1679
1678
|
const scopeProxyHandlerProperties= {
|
|
1680
1679
|
get(_shadow, prop) {
|
|
@@ -1687,20 +1686,20 @@ const createScopeHandler= (
|
|
|
1687
1686
|
// the 'with' context.
|
|
1688
1687
|
if( prop=== 'eval') {
|
|
1689
1688
|
// test that it is true rather than merely truthy
|
|
1690
|
-
if( allowNextEvalToBeUnsafe=== true) {
|
|
1689
|
+
if( scopeController.allowNextEvalToBeUnsafe=== true) {
|
|
1691
1690
|
// revoke before use
|
|
1692
|
-
allowNextEvalToBeUnsafe= false;
|
|
1691
|
+
scopeController.allowNextEvalToBeUnsafe= false;
|
|
1693
1692
|
return FERAL_EVAL;
|
|
1694
1693
|
}
|
|
1695
1694
|
// fall through
|
|
1696
1695
|
}
|
|
1697
1696
|
|
|
1698
|
-
// Properties of the
|
|
1699
|
-
if( prop in
|
|
1697
|
+
// Properties of the globalLexicals.
|
|
1698
|
+
if( prop in globalLexicals) {
|
|
1700
1699
|
// Use reflect to defeat accessors that could be present on the
|
|
1701
|
-
//
|
|
1700
|
+
// globalLexicals object itself as `this`.
|
|
1702
1701
|
// This is done out of an overabundance of caution, as the SES shim
|
|
1703
|
-
// only use the
|
|
1702
|
+
// only use the globalLexicals carry globalLexicals and live binding
|
|
1704
1703
|
// traps.
|
|
1705
1704
|
// The globalLexicals are captured as a snapshot of what's passed to
|
|
1706
1705
|
// the Compartment constructor, wherein all accessors and setters are
|
|
@@ -1709,7 +1708,7 @@ const createScopeHandler= (
|
|
|
1709
1708
|
// make use of their receiver.
|
|
1710
1709
|
// Live binding traps provide no avenue for user code to observe the
|
|
1711
1710
|
// receiver.
|
|
1712
|
-
return reflectGet(
|
|
1711
|
+
return reflectGet(globalLexicals, prop, globalObject);
|
|
1713
1712
|
}
|
|
1714
1713
|
|
|
1715
1714
|
// Properties of the global.
|
|
@@ -1717,17 +1716,17 @@ const createScopeHandler= (
|
|
|
1717
1716
|
},
|
|
1718
1717
|
|
|
1719
1718
|
set(_shadow, prop, value) {
|
|
1720
|
-
// Properties of the
|
|
1721
|
-
if( prop in
|
|
1722
|
-
const desc= getOwnPropertyDescriptor(
|
|
1719
|
+
// Properties of the globalLexicals.
|
|
1720
|
+
if( prop in globalLexicals) {
|
|
1721
|
+
const desc= getOwnPropertyDescriptor(globalLexicals, prop);
|
|
1723
1722
|
if( objectHasOwnProperty(desc, 'value')) {
|
|
1724
1723
|
// Work around a peculiar behavior in the specs, where
|
|
1725
1724
|
// value properties are defined on the receiver.
|
|
1726
|
-
return reflectSet(
|
|
1725
|
+
return reflectSet(globalLexicals, prop, value);
|
|
1727
1726
|
}
|
|
1728
1727
|
// Ensure that the 'this' value on setters resolves
|
|
1729
|
-
// to the safeGlobal, not to the
|
|
1730
|
-
return reflectSet(
|
|
1728
|
+
// to the safeGlobal, not to the globalLexicals object.
|
|
1729
|
+
return reflectSet(globalLexicals, prop, value, globalObject);
|
|
1731
1730
|
}
|
|
1732
1731
|
|
|
1733
1732
|
// Properties of the global.
|
|
@@ -1770,8 +1769,8 @@ const createScopeHandler= (
|
|
|
1770
1769
|
// !!!!! WARNING: DANGER ZONE !!!!!!
|
|
1771
1770
|
return(
|
|
1772
1771
|
sloppyGlobalsMode||
|
|
1773
|
-
allowNextEvalToBeUnsafe&& prop=== 'eval'||
|
|
1774
|
-
prop in
|
|
1772
|
+
scopeController.allowNextEvalToBeUnsafe&& prop=== 'eval'||
|
|
1773
|
+
prop in globalLexicals||
|
|
1775
1774
|
prop in globalObject||
|
|
1776
1775
|
prop in globalThis);
|
|
1777
1776
|
|
|
@@ -1811,8 +1810,7 @@ const createScopeHandler= (
|
|
|
1811
1810
|
|
|
1812
1811
|
|
|
1813
1812
|
return {
|
|
1814
|
-
|
|
1815
|
-
resetOneUnsafeEvalNext,
|
|
1813
|
+
scopeController,
|
|
1816
1814
|
scopeHandler};
|
|
1817
1815
|
|
|
1818
1816
|
};$h_once.createScopeHandler(createScopeHandler);
|
|
@@ -2141,8 +2139,6 @@ const applyTransforms= (source, transforms)=> {
|
|
|
2141
2139
|
|
|
2142
2140
|
const { details: d}= assert;
|
|
2143
2141
|
|
|
2144
|
-
// TODO: rename localObject to scopeObject
|
|
2145
|
-
|
|
2146
2142
|
/**
|
|
2147
2143
|
* makeSafeEvaluator()
|
|
2148
2144
|
* Build the low-level operation used by all evaluators:
|
|
@@ -2150,24 +2146,24 @@ const { details: d}= assert;
|
|
|
2150
2146
|
*
|
|
2151
2147
|
* @param {Object} options
|
|
2152
2148
|
* @param {Object} options.globalObject
|
|
2153
|
-
* @param {Object} [options.
|
|
2149
|
+
* @param {Object} [options.globalLexicals]
|
|
2154
2150
|
* @param {Array<Transform>} [options.globalTransforms]
|
|
2155
2151
|
* @param {bool} [options.sloppyGlobalsMode]
|
|
2156
2152
|
* @param {WeakSet} [options.knownScopeProxies]
|
|
2157
2153
|
*/
|
|
2158
2154
|
const makeSafeEvaluator= ({
|
|
2159
2155
|
globalObject,
|
|
2160
|
-
|
|
2156
|
+
globalLexicals= {},
|
|
2161
2157
|
globalTransforms= [],
|
|
2162
2158
|
sloppyGlobalsMode= false,
|
|
2163
2159
|
knownScopeProxies= new WeakSet()}=
|
|
2164
2160
|
{})=> {
|
|
2165
|
-
const {
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2161
|
+
const { scopeHandler, scopeController}= createScopeHandler(
|
|
2162
|
+
globalObject,
|
|
2163
|
+
globalLexicals,
|
|
2164
|
+
{
|
|
2165
|
+
sloppyGlobalsMode});
|
|
2166
|
+
|
|
2171
2167
|
|
|
2172
2168
|
const { proxy: scopeProxy, revoke: revokeScopeProxy}= proxyRevocable(
|
|
2173
2169
|
immutableObject,
|
|
@@ -2181,7 +2177,7 @@ const makeSafeEvaluator= ({
|
|
|
2181
2177
|
let evaluate;
|
|
2182
2178
|
const makeEvaluate= ()=> {
|
|
2183
2179
|
if( !evaluate) {
|
|
2184
|
-
const constants= getScopeConstants(globalObject,
|
|
2180
|
+
const constants= getScopeConstants(globalObject, globalLexicals);
|
|
2185
2181
|
const evaluateFactory= makeEvaluateFactory(constants);
|
|
2186
2182
|
evaluate= apply(evaluateFactory, scopeProxy, []);
|
|
2187
2183
|
}
|
|
@@ -2203,7 +2199,7 @@ const makeSafeEvaluator= ({
|
|
|
2203
2199
|
mandatoryTransforms]);
|
|
2204
2200
|
|
|
2205
2201
|
|
|
2206
|
-
|
|
2202
|
+
scopeController.allowNextEvalToBeUnsafe= true;
|
|
2207
2203
|
let err;
|
|
2208
2204
|
try {
|
|
2209
2205
|
// Ensure that "this" resolves to the safe global.
|
|
@@ -2213,13 +2209,15 @@ const makeSafeEvaluator= ({
|
|
|
2213
2209
|
err= e;
|
|
2214
2210
|
throw e;
|
|
2215
2211
|
}finally {
|
|
2216
|
-
|
|
2212
|
+
const unsafeEvalWasStillExposed= scopeController.allowNextEvalToBeUnsafe;
|
|
2213
|
+
scopeController.allowNextEvalToBeUnsafe= false;
|
|
2214
|
+
if( unsafeEvalWasStillExposed) {
|
|
2217
2215
|
// Barring a defect in the SES shim, the scope proxy should allow the
|
|
2218
2216
|
// powerful, unsafe `eval` to be used by `evaluate` exactly once, as the
|
|
2219
2217
|
// very first name that it attempts to access from the lexical scope.
|
|
2220
|
-
// A defect in the SES shim could throw an exception after
|
|
2221
|
-
// `
|
|
2222
|
-
// internally.
|
|
2218
|
+
// A defect in the SES shim could throw an exception after we set
|
|
2219
|
+
// `scopeController.allowNextEvalToBeUnsafe` and before `evaluate`
|
|
2220
|
+
// calls `eval` internally.
|
|
2223
2221
|
// If we get here, SES is very broken.
|
|
2224
2222
|
// This condition is one where this vat is now hopelessly confused, and
|
|
2225
2223
|
// the vat as a whole should be aborted.
|
|
@@ -2300,7 +2298,7 @@ const provideCompartmentEvaluator= (compartmentFields, options)=> {
|
|
|
2300
2298
|
|
|
2301
2299
|
({ safeEvaluate}= makeSafeEvaluator({
|
|
2302
2300
|
globalObject,
|
|
2303
|
-
localObject,
|
|
2301
|
+
globalLexicals: localObject,
|
|
2304
2302
|
globalTransforms,
|
|
2305
2303
|
sloppyGlobalsMode,
|
|
2306
2304
|
knownScopeProxies}));
|
|
@@ -5417,7 +5415,7 @@ const makeCompartmentConstructor= (
|
|
|
5417
5415
|
const knownScopeProxies= new WeakSet();
|
|
5418
5416
|
const { safeEvaluate}= makeSafeEvaluator({
|
|
5419
5417
|
globalObject,
|
|
5420
|
-
|
|
5418
|
+
globalLexicals,
|
|
5421
5419
|
globalTransforms,
|
|
5422
5420
|
sloppyGlobalsMode: false,
|
|
5423
5421
|
knownScopeProxies});
|