ses 0.15.9 → 0.15.10

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/index.d.ts CHANGED
@@ -23,6 +23,7 @@ export interface LockdownOptions {
23
23
  errorTaming?: 'safe' | 'unsafe';
24
24
  dateTaming?: 'safe' | 'unsafe'; // deprecated
25
25
  mathTaming?: 'safe' | 'unsafe'; // deprecated
26
+ evalTaming?: 'safeEval' | 'unsafeEval' | 'noEval';
26
27
  stackFiltering?: 'concise' | 'verbose';
27
28
  overrideTaming?: 'moderate' | 'min' | 'severe';
28
29
  overrideDebug?: Array<string>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ses",
3
- "version": "0.15.9",
3
+ "version": "0.15.10",
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.6.7",
63
- "@endo/eslint-config": "^0.4.4",
64
- "@endo/static-module-record": "^0.6.14",
65
- "@endo/test262-runner": "^0.1.20",
62
+ "@endo/compartment-mapper": "^0.7.0",
63
+ "@endo/eslint-config": "^0.4.5",
64
+ "@endo/static-module-record": "^0.6.15",
65
+ "@endo/test262-runner": "^0.1.21",
66
66
  "ava": "^3.12.1",
67
67
  "babel-eslint": "^10.0.3",
68
68
  "c8": "^7.7.3",
@@ -178,5 +178,5 @@
178
178
  ],
179
179
  "timeout": "2m"
180
180
  },
181
- "gitHead": "bbefeb4e9869df15a031be1cd6fc57a50b2906e0"
181
+ "gitHead": "08973d4fc6358a58d733251b051b2812bb4c651a"
182
182
  }
package/src/commons.js CHANGED
@@ -272,3 +272,9 @@ export const FERAL_EVAL = eval;
272
272
  // Sample at module initialization time, which is before lockdown can
273
273
  // repair it. Use it only to build powerless abstractions.
274
274
  export const FERAL_FUNCTION = Function;
275
+
276
+ export const noEvalEvaluate = () => {
277
+ throw new TypeError(
278
+ 'Cannot eval with evalTaming set to "noEval" (SES_NO_EVAL)',
279
+ );
280
+ };
@@ -23,6 +23,7 @@ import {
23
23
  import {
24
24
  setGlobalObjectConstantProperties,
25
25
  setGlobalObjectMutableProperties,
26
+ setGlobalObjectEvaluators,
26
27
  } from './global-object.js';
27
28
  import { isValidIdentifierName } from './scope-constants.js';
28
29
  import { sharedGlobalPropertyNames } from './whitelist.js';
@@ -292,10 +293,16 @@ export const makeCompartmentConstructor = (
292
293
  intrinsics,
293
294
  newGlobalPropertyNames: sharedGlobalPropertyNames,
294
295
  makeCompartmentConstructor: targetMakeCompartmentConstructor,
295
- safeEvaluate,
296
296
  markVirtualizedNativeFunction,
297
297
  });
298
298
 
299
+ // TODO: maybe add evalTaming to the Compartment constructor 3rd options?
300
+ setGlobalObjectEvaluators(
301
+ globalObject,
302
+ safeEvaluate,
303
+ markVirtualizedNativeFunction,
304
+ );
305
+
299
306
  assign(globalObject, endowments);
300
307
 
301
308
  weakmapSet(privateFields, this, {
@@ -34,7 +34,6 @@ export const setGlobalObjectConstantProperties = globalObject => {
34
34
  * @param {Object} param1.intrinsics
35
35
  * @param {Object} param1.newGlobalPropertyNames
36
36
  * @param {Function} param1.makeCompartmentConstructor
37
- * @param {(string, Object?) => any} param1.safeEvaluate
38
37
  * @param {(Object) => void} param1.markVirtualizedNativeFunction
39
38
  */
40
39
  export const setGlobalObjectMutableProperties = (
@@ -43,7 +42,6 @@ export const setGlobalObjectMutableProperties = (
43
42
  intrinsics,
44
43
  newGlobalPropertyNames,
45
44
  makeCompartmentConstructor,
46
- safeEvaluate,
47
45
  markVirtualizedNativeFunction,
48
46
  },
49
47
  ) => {
@@ -71,8 +69,6 @@ export const setGlobalObjectMutableProperties = (
71
69
 
72
70
  const perCompartmentGlobals = {
73
71
  globalThis: globalObject,
74
- eval: makeEvalFunction(safeEvaluate),
75
- Function: makeFunctionConstructor(safeEvaluate),
76
72
  };
77
73
 
78
74
  perCompartmentGlobals.Compartment = makeCompartmentConstructor(
@@ -95,3 +91,38 @@ export const setGlobalObjectMutableProperties = (
95
91
  }
96
92
  }
97
93
  };
94
+
95
+ /**
96
+ * setGlobalObjectEvaluators()
97
+ * Set the eval and the Function evaluator on the global object with given evalTaming policy.
98
+ *
99
+ * @param {Object} globalObject
100
+ * @param {Function} evaluator
101
+ * @param {(Object) => void} markVirtualizedNativeFunction
102
+ */
103
+ export const setGlobalObjectEvaluators = (
104
+ globalObject,
105
+ evaluator,
106
+ markVirtualizedNativeFunction,
107
+ ) => {
108
+ {
109
+ const f = makeEvalFunction(evaluator);
110
+ markVirtualizedNativeFunction(f);
111
+ defineProperty(globalObject, 'eval', {
112
+ value: f,
113
+ writable: true,
114
+ enumerable: false,
115
+ configurable: true,
116
+ });
117
+ }
118
+ {
119
+ const f = makeFunctionConstructor(evaluator);
120
+ markVirtualizedNativeFunction(f);
121
+ defineProperty(globalObject, 'Function', {
122
+ value: f,
123
+ writable: true,
124
+ enumerable: false,
125
+ configurable: true,
126
+ });
127
+ }
128
+ };
@@ -24,6 +24,7 @@ import {
24
24
  is,
25
25
  ownKeys,
26
26
  stringSplit,
27
+ noEvalEvaluate,
27
28
  } from './commons.js';
28
29
  import { enJoin } from './error/stringify-utils.js';
29
30
  import { makeHardener } from './make-hardener.js';
@@ -38,6 +39,7 @@ import tameLocaleMethods from './tame-locale-methods.js';
38
39
  import {
39
40
  setGlobalObjectConstantProperties,
40
41
  setGlobalObjectMutableProperties,
42
+ setGlobalObjectEvaluators,
41
43
  } from './global-object.js';
42
44
  import { makeSafeEvaluator } from './make-safe-evaluator.js';
43
45
  import { initialGlobalPropertyNames } from './whitelist.js';
@@ -164,6 +166,7 @@ export const repairIntrinsics = (options = {}) => {
164
166
  overrideTaming = getenv('LOCKDOWN_OVERRIDE_TAMING', 'moderate'),
165
167
  stackFiltering = getenv('LOCKDOWN_STACK_FILTERING', 'concise'),
166
168
  domainTaming = getenv('LOCKDOWN_DOMAIN_TAMING', 'safe'),
169
+ evalTaming = getenv('LOCKDOWN_EVAL_TAMING', 'safeEval'),
167
170
  overrideDebug = arrayFilter(
168
171
  stringSplit(getenv('LOCKDOWN_OVERRIDE_DEBUG', ''), ','),
169
172
  /** @param {string} debugName */
@@ -189,6 +192,13 @@ export const repairIntrinsics = (options = {}) => {
189
192
  );
190
193
  }
191
194
 
195
+ assert(
196
+ evalTaming === 'unsafeEval' ||
197
+ evalTaming === 'safeEval' ||
198
+ evalTaming === 'noEval',
199
+ d`lockdown(): non supported option evalTaming: ${q(evalTaming)}`,
200
+ );
201
+
192
202
  // Assert that only supported options were passed.
193
203
  // Use Reflect.ownKeys to reject symbol-named properties as well.
194
204
  const extraOptionsNames = ownKeys(extraOptions);
@@ -324,16 +334,32 @@ export const repairIntrinsics = (options = {}) => {
324
334
 
325
335
  setGlobalObjectConstantProperties(globalThis);
326
336
 
327
- const { safeEvaluate } = makeSafeEvaluator({ globalObject: globalThis });
328
-
329
337
  setGlobalObjectMutableProperties(globalThis, {
330
338
  intrinsics,
331
339
  newGlobalPropertyNames: initialGlobalPropertyNames,
332
340
  makeCompartmentConstructor,
333
- safeEvaluate,
334
341
  markVirtualizedNativeFunction,
335
342
  });
336
343
 
344
+ if (evalTaming === 'noEval') {
345
+ setGlobalObjectEvaluators(
346
+ globalThis,
347
+ noEvalEvaluate,
348
+ markVirtualizedNativeFunction,
349
+ );
350
+ } else if (evalTaming === 'safeEval') {
351
+ const { safeEvaluate } = makeSafeEvaluator({ globalObject: globalThis });
352
+ setGlobalObjectEvaluators(
353
+ globalThis,
354
+ safeEvaluate,
355
+ markVirtualizedNativeFunction,
356
+ );
357
+ } else if (evalTaming === 'unsafeEval') {
358
+ // Leave eval function and Function constructor of the initial compartment in-tact.
359
+ // Other compartments will not have access to these evaluators unless a guest program
360
+ // escapes containment.
361
+ }
362
+
337
363
  /**
338
364
  * 3. HARDEN to share the intrinsics.
339
365
  *
@@ -1,7 +1,9 @@
1
- /*
1
+ /**
2
2
  * makeEvalFunction()
3
3
  * A safe version of the native eval function which relies on
4
4
  * the safety of safeEvaluate for confinement.
5
+ *
6
+ * @param {Function} safeEvaluate
5
7
  */
6
8
  export const makeEvalFunction = safeEvaluate => {
7
9
  // We use the the concise method syntax to create an eval without a