ses 0.18.8 → 1.0.1

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.18.8",
3
+ "version": "1.0.1",
4
4
  "description": "Hardened JavaScript for Fearless Cooperation",
5
5
  "keywords": [
6
6
  "lockdown",
@@ -35,10 +35,12 @@
35
35
  "types": "./types.d.ts",
36
36
  "exports": {
37
37
  ".": {
38
+ "types": "./types.d.ts",
38
39
  "import": "./index.js",
39
40
  "require": "./dist/ses.cjs"
40
41
  },
41
42
  "./lockdown": {
43
+ "types": "./types.d.ts",
42
44
  "import": "./index.js",
43
45
  "require": "./dist/ses.cjs"
44
46
  },
@@ -60,11 +62,11 @@
60
62
  "test:platform-compatibility": "node test/package/test.cjs"
61
63
  },
62
64
  "dependencies": {
63
- "@endo/env-options": "^0.1.4"
65
+ "@endo/env-options": "^1.0.1"
64
66
  },
65
67
  "devDependencies": {
66
- "@endo/compartment-mapper": "^0.9.2",
67
- "@endo/static-module-record": "^0.8.2",
68
+ "@endo/compartment-mapper": "^1.0.1",
69
+ "@endo/static-module-record": "^1.0.1",
68
70
  "@endo/test262-runner": "^0.1.32",
69
71
  "ava": "^5.3.0",
70
72
  "babel-eslint": "^10.0.3",
@@ -74,7 +76,7 @@
74
76
  "eslint-config-airbnb-base": "^15.0.0",
75
77
  "eslint-config-prettier": "^8.8.0",
76
78
  "eslint-plugin-eslint-comments": "^3.1.2",
77
- "eslint-plugin-import": "^2.27.5",
79
+ "eslint-plugin-import": "^2.29.0",
78
80
  "prettier": "^3.0.0",
79
81
  "sinon": "^15.1.0",
80
82
  "terser": "^5.16.6",
@@ -179,5 +181,8 @@
179
181
  ],
180
182
  "timeout": "2m"
181
183
  },
182
- "gitHead": "9c779d317c4b02133172dbe142c5b2d1727efc49"
184
+ "typeCoverage": {
185
+ "atLeast": 81.13
186
+ },
187
+ "gitHead": "c02aec92c3caa417d6bdf3c4f555f0b2694d9f9e"
183
188
  }
@@ -193,7 +193,7 @@ export const severeEnablements = {
193
193
  * With the `'*'` setting here, all the properties inherited from
194
194
  * `Object.prototype` are accessors, creating an unusable display as seen
195
195
  * at As explained at
196
- * https://github.com/endojs/endo/blob/master/packages/ses/lockdown-options.md#overridetaming-options
196
+ * https://github.com/endojs/endo/blob/master/packages/ses/docs/lockdown.md#overridetaming-options
197
197
  * Open the triangles at the bottom of that section.
198
198
  */
199
199
  '%ObjectPrototype%': '*',
@@ -174,6 +174,10 @@ freeze(ErrorInfo);
174
174
 
175
175
  /** @type {MakeCausalConsole} */
176
176
  const makeCausalConsole = (baseConsole, loggedErrorHandler) => {
177
+ if (!baseConsole) {
178
+ return undefined;
179
+ }
180
+
177
181
  const { getStackString, tagError, takeMessageLogArgs, takeNoteLogArgsArray } =
178
182
  loggedErrorHandler;
179
183
 
@@ -83,7 +83,7 @@
83
83
  * calls methods of the `loggedErrorHandler` to customize how it handles logged
84
84
  * errors.
85
85
  *
86
- * @param {VirtualConsole} baseConsole
86
+ * @param {VirtualConsole | undefined} baseConsole
87
87
  * @param {LoggedErrorHandler} loggedErrorHandler
88
- * @returns {VirtualConsole}
88
+ * @returns {VirtualConsole | undefined}
89
89
  */
@@ -1,14 +1,47 @@
1
1
  // @ts-check
2
2
 
3
- import { TypeError, globalThis } from '../commons.js';
3
+ import {
4
+ TypeError,
5
+ apply,
6
+ defineProperty,
7
+ freeze,
8
+ globalThis,
9
+ } from '../commons.js';
4
10
  import { loggedErrorHandler as defaultHandler } from './assert.js';
5
11
  import { makeCausalConsole } from './console.js';
6
12
  import { makeRejectionHandlers } from './unhandled-rejection.js';
7
13
  import './types.js';
8
14
  import './internal-types.js';
9
15
 
16
+ const wrapLogger = (logger, thisArg) =>
17
+ freeze((...args) => apply(logger, thisArg, args));
18
+
10
19
  // eslint-disable-next-line no-restricted-globals
11
- const originalConsole = console;
20
+ const originalConsole = /** @type {VirtualConsole} */ (
21
+ // eslint-disable-next-line no-nested-ternary
22
+ typeof console !== 'undefined'
23
+ ? console
24
+ : typeof print === 'function'
25
+ ? // Make a good-enough console for eshost (including only functions that
26
+ // log at a specific level with no special argument interpretation).
27
+ // https://console.spec.whatwg.org/#logging
28
+ (p => freeze({ debug: p, log: p, info: p, warn: p, error: p }))(
29
+ // eslint-disable-next-line no-undef
30
+ wrapLogger(print),
31
+ )
32
+ : undefined
33
+ );
34
+
35
+ // Upgrade a log-only console (as in `eshost -h SpiderMonkey`).
36
+ if (originalConsole && originalConsole.log) {
37
+ for (const methodName of ['warn', 'error']) {
38
+ if (!originalConsole[methodName]) {
39
+ defineProperty(originalConsole, methodName, {
40
+ value: wrapLogger(originalConsole.log, originalConsole),
41
+ });
42
+ }
43
+ }
44
+ }
12
45
 
13
46
  /**
14
47
  * Wrap console unless suppressed.
@@ -40,10 +73,11 @@ export const tameConsole = (
40
73
  getStackString: optGetStackString,
41
74
  };
42
75
  }
43
- const ourConsole =
76
+ const ourConsole = /** @type {VirtualConsole} */ (
44
77
  consoleTaming === 'unsafe'
45
78
  ? originalConsole
46
- : makeCausalConsole(originalConsole, loggedErrorHandler);
79
+ : makeCausalConsole(originalConsole, loggedErrorHandler)
80
+ );
47
81
 
48
82
  // Attach platform-specific error traps such that any error that gets thrown
49
83
  // at top-of-turn (the bottom of stack) will get logged by our causal
@@ -4,7 +4,7 @@
4
4
  * @callback BaseAssert
5
5
  * The `assert` function itself.
6
6
  *
7
- * @param {*} flag The truthy/falsy value
7
+ * @param {any} flag The truthy/falsy value
8
8
  * @param {Details=} optDetails The details to throw
9
9
  * @param {ErrorConstructor=} ErrorConstructor An optional alternate error
10
10
  * constructor to use.
@@ -51,8 +51,8 @@
51
51
  * The `assert.equal` method
52
52
  *
53
53
  * Assert that two values must be `Object.is`.
54
- * @param {*} actual The value we received
55
- * @param {*} expected What we wanted
54
+ * @param {any} actual The value we received
55
+ * @param {any} expected What we wanted
56
56
  * @param {Details=} optDetails The details to throw
57
57
  * @param {ErrorConstructor=} ErrorConstructor An optional alternate error
58
58
  * constructor to use.
@@ -201,7 +201,7 @@
201
201
  * ```
202
202
  *
203
203
  * @callback AssertQuote
204
- * @param {*} payload What to declassify
204
+ * @param {any} payload What to declassify
205
205
  * @param {(string|number)=} spaces
206
206
  * @returns {StringablePayload} The declassified payload
207
207
  */
@@ -110,10 +110,12 @@ export const setGlobalObjectMutableProperties = (
110
110
  globalThis: globalObject,
111
111
  };
112
112
 
113
- perCompartmentGlobals.Compartment = makeCompartmentConstructor(
114
- makeCompartmentConstructor,
115
- intrinsics,
116
- markVirtualizedNativeFunction,
113
+ perCompartmentGlobals.Compartment = freeze(
114
+ makeCompartmentConstructor(
115
+ makeCompartmentConstructor,
116
+ intrinsics,
117
+ markVirtualizedNativeFunction,
118
+ ),
117
119
  );
118
120
 
119
121
  // TODO These should still be tamed according to the whitelist before
@@ -145,7 +147,7 @@ export const setGlobalObjectEvaluators = (
145
147
  markVirtualizedNativeFunction,
146
148
  ) => {
147
149
  {
148
- const f = makeEvalFunction(evaluator);
150
+ const f = freeze(makeEvalFunction(evaluator));
149
151
  markVirtualizedNativeFunction(f);
150
152
  defineProperty(globalObject, 'eval', {
151
153
  value: f,
@@ -155,7 +157,7 @@ export const setGlobalObjectEvaluators = (
155
157
  });
156
158
  }
157
159
  {
158
- const f = makeFunctionConstructor(evaluator);
160
+ const f = freeze(makeFunctionConstructor(evaluator));
159
161
  markVirtualizedNativeFunction(f);
160
162
  defineProperty(globalObject, 'Function', {
161
163
  value: f,
package/src/lockdown.js CHANGED
@@ -25,6 +25,7 @@ import {
25
25
  ownKeys,
26
26
  stringSplit,
27
27
  noEvalEvaluate,
28
+ getOwnPropertyNames,
28
29
  } from './commons.js';
29
30
  import { makeHardener } from './make-hardener.js';
30
31
  import { makeIntrinsicsCollector } from './intrinsics.js';
@@ -151,21 +152,25 @@ export const repairIntrinsics = (options = {}) => {
151
152
  // such as those from the infrastructure. However, the bug you're trying to
152
153
  // track down might be in the infrastrure, in which case the `'verbose'` setting
153
154
  // is useful. See
154
- // [`stackFiltering` options](https://github.com/Agoric/SES-shim/blob/master/packages/ses/lockdown-options.md#stackfiltering-options)
155
+ // [`stackFiltering` options](https://github.com/Agoric/SES-shim/blob/master/packages/ses/docs/lockdown.md#stackfiltering-options)
155
156
  // for an explanation.
156
157
 
157
158
  const { getEnvironmentOption: getenv } = makeEnvironmentCaptor(globalThis);
158
159
 
159
160
  const {
160
161
  errorTaming = getenv('LOCKDOWN_ERROR_TAMING', 'safe'),
161
- errorTrapping = getenv('LOCKDOWN_ERROR_TRAPPING', 'platform'),
162
- unhandledRejectionTrapping = getenv(
163
- 'LOCKDOWN_UNHANDLED_REJECTION_TRAPPING',
164
- 'report',
162
+ errorTrapping = /** @type {"platform" | "none" | "report" | "abort" | "exit" | undefined} */ (
163
+ getenv('LOCKDOWN_ERROR_TRAPPING', 'platform')
164
+ ),
165
+ unhandledRejectionTrapping = /** @type {"none" | "report" | undefined} */ (
166
+ getenv('LOCKDOWN_UNHANDLED_REJECTION_TRAPPING', 'report')
165
167
  ),
166
168
  regExpTaming = getenv('LOCKDOWN_REGEXP_TAMING', 'safe'),
167
169
  localeTaming = getenv('LOCKDOWN_LOCALE_TAMING', 'safe'),
168
- consoleTaming = getenv('LOCKDOWN_CONSOLE_TAMING', 'safe'),
170
+
171
+ consoleTaming = /** @type {'unsafe' | 'safe' | undefined} */ (
172
+ getenv('LOCKDOWN_CONSOLE_TAMING', 'safe')
173
+ ),
169
174
  overrideTaming = getenv('LOCKDOWN_OVERRIDE_TAMING', 'moderate'),
170
175
  stackFiltering = getenv('LOCKDOWN_STACK_FILTERING', 'concise'),
171
176
  domainTaming = getenv('LOCKDOWN_DOMAIN_TAMING', 'safe'),
@@ -385,6 +390,18 @@ export const repairIntrinsics = (options = {}) => {
385
390
  // must be the operation that modifies the intrinsics.
386
391
  tamedHarden(intrinsics);
387
392
 
393
+ // Harden evaluators
394
+ tamedHarden(globalThis.Function);
395
+ tamedHarden(globalThis.eval);
396
+ // @ts-ignore Compartment does exist on globalThis
397
+ tamedHarden(globalThis.Compartment);
398
+
399
+ // Harden Symbol and properties for initialGlobalPropertyNames in the host realm
400
+ tamedHarden(globalThis.Symbol);
401
+ for (const prop of getOwnPropertyNames(initialGlobalPropertyNames)) {
402
+ tamedHarden(globalThis[prop]);
403
+ }
404
+
388
405
  return tamedHarden;
389
406
  };
390
407
 
package/src/permits.js CHANGED
@@ -1414,6 +1414,8 @@ export const permitted = {
1414
1414
  race: fn,
1415
1415
  reject: fn,
1416
1416
  resolve: fn,
1417
+ // https://github.com/tc39/proposal-promise-with-resolvers
1418
+ withResolvers: fn,
1417
1419
  '@@species': getter,
1418
1420
  },
1419
1421
 
package/types.d.ts CHANGED
@@ -58,8 +58,11 @@ export interface PrecompiledStaticModuleInterface {
58
58
  export interface ThirdPartyStaticModuleInterface {
59
59
  imports: Array<string>;
60
60
  exports: Array<string>;
61
+ /**
62
+ * Note that this value does _not_ contain any numeric or symbol property keys, which can theoretically be members of `exports` in a CommonJS module.
63
+ */
61
64
  execute(
62
- proxiedExports: Object,
65
+ proxiedExports: Record<string, any>,
63
66
  compartment: Compartment,
64
67
  resolvedImports: Record<string, string>,
65
68
  ): void;