ses 0.15.3 → 0.15.7

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/dist/lockdown.mjs CHANGED
@@ -28,6 +28,7 @@ const {
28
28
  JSON,
29
29
  Map,
30
30
  Math,
31
+ Number,
31
32
  Object,
32
33
  Promise,
33
34
  Proxy,
@@ -37,7 +38,7 @@ const {
37
38
  String,
38
39
  WeakMap,
39
40
  WeakSet } =
40
- globalThis;$h‍_once.Array(Array);$h‍_once.Date(Date);$h‍_once.Float32Array(Float32Array);$h‍_once.JSON(JSON);$h‍_once.Map(Map);$h‍_once.Math(Math);$h‍_once.Object(Object);$h‍_once.Promise(Promise);$h‍_once.Proxy(Proxy);$h‍_once.Reflect(Reflect);$h‍_once.FERAL_REG_EXP(FERAL_REG_EXP);$h‍_once.Set(Set);$h‍_once.String(String);$h‍_once.WeakMap(WeakMap);$h‍_once.WeakSet(WeakSet);
41
+ globalThis;$h‍_once.Array(Array);$h‍_once.Date(Date);$h‍_once.Float32Array(Float32Array);$h‍_once.JSON(JSON);$h‍_once.Map(Map);$h‍_once.Math(Math);$h‍_once.Number(Number);$h‍_once.Object(Object);$h‍_once.Promise(Promise);$h‍_once.Proxy(Proxy);$h‍_once.Reflect(Reflect);$h‍_once.FERAL_REG_EXP(FERAL_REG_EXP);$h‍_once.Set(Set);$h‍_once.String(String);$h‍_once.WeakMap(WeakMap);$h‍_once.WeakSet(WeakSet);
41
42
 
42
43
  const {
43
44
  // The feral Error constructor is safe for internal use, but must not be
@@ -2733,7 +2734,10 @@ function NativeErrorPrototype(constructor) {
2733
2734
  message: 'string',
2734
2735
  name: 'string',
2735
2736
  // Redundantly present only on v8. Safe to remove.
2736
- toString: false };
2737
+ toString: false,
2738
+ // Superfluously present in some versions of V8.
2739
+ // https://github.com/tc39/notes/blob/master/meetings/2021-10/oct-26.md#:~:text=However%2C%20Chrome%2093,and%20node%2016.11.
2740
+ cause: false };
2737
2741
 
2738
2742
  }
2739
2743
 
@@ -2997,7 +3001,10 @@ const whitelist = {
2997
3001
  // Seen on FF Nightly 88.0a1
2998
3002
  at: false,
2999
3003
  // Seen on FF and XS
3000
- stack: false },
3004
+ stack: false,
3005
+ // Superfluously present in some versions of V8.
3006
+ // https://github.com/tc39/notes/blob/master/meetings/2021-10/oct-26.md#:~:text=However%2C%20Chrome%2093,and%20node%2016.11.
3007
+ cause: false },
3001
3008
 
3002
3009
 
3003
3010
  // NativeError
@@ -6557,7 +6564,11 @@ optGetStackString = undefined) =>
6557
6564
  }
6558
6565
 
6559
6566
  // Browser
6560
- if (errorTrapping !== 'none' && globalThis.window !== undefined) {
6567
+ if (
6568
+ errorTrapping !== 'none' &&
6569
+ globalThis.window !== undefined &&
6570
+ globalThis.window.addEventListener !== undefined)
6571
+ {
6561
6572
  // eslint-disable-next-line @endo/no-polymorphic-call
6562
6573
  globalThis.window.addEventListener('error', (event) => {
6563
6574
  // eslint-disable-next-line @endo/no-polymorphic-call
@@ -7709,7 +7720,8 @@ const tameFunctionToString = () => {
7709
7720
  })
7710
7721
  ,
7711
7722
  // === functors[35] ===
7712
- (({ imports: $h‍_imports, liveVar: $h‍_live, onceVar: $h‍_once, }) => { let String,TypeError,defineProperty,getOwnPropertyNames,isObject,regexpExec,assert;$h‍_imports([["./commons.js", [["String", [$h‍_a => (String = $h‍_a)]],["TypeError", [$h‍_a => (TypeError = $h‍_a)]],["defineProperty", [$h‍_a => (defineProperty = $h‍_a)]],["getOwnPropertyNames", [$h‍_a => (getOwnPropertyNames = $h‍_a)]],["isObject", [$h‍_a => (isObject = $h‍_a)]],["regexpExec", [$h‍_a => (regexpExec = $h‍_a)]]]],["./error/assert.js", [["assert", [$h‍_a => (assert = $h‍_a)]]]]]);
7723
+ (({ imports: $h‍_imports, liveVar: $h‍_live, onceVar: $h‍_once, }) => { let Number,String,TypeError,defineProperty,getOwnPropertyNames,isObject,regexpExec,assert;$h‍_imports([["./commons.js", [["Number", [$h‍_a => (Number = $h‍_a)]],["String", [$h‍_a => (String = $h‍_a)]],["TypeError", [$h‍_a => (TypeError = $h‍_a)]],["defineProperty", [$h‍_a => (defineProperty = $h‍_a)]],["getOwnPropertyNames", [$h‍_a => (getOwnPropertyNames = $h‍_a)]],["isObject", [$h‍_a => (isObject = $h‍_a)]],["regexpExec", [$h‍_a => (regexpExec = $h‍_a)]]]],["./error/assert.js", [["assert", [$h‍_a => (assert = $h‍_a)]]]]]);
7724
+
7713
7725
 
7714
7726
 
7715
7727
 
@@ -7743,10 +7755,15 @@ const tamedMethods = {
7743
7755
  }
7744
7756
  assert(s === that, d`expected ${q(s)} and ${q(that)} to compare`);
7745
7757
  return 0;
7758
+ },
7759
+
7760
+ toString() {
7761
+ return `${this}`;
7746
7762
  } };
7747
7763
 
7748
7764
 
7749
7765
  const nonLocaleCompare = tamedMethods.localeCompare;
7766
+ const numberToString = tamedMethods.toString;
7750
7767
 
7751
7768
  function tameLocaleMethods(intrinsics, localeTaming = 'safe') {
7752
7769
  if (localeTaming !== 'safe' && localeTaming !== 'unsafe') {
@@ -7781,6 +7798,12 @@ function tameLocaleMethods(intrinsics, localeTaming = 'safe') {
7781
7798
  }
7782
7799
  }
7783
7800
  }
7801
+
7802
+ // Numbers are special because toString accepts a radix instead of ignoring
7803
+ // all of the arguments that we would otherwise forward.
7804
+ defineProperty(Number.prototype, 'toLocaleString', {
7805
+ value: numberToString });
7806
+
7784
7807
  }$h‍_once.default(tameLocaleMethods);
7785
7808
  })
7786
7809
  ,
@@ -8144,7 +8167,9 @@ markVirtualizedNativeFunction)
8144
8167
  })
8145
8168
  ,
8146
8169
  // === functors[39] ===
8147
- (({ imports: $h‍_imports, liveVar: $h‍_live, onceVar: $h‍_once, }) => { let TypeError,arrayFilter,arrayMap,globalThis,is,ownKeys,stringSplit,enJoin,makeHardener,makeIntrinsicsCollector,whitelistIntrinsics,tameFunctionConstructors,tameDateConstructor,tameMathObject,tameRegExpConstructor,enablePropertyOverrides,tameLocaleMethods,setGlobalObjectConstantProperties,setGlobalObjectMutableProperties,makeSafeEvaluator,initialGlobalPropertyNames,tameFunctionToString,tameDomains,tameConsole,tameErrorConstructor,assert,makeAssert,makeEnvironmentCaptor,getAnonymousIntrinsics,makeCompartmentConstructor;$h‍_imports([["./commons.js", [["TypeError", [$h‍_a => (TypeError = $h‍_a)]],["arrayFilter", [$h‍_a => (arrayFilter = $h‍_a)]],["arrayMap", [$h‍_a => (arrayMap = $h‍_a)]],["globalThis", [$h‍_a => (globalThis = $h‍_a)]],["is", [$h‍_a => (is = $h‍_a)]],["ownKeys", [$h‍_a => (ownKeys = $h‍_a)]],["stringSplit", [$h‍_a => (stringSplit = $h‍_a)]]]],["./error/stringify-utils.js", [["enJoin", [$h‍_a => (enJoin = $h‍_a)]]]],["./make-hardener.js", [["makeHardener", [$h‍_a => (makeHardener = $h‍_a)]]]],["./intrinsics.js", [["makeIntrinsicsCollector", [$h‍_a => (makeIntrinsicsCollector = $h‍_a)]]]],["./whitelist-intrinsics.js", [["default", [$h‍_a => (whitelistIntrinsics = $h‍_a)]]]],["./tame-function-constructors.js", [["default", [$h‍_a => (tameFunctionConstructors = $h‍_a)]]]],["./tame-date-constructor.js", [["default", [$h‍_a => (tameDateConstructor = $h‍_a)]]]],["./tame-math-object.js", [["default", [$h‍_a => (tameMathObject = $h‍_a)]]]],["./tame-regexp-constructor.js", [["default", [$h‍_a => (tameRegExpConstructor = $h‍_a)]]]],["./enable-property-overrides.js", [["default", [$h‍_a => (enablePropertyOverrides = $h‍_a)]]]],["./tame-locale-methods.js", [["default", [$h‍_a => (tameLocaleMethods = $h‍_a)]]]],["./global-object.js", [["setGlobalObjectConstantProperties", [$h‍_a => (setGlobalObjectConstantProperties = $h‍_a)]],["setGlobalObjectMutableProperties", [$h‍_a => (setGlobalObjectMutableProperties = $h‍_a)]]]],["./make-safe-evaluator.js", [["makeSafeEvaluator", [$h‍_a => (makeSafeEvaluator = $h‍_a)]]]],["./whitelist.js", [["initialGlobalPropertyNames", [$h‍_a => (initialGlobalPropertyNames = $h‍_a)]]]],["./tame-function-tostring.js", [["tameFunctionToString", [$h‍_a => (tameFunctionToString = $h‍_a)]]]],["./tame-domains.js", [["tameDomains", [$h‍_a => (tameDomains = $h‍_a)]]]],["./error/tame-console.js", [["tameConsole", [$h‍_a => (tameConsole = $h‍_a)]]]],["./error/tame-error-constructor.js", [["default", [$h‍_a => (tameErrorConstructor = $h‍_a)]]]],["./error/assert.js", [["assert", [$h‍_a => (assert = $h‍_a)]],["makeAssert", [$h‍_a => (makeAssert = $h‍_a)]]]],["./environment-options.js", [["makeEnvironmentCaptor", [$h‍_a => (makeEnvironmentCaptor = $h‍_a)]]]],["./get-anonymous-intrinsics.js", [["getAnonymousIntrinsics", [$h‍_a => (getAnonymousIntrinsics = $h‍_a)]]]],["./compartment-shim.js", [["makeCompartmentConstructor", [$h‍_a => (makeCompartmentConstructor = $h‍_a)]]]]]);
8170
+ (({ imports: $h‍_imports, liveVar: $h‍_live, onceVar: $h‍_once, }) => { let FERAL_FUNCTION,FERAL_EVAL,TypeError,arrayFilter,arrayMap,globalThis,is,ownKeys,stringSplit,enJoin,makeHardener,makeIntrinsicsCollector,whitelistIntrinsics,tameFunctionConstructors,tameDateConstructor,tameMathObject,tameRegExpConstructor,enablePropertyOverrides,tameLocaleMethods,setGlobalObjectConstantProperties,setGlobalObjectMutableProperties,makeSafeEvaluator,initialGlobalPropertyNames,tameFunctionToString,tameDomains,tameConsole,tameErrorConstructor,assert,makeAssert,makeEnvironmentCaptor,getAnonymousIntrinsics,makeCompartmentConstructor;$h‍_imports([["./commons.js", [["FERAL_FUNCTION", [$h‍_a => (FERAL_FUNCTION = $h‍_a)]],["FERAL_EVAL", [$h‍_a => (FERAL_EVAL = $h‍_a)]],["TypeError", [$h‍_a => (TypeError = $h‍_a)]],["arrayFilter", [$h‍_a => (arrayFilter = $h‍_a)]],["arrayMap", [$h‍_a => (arrayMap = $h‍_a)]],["globalThis", [$h‍_a => (globalThis = $h‍_a)]],["is", [$h‍_a => (is = $h‍_a)]],["ownKeys", [$h‍_a => (ownKeys = $h‍_a)]],["stringSplit", [$h‍_a => (stringSplit = $h‍_a)]]]],["./error/stringify-utils.js", [["enJoin", [$h‍_a => (enJoin = $h‍_a)]]]],["./make-hardener.js", [["makeHardener", [$h‍_a => (makeHardener = $h‍_a)]]]],["./intrinsics.js", [["makeIntrinsicsCollector", [$h‍_a => (makeIntrinsicsCollector = $h‍_a)]]]],["./whitelist-intrinsics.js", [["default", [$h‍_a => (whitelistIntrinsics = $h‍_a)]]]],["./tame-function-constructors.js", [["default", [$h‍_a => (tameFunctionConstructors = $h‍_a)]]]],["./tame-date-constructor.js", [["default", [$h‍_a => (tameDateConstructor = $h‍_a)]]]],["./tame-math-object.js", [["default", [$h‍_a => (tameMathObject = $h‍_a)]]]],["./tame-regexp-constructor.js", [["default", [$h‍_a => (tameRegExpConstructor = $h‍_a)]]]],["./enable-property-overrides.js", [["default", [$h‍_a => (enablePropertyOverrides = $h‍_a)]]]],["./tame-locale-methods.js", [["default", [$h‍_a => (tameLocaleMethods = $h‍_a)]]]],["./global-object.js", [["setGlobalObjectConstantProperties", [$h‍_a => (setGlobalObjectConstantProperties = $h‍_a)]],["setGlobalObjectMutableProperties", [$h‍_a => (setGlobalObjectMutableProperties = $h‍_a)]]]],["./make-safe-evaluator.js", [["makeSafeEvaluator", [$h‍_a => (makeSafeEvaluator = $h‍_a)]]]],["./whitelist.js", [["initialGlobalPropertyNames", [$h‍_a => (initialGlobalPropertyNames = $h‍_a)]]]],["./tame-function-tostring.js", [["tameFunctionToString", [$h‍_a => (tameFunctionToString = $h‍_a)]]]],["./tame-domains.js", [["tameDomains", [$h‍_a => (tameDomains = $h‍_a)]]]],["./error/tame-console.js", [["tameConsole", [$h‍_a => (tameConsole = $h‍_a)]]]],["./error/tame-error-constructor.js", [["default", [$h‍_a => (tameErrorConstructor = $h‍_a)]]]],["./error/assert.js", [["assert", [$h‍_a => (assert = $h‍_a)]],["makeAssert", [$h‍_a => (makeAssert = $h‍_a)]]]],["./environment-options.js", [["makeEnvironmentCaptor", [$h‍_a => (makeEnvironmentCaptor = $h‍_a)]]]],["./get-anonymous-intrinsics.js", [["getAnonymousIntrinsics", [$h‍_a => (getAnonymousIntrinsics = $h‍_a)]]]],["./compartment-shim.js", [["makeCompartmentConstructor", [$h‍_a => (makeCompartmentConstructor = $h‍_a)]]]]]);
8171
+
8172
+
8148
8173
 
8149
8174
 
8150
8175
 
@@ -8233,6 +8258,37 @@ const harden = makeHardener();
8233
8258
  // only ever need to be called once and that simplifying lockdown will improve
8234
8259
  // the quality of audits.
8235
8260
 
8261
+ const assertDirectEvalAvailable = () => {
8262
+ let allowed = false;
8263
+ try {
8264
+ allowed = FERAL_FUNCTION(
8265
+ 'eval',
8266
+ 'SES_changed',
8267
+ `\
8268
+ eval("SES_changed = true");
8269
+ return SES_changed;
8270
+ `)(
8271
+ FERAL_EVAL, false);
8272
+ // If we get here and SES_changed stayed false, that means the eval was sloppy
8273
+ // and indirect, which generally creates a new global.
8274
+ // We are going to throw an exception for failing to initialize SES, but
8275
+ // good neighbors clean up.
8276
+ if (!allowed) {
8277
+ delete globalThis.SES_changed;
8278
+ }
8279
+ } catch (_error) {
8280
+ // We reach here if eval is outright forbidden by a Content Security Policy.
8281
+ // We allow this for SES usage that delegates the responsibility to isolate
8282
+ // guest code to production code generation.
8283
+ allowed = true;
8284
+ }
8285
+ if (!allowed) {
8286
+ throw new TypeError(
8287
+ `SES cannot initialize unless 'eval' is the original intrinsic 'eval', suitable for direct-eval (dynamically scoped eval) (SES_DIRECT_EVAL)`);
8288
+
8289
+ }
8290
+ };
8291
+
8236
8292
  /**
8237
8293
  * @param {LockdownOptions} [options]
8238
8294
  * @returns {() => void} repairIntrinsics
@@ -8320,6 +8376,8 @@ const repairIntrinsics = (options = {}) => {
8320
8376
  // trace retained:
8321
8377
  priorLockdown.stack;
8322
8378
 
8379
+ assertDirectEvalAvailable();
8380
+
8323
8381
  /**
8324
8382
  * Because of packagers and bundlers, etc, multiple invocations of lockdown
8325
8383
  * might happen in separate instantiations of the source of this module.
@@ -8340,11 +8398,14 @@ const repairIntrinsics = (options = {}) => {
8340
8398
  const seemsToBeLockedDown = () => {
8341
8399
  return (
8342
8400
  globalThis.Function.prototype.constructor !== globalThis.Function &&
8401
+ // @ts-ignore harden is absent on globalThis type def.
8343
8402
  typeof globalThis.harden === 'function' &&
8403
+ // @ts-ignore lockdown is absent on globalThis type def.
8344
8404
  typeof globalThis.lockdown === 'function' &&
8345
8405
  globalThis.Date.prototype.constructor !== globalThis.Date &&
8346
8406
  typeof globalThis.Date.now === 'function' &&
8347
- // @ts-ignore
8407
+ // @ts-ignore does not recognize that Date constructor is a special
8408
+ // Function.
8348
8409
  // eslint-disable-next-line @endo/no-polymorphic-call
8349
8410
  is(globalThis.Date.prototype.constructor.now(), NaN));
8350
8411
 
@@ -8400,12 +8461,14 @@ const repairIntrinsics = (options = {}) => {
8400
8461
 
8401
8462
  globalThis.console = /** @type {Console} */consoleRecord.console;
8402
8463
 
8464
+ // @ts-ignore assert is absent on globalThis type def.
8403
8465
  if (errorTaming === 'unsafe' && globalThis.assert === assert) {
8404
8466
  // If errorTaming is 'unsafe' we replace the global assert with
8405
8467
  // one whose `details` template literal tag does not redact
8406
8468
  // unmarked substitution values. IOW, it blabs information that
8407
8469
  // was supposed to be secret from callers, as an aid to debugging
8408
8470
  // at a further cost in safety.
8471
+ // @ts-ignore assert is absent on globalThis type def.
8409
8472
  globalThis.assert = makeAssert(undefined, true);
8410
8473
  }
8411
8474
 
@@ -8470,6 +8533,7 @@ const repairIntrinsics = (options = {}) => {
8470
8533
  // that is portable between JS and SES), the existence of harden in global
8471
8534
  // scope signals whether such code should attempt to use harden in the
8472
8535
  // defense of its own API.
8536
+ // @ts-ignore harden not yet recognized on globalThis.
8473
8537
  globalThis.harden = harden;
8474
8538
 
8475
8539
  // Returning `true` indicates that this is a JS to SES transition.
@@ -8563,6 +8627,7 @@ assign(globalThis, {
8563
8627
  JSON: cell("JSON"),
8564
8628
  Map: cell("Map"),
8565
8629
  Math: cell("Math"),
8630
+ Number: cell("Number"),
8566
8631
  Object: cell("Object"),
8567
8632
  Promise: cell("Promise"),
8568
8633
  Proxy: cell("Proxy"),
@@ -8862,6 +8927,7 @@ assign(globalThis, {
8862
8927
  JSON: cells[0].JSON.set,
8863
8928
  Map: cells[0].Map.set,
8864
8929
  Math: cells[0].Math.set,
8930
+ Number: cells[0].Number.set,
8865
8931
  Object: cells[0].Object.set,
8866
8932
  Promise: cells[0].Promise.set,
8867
8933
  Proxy: cells[0].Proxy.set,
@@ -28,6 +28,7 @@ const {
28
28
  JSON,
29
29
  Map,
30
30
  Math,
31
+ Number,
31
32
  Object,
32
33
  Promise,
33
34
  Proxy,
@@ -37,7 +38,7 @@ const {
37
38
  String,
38
39
  WeakMap,
39
40
  WeakSet } =
40
- globalThis;$h‍_once.Array(Array);$h‍_once.Date(Date);$h‍_once.Float32Array(Float32Array);$h‍_once.JSON(JSON);$h‍_once.Map(Map);$h‍_once.Math(Math);$h‍_once.Object(Object);$h‍_once.Promise(Promise);$h‍_once.Proxy(Proxy);$h‍_once.Reflect(Reflect);$h‍_once.FERAL_REG_EXP(FERAL_REG_EXP);$h‍_once.Set(Set);$h‍_once.String(String);$h‍_once.WeakMap(WeakMap);$h‍_once.WeakSet(WeakSet);
41
+ globalThis;$h‍_once.Array(Array);$h‍_once.Date(Date);$h‍_once.Float32Array(Float32Array);$h‍_once.JSON(JSON);$h‍_once.Map(Map);$h‍_once.Math(Math);$h‍_once.Number(Number);$h‍_once.Object(Object);$h‍_once.Promise(Promise);$h‍_once.Proxy(Proxy);$h‍_once.Reflect(Reflect);$h‍_once.FERAL_REG_EXP(FERAL_REG_EXP);$h‍_once.Set(Set);$h‍_once.String(String);$h‍_once.WeakMap(WeakMap);$h‍_once.WeakSet(WeakSet);
41
42
 
42
43
  const {
43
44
  // The feral Error constructor is safe for internal use, but must not be
@@ -2733,7 +2734,10 @@ function NativeErrorPrototype(constructor) {
2733
2734
  message: 'string',
2734
2735
  name: 'string',
2735
2736
  // Redundantly present only on v8. Safe to remove.
2736
- toString: false };
2737
+ toString: false,
2738
+ // Superfluously present in some versions of V8.
2739
+ // https://github.com/tc39/notes/blob/master/meetings/2021-10/oct-26.md#:~:text=However%2C%20Chrome%2093,and%20node%2016.11.
2740
+ cause: false };
2737
2741
 
2738
2742
  }
2739
2743
 
@@ -2997,7 +3001,10 @@ const whitelist = {
2997
3001
  // Seen on FF Nightly 88.0a1
2998
3002
  at: false,
2999
3003
  // Seen on FF and XS
3000
- stack: false },
3004
+ stack: false,
3005
+ // Superfluously present in some versions of V8.
3006
+ // https://github.com/tc39/notes/blob/master/meetings/2021-10/oct-26.md#:~:text=However%2C%20Chrome%2093,and%20node%2016.11.
3007
+ cause: false },
3001
3008
 
3002
3009
 
3003
3010
  // NativeError
@@ -6557,7 +6564,11 @@ optGetStackString = undefined) =>
6557
6564
  }
6558
6565
 
6559
6566
  // Browser
6560
- if (errorTrapping !== 'none' && globalThis.window !== undefined) {
6567
+ if (
6568
+ errorTrapping !== 'none' &&
6569
+ globalThis.window !== undefined &&
6570
+ globalThis.window.addEventListener !== undefined)
6571
+ {
6561
6572
  // eslint-disable-next-line @endo/no-polymorphic-call
6562
6573
  globalThis.window.addEventListener('error', (event) => {
6563
6574
  // eslint-disable-next-line @endo/no-polymorphic-call
@@ -7709,7 +7720,8 @@ const tameFunctionToString = () => {
7709
7720
  })
7710
7721
  ,
7711
7722
  // === functors[35] ===
7712
- (({ imports: $h‍_imports, liveVar: $h‍_live, onceVar: $h‍_once, }) => { let String,TypeError,defineProperty,getOwnPropertyNames,isObject,regexpExec,assert;$h‍_imports([["./commons.js", [["String", [$h‍_a => (String = $h‍_a)]],["TypeError", [$h‍_a => (TypeError = $h‍_a)]],["defineProperty", [$h‍_a => (defineProperty = $h‍_a)]],["getOwnPropertyNames", [$h‍_a => (getOwnPropertyNames = $h‍_a)]],["isObject", [$h‍_a => (isObject = $h‍_a)]],["regexpExec", [$h‍_a => (regexpExec = $h‍_a)]]]],["./error/assert.js", [["assert", [$h‍_a => (assert = $h‍_a)]]]]]);
7723
+ (({ imports: $h‍_imports, liveVar: $h‍_live, onceVar: $h‍_once, }) => { let Number,String,TypeError,defineProperty,getOwnPropertyNames,isObject,regexpExec,assert;$h‍_imports([["./commons.js", [["Number", [$h‍_a => (Number = $h‍_a)]],["String", [$h‍_a => (String = $h‍_a)]],["TypeError", [$h‍_a => (TypeError = $h‍_a)]],["defineProperty", [$h‍_a => (defineProperty = $h‍_a)]],["getOwnPropertyNames", [$h‍_a => (getOwnPropertyNames = $h‍_a)]],["isObject", [$h‍_a => (isObject = $h‍_a)]],["regexpExec", [$h‍_a => (regexpExec = $h‍_a)]]]],["./error/assert.js", [["assert", [$h‍_a => (assert = $h‍_a)]]]]]);
7724
+
7713
7725
 
7714
7726
 
7715
7727
 
@@ -7743,10 +7755,15 @@ const tamedMethods = {
7743
7755
  }
7744
7756
  assert(s === that, d`expected ${q(s)} and ${q(that)} to compare`);
7745
7757
  return 0;
7758
+ },
7759
+
7760
+ toString() {
7761
+ return `${this}`;
7746
7762
  } };
7747
7763
 
7748
7764
 
7749
7765
  const nonLocaleCompare = tamedMethods.localeCompare;
7766
+ const numberToString = tamedMethods.toString;
7750
7767
 
7751
7768
  function tameLocaleMethods(intrinsics, localeTaming = 'safe') {
7752
7769
  if (localeTaming !== 'safe' && localeTaming !== 'unsafe') {
@@ -7781,6 +7798,12 @@ function tameLocaleMethods(intrinsics, localeTaming = 'safe') {
7781
7798
  }
7782
7799
  }
7783
7800
  }
7801
+
7802
+ // Numbers are special because toString accepts a radix instead of ignoring
7803
+ // all of the arguments that we would otherwise forward.
7804
+ defineProperty(Number.prototype, 'toLocaleString', {
7805
+ value: numberToString });
7806
+
7784
7807
  }$h‍_once.default(tameLocaleMethods);
7785
7808
  })
7786
7809
  ,
@@ -8144,7 +8167,9 @@ markVirtualizedNativeFunction)
8144
8167
  })
8145
8168
  ,
8146
8169
  // === functors[39] ===
8147
- (({ imports: $h‍_imports, liveVar: $h‍_live, onceVar: $h‍_once, }) => { let TypeError,arrayFilter,arrayMap,globalThis,is,ownKeys,stringSplit,enJoin,makeHardener,makeIntrinsicsCollector,whitelistIntrinsics,tameFunctionConstructors,tameDateConstructor,tameMathObject,tameRegExpConstructor,enablePropertyOverrides,tameLocaleMethods,setGlobalObjectConstantProperties,setGlobalObjectMutableProperties,makeSafeEvaluator,initialGlobalPropertyNames,tameFunctionToString,tameDomains,tameConsole,tameErrorConstructor,assert,makeAssert,makeEnvironmentCaptor,getAnonymousIntrinsics,makeCompartmentConstructor;$h‍_imports([["./commons.js", [["TypeError", [$h‍_a => (TypeError = $h‍_a)]],["arrayFilter", [$h‍_a => (arrayFilter = $h‍_a)]],["arrayMap", [$h‍_a => (arrayMap = $h‍_a)]],["globalThis", [$h‍_a => (globalThis = $h‍_a)]],["is", [$h‍_a => (is = $h‍_a)]],["ownKeys", [$h‍_a => (ownKeys = $h‍_a)]],["stringSplit", [$h‍_a => (stringSplit = $h‍_a)]]]],["./error/stringify-utils.js", [["enJoin", [$h‍_a => (enJoin = $h‍_a)]]]],["./make-hardener.js", [["makeHardener", [$h‍_a => (makeHardener = $h‍_a)]]]],["./intrinsics.js", [["makeIntrinsicsCollector", [$h‍_a => (makeIntrinsicsCollector = $h‍_a)]]]],["./whitelist-intrinsics.js", [["default", [$h‍_a => (whitelistIntrinsics = $h‍_a)]]]],["./tame-function-constructors.js", [["default", [$h‍_a => (tameFunctionConstructors = $h‍_a)]]]],["./tame-date-constructor.js", [["default", [$h‍_a => (tameDateConstructor = $h‍_a)]]]],["./tame-math-object.js", [["default", [$h‍_a => (tameMathObject = $h‍_a)]]]],["./tame-regexp-constructor.js", [["default", [$h‍_a => (tameRegExpConstructor = $h‍_a)]]]],["./enable-property-overrides.js", [["default", [$h‍_a => (enablePropertyOverrides = $h‍_a)]]]],["./tame-locale-methods.js", [["default", [$h‍_a => (tameLocaleMethods = $h‍_a)]]]],["./global-object.js", [["setGlobalObjectConstantProperties", [$h‍_a => (setGlobalObjectConstantProperties = $h‍_a)]],["setGlobalObjectMutableProperties", [$h‍_a => (setGlobalObjectMutableProperties = $h‍_a)]]]],["./make-safe-evaluator.js", [["makeSafeEvaluator", [$h‍_a => (makeSafeEvaluator = $h‍_a)]]]],["./whitelist.js", [["initialGlobalPropertyNames", [$h‍_a => (initialGlobalPropertyNames = $h‍_a)]]]],["./tame-function-tostring.js", [["tameFunctionToString", [$h‍_a => (tameFunctionToString = $h‍_a)]]]],["./tame-domains.js", [["tameDomains", [$h‍_a => (tameDomains = $h‍_a)]]]],["./error/tame-console.js", [["tameConsole", [$h‍_a => (tameConsole = $h‍_a)]]]],["./error/tame-error-constructor.js", [["default", [$h‍_a => (tameErrorConstructor = $h‍_a)]]]],["./error/assert.js", [["assert", [$h‍_a => (assert = $h‍_a)]],["makeAssert", [$h‍_a => (makeAssert = $h‍_a)]]]],["./environment-options.js", [["makeEnvironmentCaptor", [$h‍_a => (makeEnvironmentCaptor = $h‍_a)]]]],["./get-anonymous-intrinsics.js", [["getAnonymousIntrinsics", [$h‍_a => (getAnonymousIntrinsics = $h‍_a)]]]],["./compartment-shim.js", [["makeCompartmentConstructor", [$h‍_a => (makeCompartmentConstructor = $h‍_a)]]]]]);
8170
+ (({ imports: $h‍_imports, liveVar: $h‍_live, onceVar: $h‍_once, }) => { let FERAL_FUNCTION,FERAL_EVAL,TypeError,arrayFilter,arrayMap,globalThis,is,ownKeys,stringSplit,enJoin,makeHardener,makeIntrinsicsCollector,whitelistIntrinsics,tameFunctionConstructors,tameDateConstructor,tameMathObject,tameRegExpConstructor,enablePropertyOverrides,tameLocaleMethods,setGlobalObjectConstantProperties,setGlobalObjectMutableProperties,makeSafeEvaluator,initialGlobalPropertyNames,tameFunctionToString,tameDomains,tameConsole,tameErrorConstructor,assert,makeAssert,makeEnvironmentCaptor,getAnonymousIntrinsics,makeCompartmentConstructor;$h‍_imports([["./commons.js", [["FERAL_FUNCTION", [$h‍_a => (FERAL_FUNCTION = $h‍_a)]],["FERAL_EVAL", [$h‍_a => (FERAL_EVAL = $h‍_a)]],["TypeError", [$h‍_a => (TypeError = $h‍_a)]],["arrayFilter", [$h‍_a => (arrayFilter = $h‍_a)]],["arrayMap", [$h‍_a => (arrayMap = $h‍_a)]],["globalThis", [$h‍_a => (globalThis = $h‍_a)]],["is", [$h‍_a => (is = $h‍_a)]],["ownKeys", [$h‍_a => (ownKeys = $h‍_a)]],["stringSplit", [$h‍_a => (stringSplit = $h‍_a)]]]],["./error/stringify-utils.js", [["enJoin", [$h‍_a => (enJoin = $h‍_a)]]]],["./make-hardener.js", [["makeHardener", [$h‍_a => (makeHardener = $h‍_a)]]]],["./intrinsics.js", [["makeIntrinsicsCollector", [$h‍_a => (makeIntrinsicsCollector = $h‍_a)]]]],["./whitelist-intrinsics.js", [["default", [$h‍_a => (whitelistIntrinsics = $h‍_a)]]]],["./tame-function-constructors.js", [["default", [$h‍_a => (tameFunctionConstructors = $h‍_a)]]]],["./tame-date-constructor.js", [["default", [$h‍_a => (tameDateConstructor = $h‍_a)]]]],["./tame-math-object.js", [["default", [$h‍_a => (tameMathObject = $h‍_a)]]]],["./tame-regexp-constructor.js", [["default", [$h‍_a => (tameRegExpConstructor = $h‍_a)]]]],["./enable-property-overrides.js", [["default", [$h‍_a => (enablePropertyOverrides = $h‍_a)]]]],["./tame-locale-methods.js", [["default", [$h‍_a => (tameLocaleMethods = $h‍_a)]]]],["./global-object.js", [["setGlobalObjectConstantProperties", [$h‍_a => (setGlobalObjectConstantProperties = $h‍_a)]],["setGlobalObjectMutableProperties", [$h‍_a => (setGlobalObjectMutableProperties = $h‍_a)]]]],["./make-safe-evaluator.js", [["makeSafeEvaluator", [$h‍_a => (makeSafeEvaluator = $h‍_a)]]]],["./whitelist.js", [["initialGlobalPropertyNames", [$h‍_a => (initialGlobalPropertyNames = $h‍_a)]]]],["./tame-function-tostring.js", [["tameFunctionToString", [$h‍_a => (tameFunctionToString = $h‍_a)]]]],["./tame-domains.js", [["tameDomains", [$h‍_a => (tameDomains = $h‍_a)]]]],["./error/tame-console.js", [["tameConsole", [$h‍_a => (tameConsole = $h‍_a)]]]],["./error/tame-error-constructor.js", [["default", [$h‍_a => (tameErrorConstructor = $h‍_a)]]]],["./error/assert.js", [["assert", [$h‍_a => (assert = $h‍_a)]],["makeAssert", [$h‍_a => (makeAssert = $h‍_a)]]]],["./environment-options.js", [["makeEnvironmentCaptor", [$h‍_a => (makeEnvironmentCaptor = $h‍_a)]]]],["./get-anonymous-intrinsics.js", [["getAnonymousIntrinsics", [$h‍_a => (getAnonymousIntrinsics = $h‍_a)]]]],["./compartment-shim.js", [["makeCompartmentConstructor", [$h‍_a => (makeCompartmentConstructor = $h‍_a)]]]]]);
8171
+
8172
+
8148
8173
 
8149
8174
 
8150
8175
 
@@ -8233,6 +8258,37 @@ const harden = makeHardener();
8233
8258
  // only ever need to be called once and that simplifying lockdown will improve
8234
8259
  // the quality of audits.
8235
8260
 
8261
+ const assertDirectEvalAvailable = () => {
8262
+ let allowed = false;
8263
+ try {
8264
+ allowed = FERAL_FUNCTION(
8265
+ 'eval',
8266
+ 'SES_changed',
8267
+ `\
8268
+ eval("SES_changed = true");
8269
+ return SES_changed;
8270
+ `)(
8271
+ FERAL_EVAL, false);
8272
+ // If we get here and SES_changed stayed false, that means the eval was sloppy
8273
+ // and indirect, which generally creates a new global.
8274
+ // We are going to throw an exception for failing to initialize SES, but
8275
+ // good neighbors clean up.
8276
+ if (!allowed) {
8277
+ delete globalThis.SES_changed;
8278
+ }
8279
+ } catch (_error) {
8280
+ // We reach here if eval is outright forbidden by a Content Security Policy.
8281
+ // We allow this for SES usage that delegates the responsibility to isolate
8282
+ // guest code to production code generation.
8283
+ allowed = true;
8284
+ }
8285
+ if (!allowed) {
8286
+ throw new TypeError(
8287
+ `SES cannot initialize unless 'eval' is the original intrinsic 'eval', suitable for direct-eval (dynamically scoped eval) (SES_DIRECT_EVAL)`);
8288
+
8289
+ }
8290
+ };
8291
+
8236
8292
  /**
8237
8293
  * @param {LockdownOptions} [options]
8238
8294
  * @returns {() => void} repairIntrinsics
@@ -8320,6 +8376,8 @@ const repairIntrinsics = (options = {}) => {
8320
8376
  // trace retained:
8321
8377
  priorLockdown.stack;
8322
8378
 
8379
+ assertDirectEvalAvailable();
8380
+
8323
8381
  /**
8324
8382
  * Because of packagers and bundlers, etc, multiple invocations of lockdown
8325
8383
  * might happen in separate instantiations of the source of this module.
@@ -8340,11 +8398,14 @@ const repairIntrinsics = (options = {}) => {
8340
8398
  const seemsToBeLockedDown = () => {
8341
8399
  return (
8342
8400
  globalThis.Function.prototype.constructor !== globalThis.Function &&
8401
+ // @ts-ignore harden is absent on globalThis type def.
8343
8402
  typeof globalThis.harden === 'function' &&
8403
+ // @ts-ignore lockdown is absent on globalThis type def.
8344
8404
  typeof globalThis.lockdown === 'function' &&
8345
8405
  globalThis.Date.prototype.constructor !== globalThis.Date &&
8346
8406
  typeof globalThis.Date.now === 'function' &&
8347
- // @ts-ignore
8407
+ // @ts-ignore does not recognize that Date constructor is a special
8408
+ // Function.
8348
8409
  // eslint-disable-next-line @endo/no-polymorphic-call
8349
8410
  is(globalThis.Date.prototype.constructor.now(), NaN));
8350
8411
 
@@ -8400,12 +8461,14 @@ const repairIntrinsics = (options = {}) => {
8400
8461
 
8401
8462
  globalThis.console = /** @type {Console} */consoleRecord.console;
8402
8463
 
8464
+ // @ts-ignore assert is absent on globalThis type def.
8403
8465
  if (errorTaming === 'unsafe' && globalThis.assert === assert) {
8404
8466
  // If errorTaming is 'unsafe' we replace the global assert with
8405
8467
  // one whose `details` template literal tag does not redact
8406
8468
  // unmarked substitution values. IOW, it blabs information that
8407
8469
  // was supposed to be secret from callers, as an aid to debugging
8408
8470
  // at a further cost in safety.
8471
+ // @ts-ignore assert is absent on globalThis type def.
8409
8472
  globalThis.assert = makeAssert(undefined, true);
8410
8473
  }
8411
8474
 
@@ -8470,6 +8533,7 @@ const repairIntrinsics = (options = {}) => {
8470
8533
  // that is portable between JS and SES), the existence of harden in global
8471
8534
  // scope signals whether such code should attempt to use harden in the
8472
8535
  // defense of its own API.
8536
+ // @ts-ignore harden not yet recognized on globalThis.
8473
8537
  globalThis.harden = harden;
8474
8538
 
8475
8539
  // Returning `true` indicates that this is a JS to SES transition.
@@ -8563,6 +8627,7 @@ assign(globalThis, {
8563
8627
  JSON: cell("JSON"),
8564
8628
  Map: cell("Map"),
8565
8629
  Math: cell("Math"),
8630
+ Number: cell("Number"),
8566
8631
  Object: cell("Object"),
8567
8632
  Promise: cell("Promise"),
8568
8633
  Proxy: cell("Proxy"),
@@ -8862,6 +8927,7 @@ assign(globalThis, {
8862
8927
  JSON: cells[0].JSON.set,
8863
8928
  Map: cells[0].Map.set,
8864
8929
  Math: cells[0].Math.set,
8930
+ Number: cells[0].Number.set,
8865
8931
  Object: cells[0].Object.set,
8866
8932
  Promise: cells[0].Promise.set,
8867
8933
  Proxy: cells[0].Proxy.set,