ses 1.9.1 → 1.10.0

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/types.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @file Types of the SES environment
2
+ * @module Types of the SES environment
3
3
  */
4
4
 
5
5
  /* eslint-disable no-restricted-globals, vars-on-top, no-var */
@@ -24,6 +24,7 @@ export interface RepairOptions {
24
24
  localeTaming?: 'safe' | 'unsafe';
25
25
  consoleTaming?: 'safe' | 'unsafe';
26
26
  errorTrapping?: 'platform' | 'exit' | 'abort' | 'report' | 'none';
27
+ reporting?: 'platform' | 'console' | 'none';
27
28
  unhandledRejectionTrapping?: 'report' | 'none';
28
29
  errorTaming?: 'safe' | 'unsafe' | 'unsafe-debug';
29
30
  dateTaming?: 'safe' | 'unsafe'; // deprecated
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ses",
3
- "version": "1.9.1",
3
+ "version": "1.10.0",
4
4
  "description": "Hardened JavaScript for Fearless Cooperation",
5
5
  "keywords": [
6
6
  "lockdown",
@@ -78,12 +78,12 @@
78
78
  "postpack": "git clean -f '*.d.ts*' '*.tsbuildinfo'"
79
79
  },
80
80
  "dependencies": {
81
- "@endo/env-options": "^1.1.7"
81
+ "@endo/env-options": "^1.1.8"
82
82
  },
83
83
  "devDependencies": {
84
- "@endo/compartment-mapper": "^1.3.1",
85
- "@endo/module-source": "^1.1.1",
86
- "@endo/test262-runner": "^0.1.42",
84
+ "@endo/compartment-mapper": "^1.4.0",
85
+ "@endo/module-source": "^1.1.2",
86
+ "@endo/test262-runner": "^0.1.43",
87
87
  "ava": "^6.1.3",
88
88
  "babel-eslint": "^10.1.0",
89
89
  "c8": "^7.14.0",
@@ -93,10 +93,10 @@
93
93
  "eslint-config-prettier": "^9.1.0",
94
94
  "eslint-plugin-eslint-comments": "^3.2.0",
95
95
  "eslint-plugin-import": "^2.29.1",
96
- "prettier": "^3.2.5",
96
+ "prettier": "^3.3.3",
97
97
  "terser": "^5.16.6",
98
98
  "tsd": "^0.31.2",
99
- "typescript": "~5.6.2"
99
+ "typescript": "~5.6.3"
100
100
  },
101
101
  "files": [
102
102
  "./*.d.ts",
@@ -203,5 +203,5 @@
203
203
  "typeCoverage": {
204
204
  "atLeast": 81.17
205
205
  },
206
- "gitHead": "c242c28a68d1af29475150e44b5f3e9d0feda8cd"
206
+ "gitHead": "5486ed1f238104716b6a8321b977fbc508ef80e1"
207
207
  }
@@ -0,0 +1,69 @@
1
+ import { objectHasOwnProperty } from './commons.js';
2
+
3
+ /**
4
+ * @import {Reporter} from './reporting-types.js'
5
+ */
6
+
7
+ /**
8
+ * Delete `obj[prop]` or at least make it harmless.
9
+ *
10
+ * If the property was not expected, then emit a reporter-dependent warning
11
+ * to bring attention to this case, so someone can determine what to do with it.
12
+ *
13
+ * If the property to be deleted is a function's `.prototype` property, this
14
+ * will normally be because the function was supposed to be a
15
+ * - builtin method or non-constructor function
16
+ * - arrow function
17
+ * - concise method
18
+ *
19
+ * all of whom are not supposed to have a `.prototype` property. Nevertheless,
20
+ * on some platforms (like older versions of Hermes), or as a result of
21
+ * some shim-based mods to the primordials (like core-js?), some of these
22
+ * functions may accidentally be more like `function` functions with
23
+ * an undeletable `.prototype` property. In these cases, if we can
24
+ * set the value of that bogus `.prototype` property to `undefined`,
25
+ * we do so, issuing a warning, rather than failing to initialize ses.
26
+ *
27
+ * @param {object} obj
28
+ * @param {PropertyKey} prop
29
+ * @param {boolean} known If deletion is expected, don't warn
30
+ * @param {string} subPath Used for warning messages
31
+ * @param {Reporter} reporter Where to issue warning or error.
32
+ * @returns {void}
33
+ */
34
+ export const cauterizeProperty = (
35
+ obj,
36
+ prop,
37
+ known,
38
+ subPath,
39
+ { warn, error },
40
+ ) => {
41
+ // Either the object lacks a permit or the object doesn't match the
42
+ // permit.
43
+ // If the permit is specifically false, not merely undefined,
44
+ // this is a property we expect to see because we know it exists in
45
+ // some environments and we have expressly decided to exclude it.
46
+ // Any other disallowed property is one we have not audited and we log
47
+ // that we are removing it so we know to look into it, as happens when
48
+ // the language evolves new features to existing intrinsics.
49
+ if (!known) {
50
+ warn(`Removing ${subPath}`);
51
+ }
52
+ try {
53
+ delete obj[prop];
54
+ } catch (err) {
55
+ if (objectHasOwnProperty(obj, prop)) {
56
+ if (typeof obj === 'function' && prop === 'prototype') {
57
+ obj.prototype = undefined;
58
+ if (obj.prototype === undefined) {
59
+ warn(`Tolerating undeletable ${subPath} === undefined`);
60
+ return;
61
+ }
62
+ }
63
+ error(`failed to delete ${subPath}`, err);
64
+ } else {
65
+ error(`deleting ${subPath} threw`, err);
66
+ }
67
+ throw err;
68
+ }
69
+ };
@@ -2,12 +2,18 @@ import { globalThis } from './commons.js';
2
2
  import { makeCompartmentConstructor } from './compartment.js';
3
3
  import { tameFunctionToString } from './tame-function-tostring.js';
4
4
  import { getGlobalIntrinsics } from './intrinsics.js';
5
+ import { chooseReporter } from './reporting.js';
5
6
 
6
7
  const markVirtualizedNativeFunction = tameFunctionToString();
7
8
 
9
+ const muteReporter = chooseReporter('none');
10
+
8
11
  // @ts-ignore Compartment is definitely on globalThis.
9
12
  globalThis.Compartment = makeCompartmentConstructor(
10
13
  makeCompartmentConstructor,
11
- getGlobalIntrinsics(globalThis),
14
+ // Any reporting that would need to be done should have already been done
15
+ // during `lockdown()`.
16
+ // See https://github.com/endojs/endo/pull/2624#discussion_r1840979770
17
+ getGlobalIntrinsics(globalThis, muteReporter),
12
18
  markVirtualizedNativeFunction,
13
19
  );
@@ -23,8 +23,10 @@ import {
23
23
  severeEnablements,
24
24
  } from './enablements.js';
25
25
 
26
+ /** @import {Reporter} from './reporting-types.js' */
27
+
26
28
  /**
27
- * For a special set of properties defined in the `enablement` whitelist,
29
+ * For a special set of properties defined in the `enablement` list,
28
30
  * `enablePropertyOverrides` ensures that the effect of freezing does not
29
31
  * suppress the ability to override these properties on derived objects by
30
32
  * simple assignment.
@@ -75,11 +77,13 @@ import {
75
77
  *
76
78
  * @param {Record<string, any>} intrinsics
77
79
  * @param {'min' | 'moderate' | 'severe'} overrideTaming
80
+ * @param {Reporter} reporter
78
81
  * @param {Iterable<string | symbol>} [overrideDebug]
79
82
  */
80
83
  export default function enablePropertyOverrides(
81
84
  intrinsics,
82
85
  overrideTaming,
86
+ { warn },
83
87
  overrideDebug = [],
84
88
  ) {
85
89
  const debugProperties = new Set(overrideDebug);
@@ -109,8 +113,7 @@ export default function enablePropertyOverrides(
109
113
  this[prop] = newValue;
110
114
  } else {
111
115
  if (isDebug) {
112
- // eslint-disable-next-line @endo/no-polymorphic-call
113
- console.error(TypeError(`Override property ${prop}`));
116
+ warn(TypeError(`Override property ${prop}`));
114
117
  }
115
118
  defineProperty(this, prop, {
116
119
  value: newValue,
@@ -1,7 +1,7 @@
1
1
  import { toStringTagSymbol, iteratorSymbol } from './commons.js';
2
2
 
3
3
  /**
4
- * @file Exports {@code enablements}, a recursively defined
4
+ * @module Exports {@code enablements}, a recursively defined
5
5
  * JSON record defining the optimum set of intrinsics properties
6
6
  * that need to be "repaired" before hardening is applied on
7
7
  * enviromments subject to the override mistake.
@@ -62,9 +62,9 @@ Before repair or `lockdown`, we assume there is some prior "system" console boun
62
62
 
63
63
  The default `{ consoleTaming: 'safe' }` setting replaces the system console with a root console that does use all these side tables to generate a more informative log. This root console wraps the prior system console. This root console outputs its log information only by invoking this wrapped system console, which therefore determines how this log information is made available to the external world. To support determinism, we will also need to support a no-op console setting, as explained at [deterministic handling of adversarial code calling console.log with a Proxy #1852](https://github.com/Agoric/agoric-sdk/issues/1852) and [Need no-op console setting for determinism #487](https://github.com/Agoric/SES-shim/issues/487).
64
64
 
65
- SES considers both `assert` and `console` to be powerful objects, appearing initially in the start compartment, and not whitelisted for implicit propagation to created compartments. Rather, we recommend an endowment pattern where the global `assert` is passed forward as is, but only filtered forms of the `console` are. As compartments create each other in a tree, they create a corresponding filtering tree of consoles. Information sent to any compartment's console is then sent up the filtering tree. Only information that survives all the filters in its path arrive at the root console, producing log output. The others have no effect. Given the expected pattern of a compartment per package, the per-compartment console filter is effectly a topic filter, treating the package identity as a topic. We plan to also support coordinated stack-frame filters, as explained at [Need source-prefix-based stackframe filter #488](https://github.com/Agoric/SES-shim/issues/488).
65
+ SES considers both `assert` and `console` to be powerful objects, appearing initially in the start compartment, and not permitted for implicit propagation to created compartments. Rather, we recommend an endowment pattern where the global `assert` is passed forward as-is, but only filtered forms of the `console` are. As compartments create each other in a tree, they create a corresponding filtering tree of consoles. Information sent to any compartment's console is then sent up the filtering tree. Only information that survives all the filters in its path arrive at the root console, producing log output. The others have no effect. Given the expected pattern of a compartment per package, the per-compartment console filter is effectly a topic filter, treating the package identity as a topic. We plan to also support coordinated stack-frame filters, as explained at [Need source-prefix-based stackframe filter #488](https://github.com/Agoric/SES-shim/issues/488).
66
66
 
67
- For security and determinism, we normally reason from the *in-band frame of reference* where the console logging output does not exist, is not an effect, and `console` operations are write-only. Within this frame of reference, the `assert` and `console` powers are not very powerful. They are almost as safe as the whitelisted powerless shared primordials, which is why we're willing to recommend this endowment pattern be habitual.
67
+ For security and determinism, we normally reason from the *in-band frame of reference* where the console logging output does not exist, is not an effect, and `console` operations are write-only. Within this frame of reference, the `assert` and `console` powers are not very powerful. They are almost as safe as the permitted, powerless, shared primordials, which is why we're willing to recommend this endowment pattern be habitual.
68
68
 
69
69
  ## Hiding and Revealing Distributed Diagnostic Information
70
70
 
@@ -31,7 +31,7 @@ import {
31
31
  // For our internal debugging purposes, uncomment
32
32
  // const internalDebugConsole = console;
33
33
 
34
- // The whitelists of console methods, from:
34
+ // The permitted console methods, from:
35
35
  // Whatwg "living standard" https://console.spec.whatwg.org/
36
36
  // Node https://nodejs.org/dist/latest-v14.x/docs/api/console.html
37
37
  // MDN https://developer.mozilla.org/en-US/docs/Web/API/Console_API
@@ -110,7 +110,7 @@ export const consoleOtherMethods = freeze([
110
110
  ]);
111
111
 
112
112
  /** @type {readonly [ConsoleProps, LogSeverity | undefined][]} */
113
- const consoleWhitelist = freeze([
113
+ const consoleMethodPermits = freeze([
114
114
  ...consoleLevelMethods,
115
115
  ...consoleOtherMethods,
116
116
  ]);
@@ -118,8 +118,8 @@ const consoleWhitelist = freeze([
118
118
  /**
119
119
  * consoleOmittedProperties is currently unused. I record and maintain it here
120
120
  * with the intention that it be treated like the `false` entries in the main
121
- * SES whitelist: that seeing these on the original console is expected, but
122
- * seeing anything else that's outside the whitelist is surprising and should
121
+ * SES permits: that seeing these on the original console is expected, but
122
+ * seeing anything else that's outside the permits is surprising and should
123
123
  * provide a diagnostic.
124
124
  *
125
125
  * const consoleOmittedProperties = freeze([
@@ -158,7 +158,7 @@ export const makeLoggingConsoleKit = (
158
158
  let logArray = [];
159
159
 
160
160
  const loggingConsole = fromEntries(
161
- arrayMap(consoleWhitelist, ([name, _]) => {
161
+ arrayMap(consoleMethodPermits, ([name, _]) => {
162
162
  // Use an arrow function so that it doesn't come with its own name in
163
163
  // its printed form. Instead, we're hoping that tooling uses only
164
164
  // the `.name` property set below.
@@ -508,11 +508,11 @@ freeze(defineCausalConsoleFromLogger);
508
508
  /** @type {FilterConsole} */
509
509
  export const filterConsole = (baseConsole, filter, _topic = undefined) => {
510
510
  // TODO do something with optional topic string
511
- const whitelist = arrayFilter(
512
- consoleWhitelist,
511
+ const methodPermits = arrayFilter(
512
+ consoleMethodPermits,
513
513
  ([name, _]) => name in baseConsole,
514
514
  );
515
- const methods = arrayMap(whitelist, ([name, severity]) => {
515
+ const methods = arrayMap(methodPermits, ([name, severity]) => {
516
516
  /**
517
517
  * @param {...any} args
518
518
  */
@@ -62,7 +62,7 @@
62
62
  /**
63
63
  * @callback MakeLoggingConsoleKit
64
64
  *
65
- * A logging console just accumulates the contents of all whitelisted calls,
65
+ * A logging console just accumulates the contents of all permitted calls,
66
66
  * making them available to callers of `takeLog()`. Calling `takeLog()`
67
67
  * consumes these, so later calls to `takeLog()` will only provide a log of
68
68
  * calls that have happened since then.
@@ -19,8 +19,8 @@ import {
19
19
  TypeError,
20
20
  } from '../commons.js';
21
21
 
22
- // Whitelist names from https://v8.dev/docs/stack-trace-api
23
- // Whitelisting only the names used by error-stack-shim/src/v8StackFrames
22
+ // Permit names from https://v8.dev/docs/stack-trace-api
23
+ // Permiting only the names used by error-stack-shim/src/v8StackFrames
24
24
  // callSiteToFrame to shim the error stack proposal.
25
25
  const safeV8CallSiteMethodNames = [
26
26
  // suppress 'getThis' definitely
@@ -45,7 +45,7 @@ const safeV8CallSiteMethodNames = [
45
45
  'getPosition',
46
46
  'getScriptNameOrSourceURL',
47
47
 
48
- 'toString', // TODO replace to use only whitelisted info
48
+ 'toString', // TODO replace to use only permitted info
49
49
  ];
50
50
 
51
51
  // TODO this is a ridiculously expensive way to attenuate callsites.
@@ -121,7 +121,7 @@ export const setGlobalObjectMutableProperties = (
121
121
  ),
122
122
  );
123
123
 
124
- // TODO These should still be tamed according to the whitelist before
124
+ // TODO These should still be tamed according to the permits before
125
125
  // being made available.
126
126
  for (const [name, value] of entries(perCompartmentGlobals)) {
127
127
  defineProperty(globalObject, name, {
package/src/intrinsics.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { cauterizeProperty } from './cauterize-property.js';
1
2
  import {
2
3
  TypeError,
3
4
  WeakSet,
@@ -23,12 +24,16 @@ import {
23
24
  permitted,
24
25
  } from './permits.js';
25
26
 
27
+ /**
28
+ * @import {Reporter} from './reporting-types.js'
29
+ */
30
+
26
31
  const isFunction = obj => typeof obj === 'function';
27
32
 
28
33
  // Like defineProperty, but throws if it would modify an existing property.
29
34
  // We use this to ensure that two conflicting attempts to define the same
30
35
  // property throws, causing SES initialization to fail. Otherwise, a
31
- // conflict between, for example, two of SES's internal whitelists might
36
+ // conflict between, for example, two of SES's internal permits might
32
37
  // get masked as one overwrites the other. Accordingly, the thrown error
33
38
  // complains of a "Conflicting definition".
34
39
  function initProperty(obj, name, desc) {
@@ -71,7 +76,10 @@ function sampleGlobals(globalObject, newPropertyNames) {
71
76
  return newIntrinsics;
72
77
  }
73
78
 
74
- export const makeIntrinsicsCollector = () => {
79
+ /**
80
+ * @param {Reporter} reporter
81
+ */
82
+ export const makeIntrinsicsCollector = reporter => {
75
83
  /** @type {Record<any, any>} */
76
84
  const intrinsics = create(null);
77
85
  let pseudoNatives;
@@ -82,7 +90,7 @@ export const makeIntrinsicsCollector = () => {
82
90
  freeze(addIntrinsics);
83
91
 
84
92
  // For each intrinsic, if it has a `.prototype` property, use the
85
- // whitelist to find out the intrinsic name for that prototype and add it
93
+ // permits to find out the intrinsic name for that prototype and add it
86
94
  // to the intrinsics.
87
95
  const completePrototypes = () => {
88
96
  for (const [name, intrinsic] of entries(intrinsics)) {
@@ -96,17 +104,25 @@ export const makeIntrinsicsCollector = () => {
96
104
  }
97
105
  const permit = permitted[name];
98
106
  if (typeof permit !== 'object') {
99
- throw TypeError(`Expected permit object at whitelist.${name}`);
107
+ throw TypeError(`Expected permit object at permits.${name}`);
100
108
  }
101
109
  const namePrototype = permit.prototype;
102
110
  if (!namePrototype) {
103
- throw TypeError(`${name}.prototype property not whitelisted`);
111
+ cauterizeProperty(
112
+ intrinsic,
113
+ 'prototype',
114
+ false,
115
+ `${name}.prototype`,
116
+ reporter,
117
+ );
118
+ // eslint-disable-next-line no-continue
119
+ continue;
104
120
  }
105
121
  if (
106
122
  typeof namePrototype !== 'string' ||
107
123
  !objectHasOwnProperty(permitted, namePrototype)
108
124
  ) {
109
- throw TypeError(`Unrecognized ${name}.prototype whitelist entry`);
125
+ throw TypeError(`Unrecognized ${name}.prototype permits entry`);
110
126
  }
111
127
  const intrinsicPrototype = intrinsic.prototype;
112
128
  if (objectHasOwnProperty(intrinsics, namePrototype)) {
@@ -155,7 +171,7 @@ export const makeIntrinsicsCollector = () => {
155
171
  /**
156
172
  * getGlobalIntrinsics()
157
173
  * Doesn't tame, delete, or modify anything. Samples globalObject to create an
158
- * intrinsics record containing only the whitelisted global variables, listed
174
+ * intrinsics record containing only the permitted global variables, listed
159
175
  * by the intrinsic names appropriate for new globals, i.e., the globals of
160
176
  * newly constructed compartments.
161
177
  *
@@ -164,9 +180,11 @@ export const makeIntrinsicsCollector = () => {
164
180
  * *original* unsafe (feral, untamed) bindings of these global variables.
165
181
  *
166
182
  * @param {object} globalObject
183
+ * @param {Reporter} reporter
167
184
  */
168
- export const getGlobalIntrinsics = globalObject => {
169
- const { addIntrinsics, finalIntrinsics } = makeIntrinsicsCollector();
185
+ export const getGlobalIntrinsics = (globalObject, reporter) => {
186
+ // TODO pass a proper reporter to `makeIntrinsicsCollector`
187
+ const { addIntrinsics, finalIntrinsics } = makeIntrinsicsCollector(reporter);
170
188
 
171
189
  addIntrinsics(sampleGlobals(globalObject, sharedGlobalPropertyNames));
172
190
 
package/src/lockdown.js CHANGED
@@ -30,7 +30,7 @@ import {
30
30
  } from './commons.js';
31
31
  import { makeHardener } from './make-hardener.js';
32
32
  import { makeIntrinsicsCollector } from './intrinsics.js';
33
- import whitelistIntrinsics from './permits-intrinsics.js';
33
+ import removeUnpermittedIntrinsics from './permits-intrinsics.js';
34
34
  import tameFunctionConstructors from './tame-function-constructors.js';
35
35
  import tameDateConstructor from './tame-date-constructor.js';
36
36
  import tameMathObject from './tame-math-object.js';
@@ -58,6 +58,7 @@ import { tameSymbolConstructor } from './tame-symbol-constructor.js';
58
58
  import { tameFauxDataProperties } from './tame-faux-data-properties.js';
59
59
  import { tameRegeneratorRuntime } from './tame-regenerator-runtime.js';
60
60
  import { shimArrayBufferTransfer } from './shim-arraybuffer-transfer.js';
61
+ import { reportInGroup, chooseReporter } from './reporting.js';
61
62
 
62
63
  /** @import {LockdownOptions} from '../types.js' */
63
64
 
@@ -162,19 +163,24 @@ export const repairIntrinsics = (options = {}) => {
162
163
 
163
164
  const {
164
165
  errorTaming = getenv('LOCKDOWN_ERROR_TAMING', 'safe'),
165
- errorTrapping = /** @type {"platform" | "none" | "report" | "abort" | "exit" | undefined} */ (
166
+ errorTrapping = /** @type {"platform" | "none" | "report" | "abort" | "exit"} */ (
166
167
  getenv('LOCKDOWN_ERROR_TRAPPING', 'platform')
167
168
  ),
168
- unhandledRejectionTrapping = /** @type {"none" | "report" | undefined} */ (
169
+ reporting = /** @type {"platform" | "console" | "none"} */ (
170
+ getenv('LOCKDOWN_REPORTING', 'platform')
171
+ ),
172
+ unhandledRejectionTrapping = /** @type {"none" | "report"} */ (
169
173
  getenv('LOCKDOWN_UNHANDLED_REJECTION_TRAPPING', 'report')
170
174
  ),
171
175
  regExpTaming = getenv('LOCKDOWN_REGEXP_TAMING', 'safe'),
172
176
  localeTaming = getenv('LOCKDOWN_LOCALE_TAMING', 'safe'),
173
177
 
174
- consoleTaming = /** @type {'unsafe' | 'safe' | undefined} */ (
178
+ consoleTaming = /** @type {'unsafe' | 'safe'} */ (
175
179
  getenv('LOCKDOWN_CONSOLE_TAMING', 'safe')
176
180
  ),
177
- overrideTaming = getenv('LOCKDOWN_OVERRIDE_TAMING', 'moderate'),
181
+ overrideTaming = /** @type {'moderate' | 'min' | 'severe'} */ (
182
+ getenv('LOCKDOWN_OVERRIDE_TAMING', 'moderate')
183
+ ),
178
184
  stackFiltering = getenv('LOCKDOWN_STACK_FILTERING', 'concise'),
179
185
  domainTaming = getenv('LOCKDOWN_DOMAIN_TAMING', 'safe'),
180
186
  evalTaming = getenv('LOCKDOWN_EVAL_TAMING', 'safeEval'),
@@ -208,6 +214,8 @@ export const repairIntrinsics = (options = {}) => {
208
214
  extraOptionsNames.length === 0 ||
209
215
  Fail`lockdown(): non supported option ${q(extraOptionsNames)}`;
210
216
 
217
+ const reporter = chooseReporter(reporting);
218
+
211
219
  priorRepairIntrinsics === undefined ||
212
220
  // eslint-disable-next-line @endo/no-polymorphic-call
213
221
  assert.fail(
@@ -273,7 +281,7 @@ export const repairIntrinsics = (options = {}) => {
273
281
  const markVirtualizedNativeFunction = tameFunctionToString();
274
282
 
275
283
  const { addIntrinsics, completePrototypes, finalIntrinsics } =
276
- makeIntrinsicsCollector();
284
+ makeIntrinsicsCollector(reporter);
277
285
 
278
286
  // @ts-expect-error __hardenTaming__ could be any string
279
287
  const tamedHarden = tameHarden(safeHarden, __hardenTaming__);
@@ -357,13 +365,22 @@ export const repairIntrinsics = (options = {}) => {
357
365
  tameFauxDataProperties(intrinsics);
358
366
 
359
367
  /**
360
- * 2. WHITELIST to standardize the environment.
368
+ * 2. Enforce PERMITS on shared intrinsics
361
369
  */
362
370
 
363
371
  // Remove non-standard properties.
364
- // All remaining function encountered during whitelisting are
372
+ // All remaining functions encountered during whitelisting are
365
373
  // branded as honorary native functions.
366
- whitelistIntrinsics(intrinsics, markVirtualizedNativeFunction);
374
+ reportInGroup(
375
+ 'SES Removing unpermitted intrinsics',
376
+ reporter,
377
+ groupReporter =>
378
+ removeUnpermittedIntrinsics(
379
+ intrinsics,
380
+ markVirtualizedNativeFunction,
381
+ groupReporter,
382
+ ),
383
+ );
367
384
 
368
385
  // Initialize the powerful initial global, i.e., the global of the
369
386
  // start compartment, from the intrinsics.
@@ -425,7 +442,14 @@ export const repairIntrinsics = (options = {}) => {
425
442
  // therefore before vetted shims rather than afterwards. It is not
426
443
  // clear yet which is better.
427
444
  // @ts-ignore enablePropertyOverrides does its own input validation
428
- enablePropertyOverrides(intrinsics, overrideTaming, overrideDebug);
445
+ reportInGroup('SES Enabling property overrides', reporter, groupReporter =>
446
+ enablePropertyOverrides(
447
+ intrinsics,
448
+ overrideTaming,
449
+ groupReporter,
450
+ overrideDebug,
451
+ ),
452
+ );
429
453
  if (legacyRegeneratorRuntimeTaming === 'unsafe-ignore') {
430
454
  tameRegeneratorRuntime();
431
455
  }
@@ -76,27 +76,27 @@ function mayBeVirtualModuleSource(moduleSource) {
76
76
  function validateVirtualModuleSource(moduleSource, moduleSpecifier) {
77
77
  const { exports } = moduleSource;
78
78
  isArray(exports) ||
79
- Fail`Property 'exports' of a third-party module source must be an array, got ${q(
79
+ Fail`Invalid module source: 'exports' of a virtual module source must be an array, got ${q(
80
80
  exports,
81
81
  )}, for module ${q(moduleSpecifier)}`;
82
82
  }
83
83
 
84
84
  function validateModuleSource(moduleSource, moduleSpecifier) {
85
85
  isObject(moduleSource) ||
86
- Fail`Module sources must be of type object, got ${q(
86
+ Fail`Invalid module source: must be of type object, got ${q(
87
87
  moduleSource,
88
88
  )}, for module ${q(moduleSpecifier)}`;
89
89
  const { imports, exports, reexports = [] } = moduleSource;
90
90
  isArray(imports) ||
91
- Fail`Property 'imports' of a module source must be an array, got ${q(
91
+ Fail`Invalid module source: 'imports' must be an array, got ${q(
92
92
  imports,
93
93
  )}, for module ${q(moduleSpecifier)}`;
94
94
  isArray(exports) ||
95
- Fail`Property 'exports' of a precompiled module source must be an array, got ${q(
95
+ Fail`Invalid module source: 'exports' must be an array, got ${q(
96
96
  exports,
97
97
  )}, for module ${q(moduleSpecifier)}`;
98
98
  isArray(reexports) ||
99
- Fail`Property 'reexports' of a precompiled module source must be an array if present, got ${q(
99
+ Fail`Invalid module source: 'reexports' must be an array if present, got ${q(
100
100
  reexports,
101
101
  )}, for module ${q(moduleSpecifier)}`;
102
102
  }
@@ -138,9 +138,7 @@ export const instantiate = (
138
138
  resolvedImports,
139
139
  );
140
140
  } else {
141
- throw TypeError(
142
- `importHook must provide a module source, got ${q(moduleSource)}`,
143
- );
141
+ throw TypeError(`Invalid module source, got ${q(moduleSource)}`);
144
142
  }
145
143
 
146
144
  // Memoize.
@@ -6,11 +6,13 @@ import {
6
6
  arrayJoin,
7
7
  arrayMap,
8
8
  arrayPush,
9
+ arraySome,
9
10
  create,
10
11
  freeze,
11
12
  generatorNext,
12
13
  generatorThrow,
13
14
  getOwnPropertyNames,
15
+ isArray,
14
16
  isObject,
15
17
  mapGet,
16
18
  mapHas,
@@ -85,14 +87,23 @@ const loadModuleSource = (
85
87
  moduleLoads,
86
88
  importMeta,
87
89
  ) => {
88
- const { resolveHook } = weakmapGet(compartmentPrivateFields, compartment);
90
+ const { resolveHook, name: compartmentName } = weakmapGet(
91
+ compartmentPrivateFields,
92
+ compartment,
93
+ );
94
+
95
+ const { imports } = moduleSource;
96
+ if (
97
+ !isArray(imports) ||
98
+ arraySome(imports, specifier => typeof specifier !== 'string')
99
+ ) {
100
+ throw makeError(
101
+ X`Invalid module source: 'imports' must be an array of strings, got ${imports} for module ${q(moduleSpecifier)} of compartment ${q(compartmentName)}`,
102
+ );
103
+ }
89
104
 
90
105
  // resolve all imports relative to this referrer module.
91
- const resolvedImports = resolveAll(
92
- moduleSource.imports,
93
- resolveHook,
94
- moduleSpecifier,
95
- );
106
+ const resolvedImports = resolveAll(imports, resolveHook, moduleSpecifier);
96
107
  const moduleRecord = freeze({
97
108
  compartment,
98
109
  moduleSource,