ses 0.14.2 → 0.15.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/CHANGELOG.md +64 -0
- package/NEWS.md +60 -1
- package/README.md +0 -1
- package/dist/lockdown.cjs +1769 -992
- package/dist/lockdown.mjs +1769 -992
- package/dist/lockdown.umd.js +1769 -992
- package/dist/lockdown.umd.min.js +1 -1
- package/dist/ses.cjs +1769 -992
- package/dist/ses.mjs +1769 -992
- package/dist/ses.umd.js +1769 -992
- package/dist/ses.umd.min.js +1 -1
- package/index.d.ts +2 -1
- package/index.js +6 -13
- package/package.json +24 -11
- package/src/commons.js +44 -9
- package/src/compartment-evaluate.js +102 -0
- package/src/compartment-shim.js +78 -106
- package/src/enable-property-overrides.js +5 -4
- package/src/enablements.js +7 -2
- package/src/environment-options.js +125 -0
- package/src/error/assert.js +51 -39
- package/src/error/console.js +32 -14
- package/src/error/fatal-assert.js +2 -0
- package/src/error/stringify-utils.js +26 -3
- package/src/error/tame-console.js +12 -4
- package/src/error/tame-error-constructor.js +18 -17
- package/src/error/tame-v8-error-constructor.js +30 -14
- package/src/get-anonymous-intrinsics.js +11 -8
- package/src/get-source-url.js +4 -4
- package/src/global-object.js +33 -26
- package/src/intrinsics.js +76 -67
- package/src/lockdown-shim.js +111 -119
- package/src/make-eval-function.js +3 -5
- package/src/make-function-constructor.js +3 -4
- package/src/make-safe-evaluator.js +117 -0
- package/src/module-instance.js +31 -17
- package/src/module-link.js +11 -4
- package/src/module-load.js +169 -44
- package/src/module-proxy.js +12 -4
- package/src/scope-constants.js +6 -3
- package/src/scope-handler.js +41 -17
- package/src/tame-date-constructor.js +8 -2
- package/src/tame-domains.js +46 -0
- package/src/tame-function-constructors.js +1 -0
- package/src/tame-locale-methods.js +6 -6
- package/src/tame-math-object.js +2 -2
- package/src/tame-regexp-constructor.js +7 -7
- package/src/transforms.js +13 -6
- package/src/whitelist-intrinsics.js +9 -3
- package/src/evaluate.js +0 -98
package/src/module-link.js
CHANGED
|
@@ -14,9 +14,9 @@ import {
|
|
|
14
14
|
makeThirdPartyModuleInstance,
|
|
15
15
|
} from './module-instance.js';
|
|
16
16
|
import {
|
|
17
|
-
Error,
|
|
18
17
|
Map,
|
|
19
18
|
ReferenceError,
|
|
19
|
+
TypeError,
|
|
20
20
|
entries,
|
|
21
21
|
isArray,
|
|
22
22
|
isObject,
|
|
@@ -40,11 +40,18 @@ export const link = (
|
|
|
40
40
|
compartment,
|
|
41
41
|
moduleSpecifier,
|
|
42
42
|
) => {
|
|
43
|
-
const { moduleRecords } = weakmapGet(
|
|
43
|
+
const { name: compartmentName, moduleRecords } = weakmapGet(
|
|
44
|
+
compartmentPrivateFields,
|
|
45
|
+
compartment,
|
|
46
|
+
);
|
|
44
47
|
|
|
45
48
|
const moduleRecord = mapGet(moduleRecords, moduleSpecifier);
|
|
46
49
|
if (moduleRecord === undefined) {
|
|
47
|
-
throw new ReferenceError(
|
|
50
|
+
throw new ReferenceError(
|
|
51
|
+
`Missing link to module ${q(moduleSpecifier)} from compartment ${q(
|
|
52
|
+
compartmentName,
|
|
53
|
+
)}`,
|
|
54
|
+
);
|
|
48
55
|
}
|
|
49
56
|
|
|
50
57
|
// Mutual recursion so there's no confusion about which
|
|
@@ -163,7 +170,7 @@ export const instantiate = (
|
|
|
163
170
|
resolvedImports,
|
|
164
171
|
);
|
|
165
172
|
} else {
|
|
166
|
-
throw new
|
|
173
|
+
throw new TypeError(
|
|
167
174
|
`importHook must return a static module record, got ${q(
|
|
168
175
|
staticModuleRecord,
|
|
169
176
|
)}`,
|
package/src/module-load.js
CHANGED
|
@@ -7,17 +7,30 @@
|
|
|
7
7
|
// the particular compartment's "resolveHook".
|
|
8
8
|
|
|
9
9
|
import {
|
|
10
|
-
Promise,
|
|
11
|
-
TypeError,
|
|
12
10
|
ReferenceError,
|
|
11
|
+
TypeError,
|
|
12
|
+
Map,
|
|
13
|
+
Set,
|
|
14
|
+
arrayJoin,
|
|
15
|
+
arrayMap,
|
|
16
|
+
arrayPush,
|
|
13
17
|
create,
|
|
14
|
-
values,
|
|
15
18
|
freeze,
|
|
19
|
+
mapGet,
|
|
20
|
+
mapHas,
|
|
21
|
+
mapSet,
|
|
22
|
+
setAdd,
|
|
23
|
+
promiseCatch,
|
|
24
|
+
promiseThen,
|
|
25
|
+
values,
|
|
26
|
+
weakmapGet,
|
|
16
27
|
} from './commons.js';
|
|
17
28
|
import { assert } from './error/assert.js';
|
|
18
29
|
|
|
19
30
|
const { details: d, quote: q } = assert;
|
|
20
31
|
|
|
32
|
+
const noop = () => {};
|
|
33
|
+
|
|
21
34
|
// `makeAlias` constructs compartment specifier tuples for the `aliases`
|
|
22
35
|
// private field of compartments.
|
|
23
36
|
// These aliases allow a compartment to alias an internal module specifier to a
|
|
@@ -47,8 +60,12 @@ const loadRecord = async (
|
|
|
47
60
|
compartment,
|
|
48
61
|
moduleSpecifier,
|
|
49
62
|
staticModuleRecord,
|
|
63
|
+
pendingJobs,
|
|
64
|
+
moduleLoads,
|
|
65
|
+
errors,
|
|
50
66
|
) => {
|
|
51
|
-
const { resolveHook, moduleRecords } =
|
|
67
|
+
const { resolveHook, moduleRecords } = weakmapGet(
|
|
68
|
+
compartmentPrivateFields,
|
|
52
69
|
compartment,
|
|
53
70
|
);
|
|
54
71
|
|
|
@@ -65,18 +82,29 @@ const loadRecord = async (
|
|
|
65
82
|
resolvedImports,
|
|
66
83
|
});
|
|
67
84
|
|
|
68
|
-
//
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
85
|
+
// Enqueue jobs to load this module's shallow dependencies.
|
|
86
|
+
for (const fullSpecifier of values(resolvedImports)) {
|
|
87
|
+
// Behold: recursion.
|
|
88
|
+
// eslint-disable-next-line no-use-before-define
|
|
89
|
+
const dependencyLoaded = memoizedLoadWithErrorAnnotation(
|
|
90
|
+
compartmentPrivateFields,
|
|
91
|
+
moduleAliases,
|
|
92
|
+
compartment,
|
|
93
|
+
fullSpecifier,
|
|
94
|
+
pendingJobs,
|
|
95
|
+
moduleLoads,
|
|
96
|
+
errors,
|
|
97
|
+
);
|
|
98
|
+
setAdd(
|
|
99
|
+
pendingJobs,
|
|
100
|
+
promiseThen(dependencyLoaded, noop, error => {
|
|
101
|
+
arrayPush(errors, error);
|
|
102
|
+
}),
|
|
103
|
+
);
|
|
104
|
+
}
|
|
79
105
|
|
|
106
|
+
// Memoize.
|
|
107
|
+
mapSet(moduleRecords, moduleSpecifier, moduleRecord);
|
|
80
108
|
return moduleRecord;
|
|
81
109
|
};
|
|
82
110
|
|
|
@@ -85,13 +113,14 @@ const loadWithoutErrorAnnotation = async (
|
|
|
85
113
|
moduleAliases,
|
|
86
114
|
compartment,
|
|
87
115
|
moduleSpecifier,
|
|
116
|
+
pendingJobs,
|
|
117
|
+
moduleLoads,
|
|
118
|
+
errors,
|
|
88
119
|
) => {
|
|
89
|
-
const {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
moduleRecords,
|
|
94
|
-
} = compartmentPrivateFields.get(compartment);
|
|
120
|
+
const { importHook, moduleMap, moduleMapHook, moduleRecords } = weakmapGet(
|
|
121
|
+
compartmentPrivateFields,
|
|
122
|
+
compartment,
|
|
123
|
+
);
|
|
95
124
|
|
|
96
125
|
// Follow moduleMap, or moduleMapHook if present.
|
|
97
126
|
let aliasNamespace = moduleMap[moduleSpecifier];
|
|
@@ -99,6 +128,7 @@ const loadWithoutErrorAnnotation = async (
|
|
|
99
128
|
aliasNamespace = moduleMapHook(moduleSpecifier);
|
|
100
129
|
}
|
|
101
130
|
if (typeof aliasNamespace === 'string') {
|
|
131
|
+
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
102
132
|
assert.fail(
|
|
103
133
|
d`Cannot map module ${q(moduleSpecifier)} to ${q(
|
|
104
134
|
aliasNamespace,
|
|
@@ -106,8 +136,9 @@ const loadWithoutErrorAnnotation = async (
|
|
|
106
136
|
TypeError,
|
|
107
137
|
);
|
|
108
138
|
} else if (aliasNamespace !== undefined) {
|
|
109
|
-
const alias = moduleAliases
|
|
139
|
+
const alias = weakmapGet(moduleAliases, aliasNamespace);
|
|
110
140
|
if (alias === undefined) {
|
|
141
|
+
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
111
142
|
assert.fail(
|
|
112
143
|
d`Cannot map module ${q(
|
|
113
144
|
moduleSpecifier,
|
|
@@ -117,25 +148,27 @@ const loadWithoutErrorAnnotation = async (
|
|
|
117
148
|
}
|
|
118
149
|
// Behold: recursion.
|
|
119
150
|
// eslint-disable-next-line no-use-before-define
|
|
120
|
-
const aliasRecord = await
|
|
151
|
+
const aliasRecord = await memoizedLoadWithErrorAnnotation(
|
|
121
152
|
compartmentPrivateFields,
|
|
122
153
|
moduleAliases,
|
|
123
154
|
alias.compartment,
|
|
124
155
|
alias.specifier,
|
|
156
|
+
pendingJobs,
|
|
157
|
+
moduleLoads,
|
|
158
|
+
errors,
|
|
125
159
|
);
|
|
126
|
-
|
|
127
|
-
moduleRecords.set(moduleSpecifier, aliasRecord);
|
|
160
|
+
mapSet(moduleRecords, moduleSpecifier, aliasRecord);
|
|
128
161
|
return aliasRecord;
|
|
129
162
|
}
|
|
130
163
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
return moduleRecords.get(moduleSpecifier);
|
|
164
|
+
if (mapHas(moduleRecords, moduleSpecifier)) {
|
|
165
|
+
return mapGet(moduleRecords, moduleSpecifier);
|
|
134
166
|
}
|
|
135
167
|
|
|
136
168
|
const staticModuleRecord = await importHook(moduleSpecifier);
|
|
137
169
|
|
|
138
170
|
if (staticModuleRecord === null || typeof staticModuleRecord !== 'object') {
|
|
171
|
+
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
139
172
|
assert.fail(
|
|
140
173
|
d`importHook must return a promise for an object, for module ${q(
|
|
141
174
|
moduleSpecifier,
|
|
@@ -156,9 +189,11 @@ const loadWithoutErrorAnnotation = async (
|
|
|
156
189
|
aliasCompartment,
|
|
157
190
|
aliasSpecifier,
|
|
158
191
|
aliasModuleRecord,
|
|
192
|
+
pendingJobs,
|
|
193
|
+
moduleLoads,
|
|
194
|
+
errors,
|
|
159
195
|
);
|
|
160
|
-
|
|
161
|
-
moduleRecords.set(moduleSpecifier, aliasRecord);
|
|
196
|
+
mapSet(moduleRecords, moduleSpecifier, aliasRecord);
|
|
162
197
|
return aliasRecord;
|
|
163
198
|
}
|
|
164
199
|
|
|
@@ -168,33 +203,123 @@ const loadWithoutErrorAnnotation = async (
|
|
|
168
203
|
compartment,
|
|
169
204
|
moduleSpecifier,
|
|
170
205
|
staticModuleRecord,
|
|
206
|
+
pendingJobs,
|
|
207
|
+
moduleLoads,
|
|
208
|
+
errors,
|
|
209
|
+
);
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
const memoizedLoadWithErrorAnnotation = async (
|
|
213
|
+
compartmentPrivateFields,
|
|
214
|
+
moduleAliases,
|
|
215
|
+
compartment,
|
|
216
|
+
moduleSpecifier,
|
|
217
|
+
pendingJobs,
|
|
218
|
+
moduleLoads,
|
|
219
|
+
errors,
|
|
220
|
+
) => {
|
|
221
|
+
const { name: compartmentName } = weakmapGet(
|
|
222
|
+
compartmentPrivateFields,
|
|
223
|
+
compartment,
|
|
224
|
+
);
|
|
225
|
+
|
|
226
|
+
// Prevent data-lock from recursion into branches visited in dependent loads.
|
|
227
|
+
let compartmentLoading = mapGet(moduleLoads, compartment);
|
|
228
|
+
if (compartmentLoading === undefined) {
|
|
229
|
+
compartmentLoading = new Map();
|
|
230
|
+
mapSet(moduleLoads, compartment, compartmentLoading);
|
|
231
|
+
}
|
|
232
|
+
let moduleLoading = mapGet(compartmentLoading, moduleSpecifier);
|
|
233
|
+
if (moduleLoading !== undefined) {
|
|
234
|
+
return moduleLoading;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
moduleLoading = promiseCatch(
|
|
238
|
+
loadWithoutErrorAnnotation(
|
|
239
|
+
compartmentPrivateFields,
|
|
240
|
+
moduleAliases,
|
|
241
|
+
compartment,
|
|
242
|
+
moduleSpecifier,
|
|
243
|
+
pendingJobs,
|
|
244
|
+
moduleLoads,
|
|
245
|
+
errors,
|
|
246
|
+
),
|
|
247
|
+
error => {
|
|
248
|
+
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
249
|
+
assert.note(
|
|
250
|
+
error,
|
|
251
|
+
d`${error.message}, loading ${q(moduleSpecifier)} in compartment ${q(
|
|
252
|
+
compartmentName,
|
|
253
|
+
)}`,
|
|
254
|
+
);
|
|
255
|
+
throw error;
|
|
256
|
+
},
|
|
171
257
|
);
|
|
258
|
+
|
|
259
|
+
mapSet(compartmentLoading, moduleSpecifier, moduleLoading);
|
|
260
|
+
|
|
261
|
+
return moduleLoading;
|
|
172
262
|
};
|
|
173
263
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
264
|
+
/*
|
|
265
|
+
* `load` asynchronously gathers the `StaticModuleRecord`s for a module and its
|
|
266
|
+
* transitive dependencies.
|
|
267
|
+
* The module records refer to each other by a reference to the dependency's
|
|
268
|
+
* compartment and the specifier of the module within its own compartment.
|
|
269
|
+
* This graph is then ready to be synchronously linked and executed.
|
|
270
|
+
*/
|
|
179
271
|
export const load = async (
|
|
180
272
|
compartmentPrivateFields,
|
|
181
273
|
moduleAliases,
|
|
182
274
|
compartment,
|
|
183
275
|
moduleSpecifier,
|
|
184
276
|
) => {
|
|
185
|
-
|
|
277
|
+
const { name: compartmentName } = weakmapGet(
|
|
278
|
+
compartmentPrivateFields,
|
|
279
|
+
compartment,
|
|
280
|
+
);
|
|
281
|
+
|
|
282
|
+
/** @type {Set<Promise<undefined>>} */
|
|
283
|
+
const pendingJobs = new Set();
|
|
284
|
+
/** @type {Map<Object, Map<string, Promise<Record>>} */
|
|
285
|
+
const moduleLoads = new Map();
|
|
286
|
+
/** @type {Array<Error>} */
|
|
287
|
+
const errors = [];
|
|
288
|
+
|
|
289
|
+
const dependencyLoaded = memoizedLoadWithErrorAnnotation(
|
|
186
290
|
compartmentPrivateFields,
|
|
187
291
|
moduleAliases,
|
|
188
292
|
compartment,
|
|
189
293
|
moduleSpecifier,
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
294
|
+
pendingJobs,
|
|
295
|
+
moduleLoads,
|
|
296
|
+
errors,
|
|
297
|
+
);
|
|
298
|
+
setAdd(
|
|
299
|
+
pendingJobs,
|
|
300
|
+
promiseThen(dependencyLoaded, noop, error => {
|
|
301
|
+
arrayPush(errors, error);
|
|
302
|
+
}),
|
|
303
|
+
);
|
|
304
|
+
|
|
305
|
+
// Drain pending jobs queue.
|
|
306
|
+
// Each job is a promise for undefined, regardless of success or failure.
|
|
307
|
+
// Before we add a job to the queue, we catch any error and push it into the
|
|
308
|
+
// `errors` accumulator.
|
|
309
|
+
for (const job of pendingJobs) {
|
|
310
|
+
// eslint-disable-next-line no-await-in-loop
|
|
311
|
+
await job;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// Throw an aggregate error if there were any errors.
|
|
315
|
+
if (errors.length > 0) {
|
|
316
|
+
throw new TypeError(
|
|
317
|
+
`Failed to load module ${q(moduleSpecifier)} in package ${q(
|
|
318
|
+
compartmentName,
|
|
319
|
+
)} (${errors.length} underlying failures: ${arrayJoin(
|
|
320
|
+
arrayMap(errors, error => error.message),
|
|
321
|
+
', ',
|
|
196
322
|
)}`,
|
|
197
323
|
);
|
|
198
|
-
|
|
199
|
-
});
|
|
324
|
+
}
|
|
200
325
|
};
|
package/src/module-proxy.js
CHANGED
|
@@ -16,12 +16,16 @@ import {
|
|
|
16
16
|
TypeError,
|
|
17
17
|
create,
|
|
18
18
|
freeze,
|
|
19
|
+
mapGet,
|
|
20
|
+
mapHas,
|
|
21
|
+
mapSet,
|
|
19
22
|
ownKeys,
|
|
20
23
|
reflectGet,
|
|
21
24
|
reflectGetOwnPropertyDescriptor,
|
|
22
25
|
reflectHas,
|
|
23
26
|
reflectIsExtensible,
|
|
24
27
|
reflectPreventExtensions,
|
|
28
|
+
weakmapSet,
|
|
25
29
|
} from './commons.js';
|
|
26
30
|
import { assert } from './error/assert.js';
|
|
27
31
|
|
|
@@ -155,10 +159,14 @@ export const getDeferredExports = (
|
|
|
155
159
|
specifier,
|
|
156
160
|
) => {
|
|
157
161
|
const { deferredExports } = compartmentPrivateFields;
|
|
158
|
-
if (!deferredExports
|
|
162
|
+
if (!mapHas(deferredExports, specifier)) {
|
|
159
163
|
const deferred = deferExports();
|
|
160
|
-
|
|
161
|
-
|
|
164
|
+
weakmapSet(
|
|
165
|
+
moduleAliases,
|
|
166
|
+
deferred.exportsProxy,
|
|
167
|
+
makeAlias(compartment, specifier),
|
|
168
|
+
);
|
|
169
|
+
mapSet(deferredExports, specifier, deferred);
|
|
162
170
|
}
|
|
163
|
-
return deferredExports
|
|
171
|
+
return mapGet(deferredExports, specifier);
|
|
164
172
|
};
|
package/src/scope-constants.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
arrayFilter,
|
|
2
3
|
arrayIncludes,
|
|
3
4
|
getOwnPropertyDescriptor,
|
|
4
5
|
getOwnPropertyNames,
|
|
@@ -152,18 +153,20 @@ export const getScopeConstants = (globalObject, localObject = {}) => {
|
|
|
152
153
|
const localNames = getOwnPropertyNames(localObject);
|
|
153
154
|
|
|
154
155
|
// Collect all valid & immutable identifiers from the endowments.
|
|
155
|
-
const localConstants =
|
|
156
|
+
const localConstants = arrayFilter(
|
|
157
|
+
localNames,
|
|
156
158
|
name =>
|
|
157
159
|
isValidIdentifierName(name) && isImmutableDataProperty(localObject, name),
|
|
158
160
|
);
|
|
159
161
|
|
|
160
162
|
// Collect all valid & immutable identifiers from the global that
|
|
161
163
|
// are also not present in the endwoments (immutable or not).
|
|
162
|
-
const globalConstants =
|
|
164
|
+
const globalConstants = arrayFilter(
|
|
165
|
+
globalNames,
|
|
163
166
|
name =>
|
|
164
167
|
// Can't define a constant: it would prevent a
|
|
165
168
|
// lookup on the endowments.
|
|
166
|
-
!localNames
|
|
169
|
+
!arrayIncludes(localNames, name) &&
|
|
167
170
|
isValidIdentifierName(name) &&
|
|
168
171
|
isImmutableDataProperty(globalObject, name),
|
|
169
172
|
);
|
package/src/scope-handler.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
|
-
Error,
|
|
3
2
|
FERAL_EVAL,
|
|
4
3
|
Proxy,
|
|
5
4
|
String,
|
|
5
|
+
TypeError,
|
|
6
|
+
create,
|
|
6
7
|
freeze,
|
|
7
8
|
getOwnPropertyDescriptor,
|
|
9
|
+
getOwnPropertyDescriptors,
|
|
8
10
|
globalThis,
|
|
9
11
|
immutableObject,
|
|
10
12
|
objectHasOwnProperty,
|
|
@@ -22,18 +24,22 @@ const { details: d, quote: q } = assert;
|
|
|
22
24
|
* It's made from a proxy with a get trap that throws. It's safe to
|
|
23
25
|
* create one and share it between all scopeHandlers.
|
|
24
26
|
*/
|
|
25
|
-
const alwaysThrowHandler = new Proxy(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
27
|
+
const alwaysThrowHandler = new Proxy(
|
|
28
|
+
immutableObject,
|
|
29
|
+
freeze({
|
|
30
|
+
get(_shadow, prop) {
|
|
31
|
+
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
32
|
+
assert.fail(
|
|
33
|
+
d`Please report unexpected scope handler trap: ${q(String(prop))}`,
|
|
34
|
+
);
|
|
35
|
+
},
|
|
36
|
+
}),
|
|
37
|
+
);
|
|
32
38
|
|
|
33
39
|
/*
|
|
34
40
|
* createScopeHandler()
|
|
35
41
|
* ScopeHandler manages a Proxy which serves as the global scope for the
|
|
36
|
-
*
|
|
42
|
+
* safeEvaluate operation (the Proxy is the argument of a 'with' binding).
|
|
37
43
|
* As described in createSafeEvaluator(), it has several functions:
|
|
38
44
|
* - allow the very first (and only the very first) use of 'eval' to map to
|
|
39
45
|
* the real (unsafe) eval function, so it acts as a 'direct eval' and can
|
|
@@ -65,11 +71,7 @@ export const createScopeHandler = (
|
|
|
65
71
|
return wasSet;
|
|
66
72
|
};
|
|
67
73
|
|
|
68
|
-
const
|
|
69
|
-
// The scope handler throws if any trap other than get/set/has are run
|
|
70
|
-
// (e.g. getOwnPropertyDescriptors, apply, getPrototypeOf).
|
|
71
|
-
__proto__: alwaysThrowHandler,
|
|
72
|
-
|
|
74
|
+
const scopeProxyHandlerProperties = {
|
|
73
75
|
get(_shadow, prop) {
|
|
74
76
|
if (typeof prop === 'symbol') {
|
|
75
77
|
return undefined;
|
|
@@ -150,9 +152,20 @@ export const createScopeHandler = (
|
|
|
150
152
|
// at the expense of 'typeof' being wrong for those properties. For
|
|
151
153
|
// example, in the browser, evaluating 'document = 3', will add
|
|
152
154
|
// a property to globalObject instead of throwing a ReferenceError.
|
|
155
|
+
|
|
156
|
+
// !!!!! WARNING: DANGER ZONE !!!!!!
|
|
157
|
+
// The order of the conditions in the `||` expression below is of the
|
|
158
|
+
// utmost importance. Under no circumstances should `eval` be checked
|
|
159
|
+
// after `globalObject`. The prototype of the global object is under
|
|
160
|
+
// full control of user code and may be replaced by a proxy with a
|
|
161
|
+
// `has` trap. If we allow that trap to trigger while the
|
|
162
|
+
// `allowNextEvalToBeUnsafe` flag is down, it could allow user code
|
|
163
|
+
// to get a hold of `FERAL_EVAL`, resulting in a complete escape of
|
|
164
|
+
// the compartment.
|
|
165
|
+
// !!!!! WARNING: DANGER ZONE !!!!!!
|
|
153
166
|
return (
|
|
154
167
|
sloppyGlobalsMode ||
|
|
155
|
-
prop === 'eval' ||
|
|
168
|
+
(allowNextEvalToBeUnsafe && prop === 'eval') ||
|
|
156
169
|
prop in localObject ||
|
|
157
170
|
prop in globalObject ||
|
|
158
171
|
prop in globalThis
|
|
@@ -173,13 +186,24 @@ export const createScopeHandler = (
|
|
|
173
186
|
getOwnPropertyDescriptor(_target, prop) {
|
|
174
187
|
// Coerce with `String` in case prop is a symbol.
|
|
175
188
|
const quotedProp = q(String(prop));
|
|
189
|
+
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
176
190
|
console.warn(
|
|
177
191
|
`getOwnPropertyDescriptor trap on scopeHandler for ${quotedProp}`,
|
|
178
|
-
new
|
|
192
|
+
new TypeError().stack,
|
|
179
193
|
);
|
|
180
194
|
return undefined;
|
|
181
195
|
},
|
|
182
|
-
}
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
// The scope handler's prototype is a proxy that throws if any trap other
|
|
199
|
+
// than get/set/has are run (like getOwnPropertyDescriptors, apply,
|
|
200
|
+
// getPrototypeOf).
|
|
201
|
+
const scopeHandler = freeze(
|
|
202
|
+
create(
|
|
203
|
+
alwaysThrowHandler,
|
|
204
|
+
getOwnPropertyDescriptors(scopeProxyHandlerProperties),
|
|
205
|
+
),
|
|
206
|
+
);
|
|
183
207
|
|
|
184
208
|
return {
|
|
185
209
|
admitOneUnsafeEvalNext,
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
Date,
|
|
5
|
+
TypeError,
|
|
6
|
+
apply,
|
|
7
|
+
construct,
|
|
8
|
+
defineProperties,
|
|
9
|
+
} from './commons.js';
|
|
4
10
|
|
|
5
11
|
export default function tameDateConstructor(dateTaming = 'safe') {
|
|
6
12
|
if (dateTaming !== 'safe' && dateTaming !== 'unsafe') {
|
|
7
|
-
throw new
|
|
13
|
+
throw new TypeError(`unrecognized dateTaming ${dateTaming}`);
|
|
8
14
|
}
|
|
9
15
|
const OriginalDate = Date;
|
|
10
16
|
const DatePrototype = OriginalDate.prototype;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
TypeError,
|
|
5
|
+
globalThis,
|
|
6
|
+
getOwnPropertyDescriptor,
|
|
7
|
+
defineProperty,
|
|
8
|
+
} from './commons.js';
|
|
9
|
+
|
|
10
|
+
export function tameDomains(domainTaming = 'safe') {
|
|
11
|
+
if (domainTaming !== 'safe' && domainTaming !== 'unsafe') {
|
|
12
|
+
throw new TypeError(`unrecognized domainTaming ${domainTaming}`);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (domainTaming === 'unsafe') {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Protect against the hazard presented by Node.js domains.
|
|
20
|
+
if (typeof globalThis.process === 'object' && globalThis.process !== null) {
|
|
21
|
+
// Check whether domains were initialized.
|
|
22
|
+
const domainDescriptor = getOwnPropertyDescriptor(
|
|
23
|
+
globalThis.process,
|
|
24
|
+
'domain',
|
|
25
|
+
);
|
|
26
|
+
if (domainDescriptor !== undefined && domainDescriptor.get !== undefined) {
|
|
27
|
+
// The domain descriptor on Node.js initially has value: null, which
|
|
28
|
+
// becomes a get, set pair after domains initialize.
|
|
29
|
+
throw new TypeError(
|
|
30
|
+
`SES failed to lockdown, Node.js domains have been initialized (SES_NO_DOMAINS)`,
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
// Prevent domains from initializing.
|
|
34
|
+
// This is clunky because the exception thrown from the domains package does
|
|
35
|
+
// not direct the user's gaze toward a knowledge base about the problem.
|
|
36
|
+
// The domain module merely throws an exception when it attempts to define
|
|
37
|
+
// the domain property of the process global during its initialization.
|
|
38
|
+
// We have no better recourse because Node.js uses defineProperty too.
|
|
39
|
+
defineProperty(globalThis.process, 'domain', {
|
|
40
|
+
value: null,
|
|
41
|
+
configurable: false,
|
|
42
|
+
writable: false,
|
|
43
|
+
enumerable: false,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -45,6 +45,7 @@ import {
|
|
|
45
45
|
export default function tameFunctionConstructors() {
|
|
46
46
|
try {
|
|
47
47
|
// Verify that the method is not callable.
|
|
48
|
+
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
48
49
|
FERAL_FUNCTION.prototype.constructor('return 1');
|
|
49
50
|
} catch (ignore) {
|
|
50
51
|
// Throws, no need to patch.
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
|
-
Error,
|
|
3
|
-
Object,
|
|
4
2
|
String,
|
|
5
3
|
TypeError,
|
|
6
|
-
getOwnPropertyNames,
|
|
7
4
|
defineProperty,
|
|
5
|
+
getOwnPropertyNames,
|
|
6
|
+
isObject,
|
|
7
|
+
regexpExec,
|
|
8
8
|
} from './commons.js';
|
|
9
9
|
import { assert } from './error/assert.js';
|
|
10
10
|
|
|
@@ -39,7 +39,7 @@ const nonLocaleCompare = tamedMethods.localeCompare;
|
|
|
39
39
|
|
|
40
40
|
export default function tameLocaleMethods(intrinsics, localeTaming = 'safe') {
|
|
41
41
|
if (localeTaming !== 'safe' && localeTaming !== 'unsafe') {
|
|
42
|
-
throw new
|
|
42
|
+
throw new TypeError(`unrecognized localeTaming ${localeTaming}`);
|
|
43
43
|
}
|
|
44
44
|
if (localeTaming === 'unsafe') {
|
|
45
45
|
return;
|
|
@@ -51,9 +51,9 @@ export default function tameLocaleMethods(intrinsics, localeTaming = 'safe') {
|
|
|
51
51
|
|
|
52
52
|
for (const intrinsicName of getOwnPropertyNames(intrinsics)) {
|
|
53
53
|
const intrinsic = intrinsics[intrinsicName];
|
|
54
|
-
if (
|
|
54
|
+
if (isObject(intrinsic)) {
|
|
55
55
|
for (const methodName of getOwnPropertyNames(intrinsic)) {
|
|
56
|
-
const match = localePattern
|
|
56
|
+
const match = regexpExec(localePattern, methodName);
|
|
57
57
|
if (match) {
|
|
58
58
|
assert(
|
|
59
59
|
typeof intrinsic[methodName] === 'function',
|
package/src/tame-math-object.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
|
-
Error,
|
|
3
2
|
Math,
|
|
3
|
+
TypeError,
|
|
4
4
|
create,
|
|
5
5
|
getOwnPropertyDescriptors,
|
|
6
6
|
objectPrototype,
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
|
|
9
9
|
export default function tameMathObject(mathTaming = 'safe') {
|
|
10
10
|
if (mathTaming !== 'safe' && mathTaming !== 'unsafe') {
|
|
11
|
-
throw new
|
|
11
|
+
throw new TypeError(`unrecognized mathTaming ${mathTaming}`);
|
|
12
12
|
}
|
|
13
13
|
const originalMath = Math;
|
|
14
14
|
const initialMath = originalMath; // to follow the naming pattern
|