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/README.md +2 -0
- package/dist/lockdown.cjs +574 -337
- package/dist/lockdown.mjs +574 -337
- package/dist/lockdown.umd.js +574 -337
- package/dist/lockdown.umd.min.js +1 -1
- package/dist/ses.cjs +574 -337
- package/dist/ses.mjs +574 -337
- package/dist/ses.umd.js +574 -337
- package/dist/ses.umd.min.js +1 -1
- package/dist/types.d.cts +2 -1
- package/package.json +8 -8
- package/src/cauterize-property.js +69 -0
- package/src/compartment-shim.js +7 -1
- package/src/enable-property-overrides.js +6 -3
- package/src/enablements.js +1 -1
- package/src/error/README.md +2 -2
- package/src/error/console.js +8 -8
- package/src/error/internal-types.js +1 -1
- package/src/error/tame-v8-error-constructor.js +3 -3
- package/src/global-object.js +1 -1
- package/src/intrinsics.js +27 -9
- package/src/lockdown.js +34 -10
- package/src/module-link.js +6 -8
- package/src/module-load.js +17 -6
- package/src/permits-intrinsics.js +19 -62
- package/src/permits.js +12 -10
- package/src/reporting-types.d.ts +13 -0
- package/src/reporting.js +106 -0
- package/src/tame-symbol-constructor.js +2 -2
- package/types.d.ts +2 -1
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
// Typically, this module will not be used directly, but via the
|
|
25
25
|
// [lockdown-shim] which handles all necessary repairs and taming in SES.
|
|
26
26
|
//
|
|
27
|
-
// In the
|
|
27
|
+
// In the permits, the `prototype`, `__proto__`, and `constructor` must be
|
|
28
28
|
// specified and point to top level entries in the map. For example,
|
|
29
29
|
// `Object.__proto__` leads to `FunctionPrototype` which is a top level entry
|
|
30
30
|
// in the map.
|
|
@@ -34,14 +34,14 @@
|
|
|
34
34
|
// `Error.stackTraceLimit` leads to 'number'),
|
|
35
35
|
// * the name of an intrinsic,
|
|
36
36
|
// * an internal constant(for example, `eval` leads to `fn` which
|
|
37
|
-
// is an alias for `FunctionInstance`, a record that
|
|
37
|
+
// is an alias for `FunctionInstance`, a record that permits all
|
|
38
38
|
// properties allowed on such instance).
|
|
39
39
|
// * false, a property to be removed that we know about.
|
|
40
40
|
//
|
|
41
41
|
// All unlisted properties are also removed. But for the ones that are removed
|
|
42
42
|
// because they are unlisted, as opposed to `false`, we also print their
|
|
43
43
|
// name to the console as a useful diagnostic, possibly provoking an expansion
|
|
44
|
-
// of the
|
|
44
|
+
// of the permits.
|
|
45
45
|
|
|
46
46
|
import { permitted, FunctionInstance, isAccessorPermit } from './permits.js';
|
|
47
47
|
import {
|
|
@@ -61,30 +61,25 @@ import {
|
|
|
61
61
|
ownKeys,
|
|
62
62
|
symbolKeyFor,
|
|
63
63
|
} from './commons.js';
|
|
64
|
+
import { cauterizeProperty } from './cauterize-property.js';
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* @import {Reporter} from './reporting-types.js'
|
|
68
|
+
*/
|
|
64
69
|
|
|
65
70
|
/**
|
|
66
|
-
* whitelistIntrinsics()
|
|
67
71
|
* Removes all non-allowed properties found by recursively and
|
|
68
72
|
* reflectively walking own property chains.
|
|
69
73
|
*
|
|
70
74
|
* @param {object} intrinsics
|
|
71
|
-
* @param {(object) => void} markVirtualizedNativeFunction
|
|
75
|
+
* @param {(virtualizedNativeFunction: object) => void} markVirtualizedNativeFunction
|
|
76
|
+
* @param {Reporter} reporter
|
|
72
77
|
*/
|
|
73
|
-
export default function
|
|
78
|
+
export default function removeUnpermittedIntrinsics(
|
|
74
79
|
intrinsics,
|
|
75
80
|
markVirtualizedNativeFunction,
|
|
81
|
+
reporter,
|
|
76
82
|
) {
|
|
77
|
-
let groupStarted = false;
|
|
78
|
-
const inConsoleGroup = (level, ...args) => {
|
|
79
|
-
if (!groupStarted) {
|
|
80
|
-
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
81
|
-
console.groupCollapsed('Removing unpermitted intrinsics');
|
|
82
|
-
groupStarted = true;
|
|
83
|
-
}
|
|
84
|
-
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
85
|
-
return console[level](...args);
|
|
86
|
-
};
|
|
87
|
-
|
|
88
83
|
// These primitives are allowed for permits.
|
|
89
84
|
const primitives = ['undefined', 'boolean', 'number', 'string', 'symbol'];
|
|
90
85
|
|
|
@@ -148,7 +143,7 @@ export default function whitelistIntrinsics(
|
|
|
148
143
|
|
|
149
144
|
// Assert: protoName, if provided, is a string.
|
|
150
145
|
if (protoName !== undefined && typeof protoName !== 'string') {
|
|
151
|
-
throw TypeError(`Malformed
|
|
146
|
+
throw TypeError(`Malformed permit ${path}.__proto__`);
|
|
152
147
|
}
|
|
153
148
|
|
|
154
149
|
// If permit not specified, default to Object.prototype.
|
|
@@ -164,7 +159,7 @@ export default function whitelistIntrinsics(
|
|
|
164
159
|
|
|
165
160
|
/*
|
|
166
161
|
* isAllowedPropertyValue()
|
|
167
|
-
*
|
|
162
|
+
* enforce permit for a single property value.
|
|
168
163
|
*/
|
|
169
164
|
function isAllowedPropertyValue(path, value, prop, permit) {
|
|
170
165
|
if (typeof permit === 'object') {
|
|
@@ -192,7 +187,7 @@ export default function whitelistIntrinsics(
|
|
|
192
187
|
|
|
193
188
|
if (objectHasOwnProperty(intrinsics, permit)) {
|
|
194
189
|
if (value !== intrinsics[permit]) {
|
|
195
|
-
throw TypeError(`Does not match
|
|
190
|
+
throw TypeError(`Does not match permit for ${path}`);
|
|
196
191
|
}
|
|
197
192
|
return true;
|
|
198
193
|
}
|
|
@@ -285,50 +280,12 @@ export default function whitelistIntrinsics(
|
|
|
285
280
|
const subPermit = getSubPermit(obj, permit, propString);
|
|
286
281
|
|
|
287
282
|
if (!subPermit || !isAllowedProperty(subPath, obj, prop, subPermit)) {
|
|
288
|
-
|
|
289
|
-
// permit.
|
|
290
|
-
// If the permit is specifically false, not merely undefined,
|
|
291
|
-
// this is a property we expect to see because we know it exists in
|
|
292
|
-
// some environments and we have expressly decided to exclude it.
|
|
293
|
-
// Any other disallowed property is one we have not audited and we log
|
|
294
|
-
// that we are removing it so we know to look into it, as happens when
|
|
295
|
-
// the language evolves new features to existing intrinsics.
|
|
296
|
-
if (subPermit !== false) {
|
|
297
|
-
inConsoleGroup('warn', `Removing ${subPath}`);
|
|
298
|
-
}
|
|
299
|
-
try {
|
|
300
|
-
delete obj[prop];
|
|
301
|
-
} catch (err) {
|
|
302
|
-
if (prop in obj) {
|
|
303
|
-
if (typeof obj === 'function' && prop === 'prototype') {
|
|
304
|
-
obj.prototype = undefined;
|
|
305
|
-
if (obj.prototype === undefined) {
|
|
306
|
-
inConsoleGroup(
|
|
307
|
-
'warn',
|
|
308
|
-
`Tolerating undeletable ${subPath} === undefined`,
|
|
309
|
-
);
|
|
310
|
-
// eslint-disable-next-line no-continue
|
|
311
|
-
continue;
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
inConsoleGroup('error', `failed to delete ${subPath}`, err);
|
|
315
|
-
} else {
|
|
316
|
-
inConsoleGroup('error', `deleting ${subPath} threw`, err);
|
|
317
|
-
}
|
|
318
|
-
throw err;
|
|
319
|
-
}
|
|
283
|
+
cauterizeProperty(obj, prop, subPermit === false, subPath, reporter);
|
|
320
284
|
}
|
|
321
285
|
}
|
|
322
286
|
}
|
|
323
287
|
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
visitProperties('intrinsics', intrinsics, permitted);
|
|
328
|
-
} finally {
|
|
329
|
-
if (groupStarted) {
|
|
330
|
-
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
331
|
-
console.groupEnd();
|
|
332
|
-
}
|
|
333
|
-
}
|
|
288
|
+
// Start path with 'intrinsics' to clarify that properties are not
|
|
289
|
+
// removed from the global object by the permitting operation.
|
|
290
|
+
visitProperties('intrinsics', intrinsics, permitted);
|
|
334
291
|
}
|
package/src/permits.js
CHANGED
|
@@ -6,7 +6,7 @@ import { arrayPush } from './commons.js';
|
|
|
6
6
|
/** @import {GenericErrorConstructor} from '../types.js' */
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
* @
|
|
9
|
+
* @module Exports {@code permits}, a recursively defined
|
|
10
10
|
* JSON record enumerating all intrinsics and their properties
|
|
11
11
|
* according to ECMA specs.
|
|
12
12
|
*
|
|
@@ -32,7 +32,7 @@ export const constantProperties = {
|
|
|
32
32
|
* universalPropertyNames
|
|
33
33
|
* Properties of all global objects.
|
|
34
34
|
* Must be powerless.
|
|
35
|
-
* Maps from property name to the intrinsic name in the
|
|
35
|
+
* Maps from property name to the intrinsic name in the permits.
|
|
36
36
|
*/
|
|
37
37
|
export const universalPropertyNames = {
|
|
38
38
|
// *** Function Properties of the Global Object
|
|
@@ -115,7 +115,7 @@ export const universalPropertyNames = {
|
|
|
115
115
|
* Those found only on the initial global, i.e., the global of the
|
|
116
116
|
* start compartment, as well as any compartments created before lockdown.
|
|
117
117
|
* These may provide much of the power provided by the original.
|
|
118
|
-
* Maps from property name to the intrinsic name in the
|
|
118
|
+
* Maps from property name to the intrinsic name in the permits.
|
|
119
119
|
*/
|
|
120
120
|
export const initialGlobalPropertyNames = {
|
|
121
121
|
// *** Constructor Properties of the Global Object
|
|
@@ -125,7 +125,7 @@ export const initialGlobalPropertyNames = {
|
|
|
125
125
|
RegExp: '%InitialRegExp%',
|
|
126
126
|
|
|
127
127
|
// Omit `Symbol`, because we want the original to appear on the
|
|
128
|
-
// start compartment without passing through the
|
|
128
|
+
// start compartment without passing through the permits mechanism, since
|
|
129
129
|
// we want to preserve all its properties, even if we never heard of them.
|
|
130
130
|
// Symbol: '%InitialSymbol%',
|
|
131
131
|
|
|
@@ -149,7 +149,7 @@ export const initialGlobalPropertyNames = {
|
|
|
149
149
|
* sharedGlobalPropertyNames
|
|
150
150
|
* Those found only on the globals of new compartments created after lockdown,
|
|
151
151
|
* which must therefore be powerless.
|
|
152
|
-
* Maps from property name to the intrinsic name in the
|
|
152
|
+
* Maps from property name to the intrinsic name in the permits.
|
|
153
153
|
*/
|
|
154
154
|
export const sharedGlobalPropertyNames = {
|
|
155
155
|
// *** Constructor Properties of the Global Object
|
|
@@ -168,7 +168,7 @@ export const sharedGlobalPropertyNames = {
|
|
|
168
168
|
* uniqueGlobalPropertyNames
|
|
169
169
|
* Those made separately for each global, including the initial global
|
|
170
170
|
* of the start compartment.
|
|
171
|
-
* Maps from property name to the intrinsic name in the
|
|
171
|
+
* Maps from property name to the intrinsic name in the permits
|
|
172
172
|
* (which is currently always the same).
|
|
173
173
|
*/
|
|
174
174
|
export const uniqueGlobalPropertyNames = {
|
|
@@ -228,18 +228,18 @@ export { NativeErrors };
|
|
|
228
228
|
* blacklisted and simply removed. Properties not mentioned
|
|
229
229
|
* are also considered blacklisted and are removed.
|
|
230
230
|
* <li>A string value equal to a primitive ("number", "string", etc),
|
|
231
|
-
* in which case the property is
|
|
231
|
+
* in which case the property is permitted if its value property
|
|
232
232
|
* is typeof the given type. For example, {@code "Infinity"} leads to
|
|
233
233
|
* "number" and property values that fail {@code typeof "number"}.
|
|
234
234
|
* are removed.
|
|
235
235
|
* <li>A string value equal to an intinsic name ("ObjectPrototype",
|
|
236
|
-
* "Array", etc), in which case the property
|
|
236
|
+
* "Array", etc), in which case the property permitted if its
|
|
237
237
|
* value property is equal to the value of the corresponfing
|
|
238
238
|
* intrinsics. For example, {@code Map.prototype} leads to
|
|
239
239
|
* "MapPrototype" and the property is removed if its value is
|
|
240
240
|
* not equal to %MapPrototype%
|
|
241
241
|
* <li>Another record, in which case this property is simply
|
|
242
|
-
*
|
|
242
|
+
* permitted and that next record represents the disposition of
|
|
243
243
|
* the object which is its value. For example, {@code "Object"}
|
|
244
244
|
* leads to another record explaining what properties {@code
|
|
245
245
|
* "Object"} may have and how each such property should be treated.
|
|
@@ -1496,7 +1496,7 @@ export const permitted = {
|
|
|
1496
1496
|
//
|
|
1497
1497
|
// We will likely change this to add a property to Promise called
|
|
1498
1498
|
// Promise.delegate and put static methods on it, which will necessitate
|
|
1499
|
-
// another
|
|
1499
|
+
// another permits change to update to the current proposed standard.
|
|
1500
1500
|
HandledPromise: {
|
|
1501
1501
|
'[[Proto]]': 'Promise',
|
|
1502
1502
|
applyFunction: fn,
|
|
@@ -1549,6 +1549,8 @@ export const permitted = {
|
|
|
1549
1549
|
// https://github.com/tc39/proposal-promise-with-resolvers
|
|
1550
1550
|
withResolvers: fn,
|
|
1551
1551
|
'@@species': getter,
|
|
1552
|
+
// https://github.com/tc39/proposal-promise-try
|
|
1553
|
+
try: fn,
|
|
1552
1554
|
},
|
|
1553
1555
|
|
|
1554
1556
|
'%PromisePrototype%': {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/* eslint-disable no-restricted-globals */
|
|
2
|
+
|
|
3
|
+
export type Reporter = {
|
|
4
|
+
warn: (...message: Array<any>) => void;
|
|
5
|
+
error: (...message: Array<string>) => void;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export type GroupReporter = Reporter & {
|
|
9
|
+
groupCollapsed: (label: string) => void;
|
|
10
|
+
groupEnd: () => void;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// Console implements GroupReporter
|
package/src/reporting.js
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { TypeError, functionBind, globalThis } from './commons.js';
|
|
2
|
+
import { assert } from './error/assert.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @import {Reporter, GroupReporter} from './reporting-types.js'
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Creates a suitable reporter for internal errors and warnings out of the
|
|
10
|
+
* Node.js console.error to ensure all messages to go stderr, including the
|
|
11
|
+
* group label.
|
|
12
|
+
* Accounts for the extra space introduced by console.error as a delimiter
|
|
13
|
+
* between the indent and subsequent arguments.
|
|
14
|
+
*
|
|
15
|
+
* @param {(...message: Array<any>) => void} print
|
|
16
|
+
*/
|
|
17
|
+
const makeReportPrinter = print => {
|
|
18
|
+
let indent = false;
|
|
19
|
+
/** @param {Array<any>} args */
|
|
20
|
+
const printIndent = (...args) => {
|
|
21
|
+
if (indent) {
|
|
22
|
+
print(' ', ...args);
|
|
23
|
+
} else {
|
|
24
|
+
print(...args);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
return /** @type {GroupReporter} */ ({
|
|
28
|
+
warn(...args) {
|
|
29
|
+
printIndent(...args);
|
|
30
|
+
},
|
|
31
|
+
error(...args) {
|
|
32
|
+
printIndent(...args);
|
|
33
|
+
},
|
|
34
|
+
groupCollapsed(...args) {
|
|
35
|
+
assert(!indent);
|
|
36
|
+
print(...args);
|
|
37
|
+
indent = true;
|
|
38
|
+
},
|
|
39
|
+
groupEnd() {
|
|
40
|
+
indent = false;
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const mute = () => {};
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @param {"platform" | "console" | "none"} reporting
|
|
49
|
+
*/
|
|
50
|
+
export const chooseReporter = reporting => {
|
|
51
|
+
if (reporting === 'none') {
|
|
52
|
+
return makeReportPrinter(mute);
|
|
53
|
+
}
|
|
54
|
+
if (reporting !== 'platform' && reporting !== 'console') {
|
|
55
|
+
throw new TypeError(`Invalid lockdown reporting option: ${reporting}`);
|
|
56
|
+
}
|
|
57
|
+
if (
|
|
58
|
+
reporting === 'console' ||
|
|
59
|
+
globalThis.window === globalThis ||
|
|
60
|
+
globalThis.importScripts !== undefined
|
|
61
|
+
) {
|
|
62
|
+
return console;
|
|
63
|
+
}
|
|
64
|
+
if (globalThis.console !== undefined) {
|
|
65
|
+
// On Node.js, we send all feedback to stderr, regardless of purported level.
|
|
66
|
+
const console = globalThis.console;
|
|
67
|
+
const error = functionBind(console.error, console);
|
|
68
|
+
return makeReportPrinter(error);
|
|
69
|
+
}
|
|
70
|
+
if (globalThis.print !== undefined) {
|
|
71
|
+
return makeReportPrinter(globalThis.print);
|
|
72
|
+
}
|
|
73
|
+
return makeReportPrinter(mute);
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* @param {string} groupLabel
|
|
78
|
+
* @param {GroupReporter} console
|
|
79
|
+
* @param {(internalConsole: Reporter) => void} callback
|
|
80
|
+
*/
|
|
81
|
+
export const reportInGroup = (groupLabel, console, callback) => {
|
|
82
|
+
const { warn, error, groupCollapsed, groupEnd } = console;
|
|
83
|
+
let groupStarted = false;
|
|
84
|
+
try {
|
|
85
|
+
return callback({
|
|
86
|
+
warn(...args) {
|
|
87
|
+
if (!groupStarted) {
|
|
88
|
+
groupCollapsed(groupLabel);
|
|
89
|
+
groupStarted = true;
|
|
90
|
+
}
|
|
91
|
+
warn(...args);
|
|
92
|
+
},
|
|
93
|
+
error(...args) {
|
|
94
|
+
if (!groupStarted) {
|
|
95
|
+
groupCollapsed(groupLabel);
|
|
96
|
+
groupStarted = true;
|
|
97
|
+
}
|
|
98
|
+
error(...args);
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
} finally {
|
|
102
|
+
if (groupStarted) {
|
|
103
|
+
groupEnd();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
};
|
|
@@ -16,8 +16,8 @@ import {
|
|
|
16
16
|
* `Symbol` constructor on constructed compartments.
|
|
17
17
|
*
|
|
18
18
|
* Starting these properties as configurable assumes two succeeding phases of
|
|
19
|
-
* processing: A
|
|
20
|
-
* removes all properties not on the
|
|
19
|
+
* processing: A permit enforcement phase, that
|
|
20
|
+
* removes all properties not on the permits (which requires them to be
|
|
21
21
|
* configurable) and a global hardening step that freezes all primordials,
|
|
22
22
|
* returning these properties to their expected non-configurable status.
|
|
23
23
|
*
|
package/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @
|
|
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
|