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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ses",
3
- "version": "0.15.12",
3
+ "version": "0.15.13",
4
4
  "description": "Hardened JavaScript for Fearless Cooperation",
5
5
  "keywords": [
6
6
  "lockdown",
@@ -59,10 +59,10 @@
59
59
  "test:platform-compatability": "node test/package/test.cjs"
60
60
  },
61
61
  "devDependencies": {
62
- "@endo/compartment-mapper": "^0.7.2",
63
- "@endo/eslint-config": "^0.4.7",
64
- "@endo/static-module-record": "^0.7.1",
65
- "@endo/test262-runner": "^0.1.23",
62
+ "@endo/compartment-mapper": "^0.7.3",
63
+ "@endo/eslint-config": "^0.4.8",
64
+ "@endo/static-module-record": "^0.7.2",
65
+ "@endo/test262-runner": "^0.1.24",
66
66
  "ava": "^3.12.1",
67
67
  "babel-eslint": "^10.0.3",
68
68
  "c8": "^7.7.3",
@@ -179,5 +179,5 @@
179
179
  ],
180
180
  "timeout": "2m"
181
181
  },
182
- "gitHead": "59e511891ab67f4fa52d67141510974e22362134"
182
+ "gitHead": "ada5203fd64e6828dca74895fd74588e08925d97"
183
183
  }
@@ -55,7 +55,7 @@ export const provideCompartmentEvaluator = (compartmentFields, options) => {
55
55
 
56
56
  ({ safeEvaluate } = makeSafeEvaluator({
57
57
  globalObject,
58
- localObject,
58
+ globalLexicals: localObject,
59
59
  globalTransforms,
60
60
  sloppyGlobalsMode,
61
61
  knownScopeProxies,
@@ -283,7 +283,7 @@ export const makeCompartmentConstructor = (
283
283
  const knownScopeProxies = new WeakSet();
284
284
  const { safeEvaluate } = makeSafeEvaluator({
285
285
  globalObject,
286
- localObject: globalLexicals,
286
+ globalLexicals,
287
287
  globalTransforms,
288
288
  sloppyGlobalsMode: false,
289
289
  knownScopeProxies,
@@ -16,8 +16,6 @@ import { assert } from './error/assert.js';
16
16
 
17
17
  const { details: d } = assert;
18
18
 
19
- // TODO: rename localObject to scopeObject
20
-
21
19
  /**
22
20
  * makeSafeEvaluator()
23
21
  * Build the low-level operation used by all evaluators:
@@ -25,25 +23,25 @@ const { details: d } = assert;
25
23
  *
26
24
  * @param {Object} options
27
25
  * @param {Object} options.globalObject
28
- * @param {Object} [options.localObject]
26
+ * @param {Object} [options.globalLexicals]
29
27
  * @param {Array<Transform>} [options.globalTransforms]
30
28
  * @param {bool} [options.sloppyGlobalsMode]
31
29
  * @param {WeakSet} [options.knownScopeProxies]
32
30
  */
33
31
  export const makeSafeEvaluator = ({
34
32
  globalObject,
35
- localObject = {},
33
+ globalLexicals = {},
36
34
  globalTransforms = [],
37
35
  sloppyGlobalsMode = false,
38
36
  knownScopeProxies = new WeakSet(),
39
37
  } = {}) => {
40
- const {
41
- scopeHandler,
42
- admitOneUnsafeEvalNext,
43
- resetOneUnsafeEvalNext,
44
- } = createScopeHandler(globalObject, localObject, {
45
- sloppyGlobalsMode,
46
- });
38
+ const { scopeHandler, scopeController } = createScopeHandler(
39
+ globalObject,
40
+ globalLexicals,
41
+ {
42
+ sloppyGlobalsMode,
43
+ },
44
+ );
47
45
  const { proxy: scopeProxy, revoke: revokeScopeProxy } = proxyRevocable(
48
46
  immutableObject,
49
47
  scopeHandler,
@@ -56,7 +54,7 @@ export const makeSafeEvaluator = ({
56
54
  let evaluate;
57
55
  const makeEvaluate = () => {
58
56
  if (!evaluate) {
59
- const constants = getScopeConstants(globalObject, localObject);
57
+ const constants = getScopeConstants(globalObject, globalLexicals);
60
58
  const evaluateFactory = makeEvaluateFactory(constants);
61
59
  evaluate = apply(evaluateFactory, scopeProxy, []);
62
60
  }
@@ -78,7 +76,7 @@ export const makeSafeEvaluator = ({
78
76
  mandatoryTransforms,
79
77
  ]);
80
78
 
81
- admitOneUnsafeEvalNext();
79
+ scopeController.allowNextEvalToBeUnsafe = true;
82
80
  let err;
83
81
  try {
84
82
  // Ensure that "this" resolves to the safe global.
@@ -88,13 +86,15 @@ export const makeSafeEvaluator = ({
88
86
  err = e;
89
87
  throw e;
90
88
  } finally {
91
- if (resetOneUnsafeEvalNext()) {
89
+ const unsafeEvalWasStillExposed = scopeController.allowNextEvalToBeUnsafe;
90
+ scopeController.allowNextEvalToBeUnsafe = false;
91
+ if (unsafeEvalWasStillExposed) {
92
92
  // Barring a defect in the SES shim, the scope proxy should allow the
93
93
  // powerful, unsafe `eval` to be used by `evaluate` exactly once, as the
94
94
  // very first name that it attempts to access from the lexical scope.
95
- // A defect in the SES shim could throw an exception after our call to
96
- // `admitOneUnsafeEvalNext()` and before `evaluate` calls `eval`
97
- // internally.
95
+ // A defect in the SES shim could throw an exception after we set
96
+ // `scopeController.allowNextEvalToBeUnsafe` and before `evaluate`
97
+ // calls `eval` internally.
98
98
  // If we get here, SES is very broken.
99
99
  // This condition is one where this vat is now hopelessly confused, and
100
100
  // the vat as a whole should be aborted.
@@ -12,6 +12,7 @@ import {
12
12
  objectHasOwnProperty,
13
13
  reflectGet,
14
14
  reflectSet,
15
+ seal,
15
16
  } from './commons.js';
16
17
  import { assert } from './error/assert.js';
17
18
 
@@ -53,23 +54,21 @@ const alwaysThrowHandler = new Proxy(
53
54
  */
54
55
  export const createScopeHandler = (
55
56
  globalObject,
56
- localObject = {},
57
+ globalLexicals = {},
57
58
  { sloppyGlobalsMode = false } = {},
58
59
  ) => {
59
60
  // This flag allow us to determine if the eval() call is an done by the
60
61
  // compartment's code or if it is user-land invocation, so we can react
61
62
  // differently.
62
- let allowNextEvalToBeUnsafe = false;
63
-
64
- const admitOneUnsafeEvalNext = () => {
65
- allowNextEvalToBeUnsafe = true;
66
- };
67
-
68
- const resetOneUnsafeEvalNext = () => {
69
- const wasSet = allowNextEvalToBeUnsafe;
70
- allowNextEvalToBeUnsafe = false;
71
- return wasSet;
63
+ // Using a flag on an object with a single mutable property allows a safe
64
+ // evaluator to signal to the scope proxy without consuming a stack frame.
65
+ // Consuming a stack frame could possibly allow an attacker to control the
66
+ // stack depth before calling `evaluate` to cause a RangeError before this
67
+ // flag can be reset, leaving the unsafe evaluator available.
68
+ const scopeController = {
69
+ allowNextEvalToBeUnsafe: false,
72
70
  };
71
+ seal(scopeController);
73
72
 
74
73
  const scopeProxyHandlerProperties = {
75
74
  get(_shadow, prop) {
@@ -82,20 +81,20 @@ export const createScopeHandler = (
82
81
  // the 'with' context.
83
82
  if (prop === 'eval') {
84
83
  // test that it is true rather than merely truthy
85
- if (allowNextEvalToBeUnsafe === true) {
84
+ if (scopeController.allowNextEvalToBeUnsafe === true) {
86
85
  // revoke before use
87
- allowNextEvalToBeUnsafe = false;
86
+ scopeController.allowNextEvalToBeUnsafe = false;
88
87
  return FERAL_EVAL;
89
88
  }
90
89
  // fall through
91
90
  }
92
91
 
93
- // Properties of the localObject.
94
- if (prop in localObject) {
92
+ // Properties of the globalLexicals.
93
+ if (prop in globalLexicals) {
95
94
  // Use reflect to defeat accessors that could be present on the
96
- // localObject object itself as `this`.
95
+ // globalLexicals object itself as `this`.
97
96
  // This is done out of an overabundance of caution, as the SES shim
98
- // only use the localObject carry globalLexicals and live binding
97
+ // only use the globalLexicals carry globalLexicals and live binding
99
98
  // traps.
100
99
  // The globalLexicals are captured as a snapshot of what's passed to
101
100
  // the Compartment constructor, wherein all accessors and setters are
@@ -104,7 +103,7 @@ export const createScopeHandler = (
104
103
  // make use of their receiver.
105
104
  // Live binding traps provide no avenue for user code to observe the
106
105
  // receiver.
107
- return reflectGet(localObject, prop, globalObject);
106
+ return reflectGet(globalLexicals, prop, globalObject);
108
107
  }
109
108
 
110
109
  // Properties of the global.
@@ -112,17 +111,17 @@ export const createScopeHandler = (
112
111
  },
113
112
 
114
113
  set(_shadow, prop, value) {
115
- // Properties of the localObject.
116
- if (prop in localObject) {
117
- const desc = getOwnPropertyDescriptor(localObject, prop);
114
+ // Properties of the globalLexicals.
115
+ if (prop in globalLexicals) {
116
+ const desc = getOwnPropertyDescriptor(globalLexicals, prop);
118
117
  if (objectHasOwnProperty(desc, 'value')) {
119
118
  // Work around a peculiar behavior in the specs, where
120
119
  // value properties are defined on the receiver.
121
- return reflectSet(localObject, prop, value);
120
+ return reflectSet(globalLexicals, prop, value);
122
121
  }
123
122
  // Ensure that the 'this' value on setters resolves
124
- // to the safeGlobal, not to the localObject object.
125
- return reflectSet(localObject, prop, value, globalObject);
123
+ // to the safeGlobal, not to the globalLexicals object.
124
+ return reflectSet(globalLexicals, prop, value, globalObject);
126
125
  }
127
126
 
128
127
  // Properties of the global.
@@ -165,8 +164,8 @@ export const createScopeHandler = (
165
164
  // !!!!! WARNING: DANGER ZONE !!!!!!
166
165
  return (
167
166
  sloppyGlobalsMode ||
168
- (allowNextEvalToBeUnsafe && prop === 'eval') ||
169
- prop in localObject ||
167
+ (scopeController.allowNextEvalToBeUnsafe && prop === 'eval') ||
168
+ prop in globalLexicals ||
170
169
  prop in globalObject ||
171
170
  prop in globalThis
172
171
  );
@@ -206,8 +205,7 @@ export const createScopeHandler = (
206
205
  );
207
206
 
208
207
  return {
209
- admitOneUnsafeEvalNext,
210
- resetOneUnsafeEvalNext,
208
+ scopeController,
211
209
  scopeHandler,
212
210
  };
213
211
  };