ses 0.15.16 → 0.15.19
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 +37 -0
- package/NEWS.md +9 -1
- package/README.md +4 -1
- package/dist/lockdown.cjs +184 -83
- package/dist/lockdown.mjs +184 -83
- package/dist/lockdown.umd.js +184 -83
- package/dist/lockdown.umd.min.js +1 -1
- package/dist/ses.cjs +184 -83
- package/dist/ses.mjs +184 -83
- package/dist/ses.umd.js +184 -83
- package/dist/ses.umd.min.js +1 -1
- package/index.d.ts +1 -1
- package/package.json +6 -6
- package/src/compartment-shim.js +2 -0
- package/src/environment-options.js +3 -3
- package/src/error/tame-v8-error-constructor.js +46 -12
- package/src/lockdown-shim.js +3 -9
- package/src/module-instance.js +18 -2
- package/src/module-load.js +4 -0
- package/src/tame-function-constructors.js +1 -1
- package/src/transforms.js +8 -8
- package/src/whitelist-intrinsics.js +9 -0
package/index.d.ts
CHANGED
|
@@ -33,7 +33,6 @@ export interface LockdownOptions {
|
|
|
33
33
|
overrideTaming?: 'moderate' | 'min' | 'severe';
|
|
34
34
|
overrideDebug?: Array<string>;
|
|
35
35
|
domainTaming?: 'safe' | 'unsafe';
|
|
36
|
-
__allowUnsafeMonkeyPatching__?: 'safe' | 'unsafe';
|
|
37
36
|
}
|
|
38
37
|
|
|
39
38
|
export type Lockdown = (options?: LockdownOptions) => void;
|
|
@@ -67,6 +66,7 @@ export type FinalStaticModuleType =
|
|
|
67
66
|
export interface RedirectStaticModuleInterface {
|
|
68
67
|
record: FinalStaticModuleType;
|
|
69
68
|
specifier: string;
|
|
69
|
+
importMeta?: any;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
export type StaticModuleType =
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ses",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.19",
|
|
4
4
|
"description": "Hardened JavaScript for Fearless Cooperation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"lockdown",
|
|
@@ -59,10 +59,10 @@
|
|
|
59
59
|
"test:platform-compatability": "node test/package/test.cjs"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
|
-
"@endo/compartment-mapper": "^0.7.
|
|
63
|
-
"@endo/eslint-config": "^0.5.
|
|
64
|
-
"@endo/static-module-record": "^0.7.
|
|
65
|
-
"@endo/test262-runner": "^0.1.
|
|
62
|
+
"@endo/compartment-mapper": "^0.7.9",
|
|
63
|
+
"@endo/eslint-config": "^0.5.1",
|
|
64
|
+
"@endo/static-module-record": "^0.7.8",
|
|
65
|
+
"@endo/test262-runner": "^0.1.28",
|
|
66
66
|
"ava": "^3.12.1",
|
|
67
67
|
"babel-eslint": "^10.0.3",
|
|
68
68
|
"c8": "^7.7.3",
|
|
@@ -179,5 +179,5 @@
|
|
|
179
179
|
],
|
|
180
180
|
"timeout": "2m"
|
|
181
181
|
},
|
|
182
|
-
"gitHead": "
|
|
182
|
+
"gitHead": "3f129c5d6e1bde4fd5fe399c24a6205e660a4aad"
|
|
183
183
|
}
|
package/src/compartment-shim.js
CHANGED
|
@@ -215,6 +215,7 @@ export const makeCompartmentConstructor = (
|
|
|
215
215
|
resolveHook,
|
|
216
216
|
importHook,
|
|
217
217
|
moduleMapHook,
|
|
218
|
+
importMetaHook,
|
|
218
219
|
} = options;
|
|
219
220
|
const globalTransforms = [...transforms, ...__shimTransforms__];
|
|
220
221
|
|
|
@@ -316,6 +317,7 @@ export const makeCompartmentConstructor = (
|
|
|
316
317
|
importHook,
|
|
317
318
|
moduleMap,
|
|
318
319
|
moduleMapHook,
|
|
320
|
+
importMetaHook,
|
|
319
321
|
moduleRecords,
|
|
320
322
|
__shimTransforms__,
|
|
321
323
|
deferredExports,
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
// environment-options needs to be imported quite early, and so should
|
|
4
4
|
// avoid importing from anything but commons.js and assert.js
|
|
5
|
-
import { arrayPush,
|
|
5
|
+
import { arrayPush, freeze } from './commons.js';
|
|
6
6
|
import { assert } from './error/assert.js';
|
|
7
7
|
|
|
8
8
|
const { details: X, quote: q } = assert;
|
|
@@ -116,10 +116,10 @@ export const makeEnvironmentCaptor = aGlobal => {
|
|
|
116
116
|
freeze(getEnvironmentOption);
|
|
117
117
|
|
|
118
118
|
const getCapturedEnvironmentOptionNames = () => {
|
|
119
|
-
return freeze(
|
|
119
|
+
return freeze([...capturedEnvironmentOptionNames]);
|
|
120
120
|
};
|
|
121
121
|
freeze(getCapturedEnvironmentOptionNames);
|
|
122
122
|
|
|
123
|
-
return { getEnvironmentOption, getCapturedEnvironmentOptionNames };
|
|
123
|
+
return freeze({ getEnvironmentOption, getCapturedEnvironmentOptionNames });
|
|
124
124
|
};
|
|
125
125
|
freeze(makeEnvironmentCaptor);
|
|
@@ -13,7 +13,6 @@ import {
|
|
|
13
13
|
regexpExec,
|
|
14
14
|
regexpTest,
|
|
15
15
|
weakmapGet,
|
|
16
|
-
weakmapHas,
|
|
17
16
|
weakmapSet,
|
|
18
17
|
weaksetAdd,
|
|
19
18
|
weaksetHas,
|
|
@@ -165,6 +164,9 @@ export const tameV8ErrorConstructor = (
|
|
|
165
164
|
errorTaming,
|
|
166
165
|
stackFiltering,
|
|
167
166
|
) => {
|
|
167
|
+
// TODO: Proper CallSite types
|
|
168
|
+
/** @typedef {{}} CallSite */
|
|
169
|
+
|
|
168
170
|
const originalCaptureStackTrace = OriginalError.captureStackTrace;
|
|
169
171
|
|
|
170
172
|
// const callSiteFilter = _callSite => true;
|
|
@@ -190,9 +192,23 @@ export const tameV8ErrorConstructor = (
|
|
|
190
192
|
'',
|
|
191
193
|
);
|
|
192
194
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
195
|
+
/**
|
|
196
|
+
* @typedef {object} StructuredStackInfo
|
|
197
|
+
* @property {CallSite[]} callSites
|
|
198
|
+
* @property {undefined} [stackString]
|
|
199
|
+
*/
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* @typedef {object} ParsedStackInfo
|
|
203
|
+
* @property {undefined} [callSites]
|
|
204
|
+
* @property {string} stackString
|
|
205
|
+
*/
|
|
206
|
+
|
|
207
|
+
// Mapping from error instance to the stack for that instance.
|
|
208
|
+
// The stack info is either the structured stack trace
|
|
209
|
+
// or the generated tamed stack string
|
|
210
|
+
/** @type {WeakMap<Error, ParsedStackInfo | StructuredStackInfo} */
|
|
211
|
+
const stackInfos = new WeakMap();
|
|
196
212
|
|
|
197
213
|
// Use concise methods to obtain named functions without constructors.
|
|
198
214
|
const tamedMethods = {
|
|
@@ -214,23 +230,41 @@ export const tameV8ErrorConstructor = (
|
|
|
214
230
|
// string associated with an error.
|
|
215
231
|
// See https://tc39.es/proposal-error-stacks/
|
|
216
232
|
getStackString(error) {
|
|
217
|
-
|
|
233
|
+
let stackInfo = weakmapGet(stackInfos, error);
|
|
234
|
+
|
|
235
|
+
if (stackInfo === undefined) {
|
|
236
|
+
// The following will call `prepareStackTrace()` synchronously
|
|
237
|
+
// which will populate stackInfos
|
|
218
238
|
// eslint-disable-next-line no-void
|
|
219
239
|
void error.stack;
|
|
240
|
+
stackInfo = weakmapGet(stackInfos, error);
|
|
241
|
+
if (!stackInfo) {
|
|
242
|
+
stackInfo = { stackString: '' };
|
|
243
|
+
weakmapSet(stackInfos, error, stackInfo);
|
|
244
|
+
}
|
|
220
245
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
246
|
+
|
|
247
|
+
// prepareStackTrace() may generate the stackString
|
|
248
|
+
// if errorTaming === 'unsafe'
|
|
249
|
+
|
|
250
|
+
if (stackInfo.stackString !== undefined) {
|
|
251
|
+
return stackInfo.stackString;
|
|
224
252
|
}
|
|
225
|
-
|
|
253
|
+
|
|
254
|
+
const stackString = stackStringFromSST(error, stackInfo.callSites);
|
|
255
|
+
weakmapSet(stackInfos, error, { stackString });
|
|
256
|
+
|
|
257
|
+
return stackString;
|
|
226
258
|
},
|
|
227
259
|
prepareStackTrace(error, sst) {
|
|
228
|
-
weakmapSet(ssts, error, sst);
|
|
229
260
|
if (errorTaming === 'unsafe') {
|
|
230
261
|
const stackString = stackStringFromSST(error, sst);
|
|
262
|
+
weakmapSet(stackInfos, error, { stackString });
|
|
231
263
|
return `${error}${stackString}`;
|
|
264
|
+
} else {
|
|
265
|
+
weakmapSet(stackInfos, error, { callSites: sst });
|
|
266
|
+
return '';
|
|
232
267
|
}
|
|
233
|
-
return '';
|
|
234
268
|
},
|
|
235
269
|
};
|
|
236
270
|
|
|
@@ -265,7 +299,7 @@ export const tameV8ErrorConstructor = (
|
|
|
265
299
|
// Use concise methods to obtain named functions without constructors.
|
|
266
300
|
const systemMethods = {
|
|
267
301
|
prepareStackTrace(error, sst) {
|
|
268
|
-
weakmapSet(
|
|
302
|
+
weakmapSet(stackInfos, error, { callSites: sst });
|
|
269
303
|
return inputPrepareFn(error, safeV8SST(sst));
|
|
270
304
|
},
|
|
271
305
|
};
|
package/src/lockdown-shim.js
CHANGED
|
@@ -176,10 +176,6 @@ export const repairIntrinsics = (options = {}) => {
|
|
|
176
176
|
/** @param {string} debugName */
|
|
177
177
|
debugName => debugName !== '',
|
|
178
178
|
),
|
|
179
|
-
__allowUnsafeMonkeyPatching__ = getenv(
|
|
180
|
-
'__LOCKDOWN_ALLOW_UNSAFE_MONKEY_PATCHING__',
|
|
181
|
-
'safe',
|
|
182
|
-
),
|
|
183
179
|
dateTaming = 'safe', // deprecated
|
|
184
180
|
mathTaming = 'safe', // deprecated
|
|
185
181
|
...extraOptions
|
|
@@ -386,11 +382,9 @@ export const repairIntrinsics = (options = {}) => {
|
|
|
386
382
|
// @ts-ignore enablePropertyOverrides does its own input validation
|
|
387
383
|
enablePropertyOverrides(intrinsics, overrideTaming, overrideDebug);
|
|
388
384
|
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
harden(intrinsics);
|
|
393
|
-
}
|
|
385
|
+
// Finally register and optionally freeze all the intrinsics. This
|
|
386
|
+
// must be the operation that modifies the intrinsics.
|
|
387
|
+
harden(intrinsics);
|
|
394
388
|
|
|
395
389
|
// Reveal harden after lockdown.
|
|
396
390
|
// Harden is dangerous before lockdown because hardening just
|
package/src/module-instance.js
CHANGED
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
mapGet,
|
|
19
19
|
weakmapGet,
|
|
20
20
|
reflectHas,
|
|
21
|
+
assign,
|
|
21
22
|
} from './commons.js';
|
|
22
23
|
import { compartmentEvaluate } from './compartment-evaluate.js';
|
|
23
24
|
|
|
@@ -122,17 +123,23 @@ export const makeModuleInstance = (
|
|
|
122
123
|
moduleRecord,
|
|
123
124
|
importedInstances,
|
|
124
125
|
) => {
|
|
125
|
-
const {
|
|
126
|
+
const {
|
|
127
|
+
compartment,
|
|
128
|
+
moduleSpecifier,
|
|
129
|
+
staticModuleRecord,
|
|
130
|
+
importMeta: moduleRecordMeta,
|
|
131
|
+
} = moduleRecord;
|
|
126
132
|
const {
|
|
127
133
|
reexports: exportAlls = [],
|
|
128
134
|
__syncModuleProgram__: functorSource,
|
|
129
135
|
__fixedExportMap__: fixedExportMap = {},
|
|
130
136
|
__liveExportMap__: liveExportMap = {},
|
|
137
|
+
__needsImportMeta__: needsImportMeta = false,
|
|
131
138
|
} = staticModuleRecord;
|
|
132
139
|
|
|
133
140
|
const compartmentFields = weakmapGet(privateFields, compartment);
|
|
134
141
|
|
|
135
|
-
const { __shimTransforms__ } = compartmentFields;
|
|
142
|
+
const { __shimTransforms__, importMetaHook } = compartmentFields;
|
|
136
143
|
|
|
137
144
|
const { exportsProxy, proxiedExports, activate } = getDeferredExports(
|
|
138
145
|
compartment,
|
|
@@ -158,6 +165,14 @@ export const makeModuleInstance = (
|
|
|
158
165
|
// both initialize and update live bindings.
|
|
159
166
|
const liveVar = create(null);
|
|
160
167
|
|
|
168
|
+
const importMeta = create(null);
|
|
169
|
+
if (moduleRecordMeta) {
|
|
170
|
+
assign(importMeta, moduleRecordMeta);
|
|
171
|
+
}
|
|
172
|
+
if (needsImportMeta && importMetaHook) {
|
|
173
|
+
importMetaHook(moduleSpecifier, importMeta);
|
|
174
|
+
}
|
|
175
|
+
|
|
161
176
|
// {_localName_: [{get, set, notify}]} used to merge all the export updaters.
|
|
162
177
|
const localGetNotify = create(null);
|
|
163
178
|
|
|
@@ -438,6 +453,7 @@ export const makeModuleInstance = (
|
|
|
438
453
|
imports: freeze(imports),
|
|
439
454
|
onceVar: freeze(onceVar),
|
|
440
455
|
liveVar: freeze(liveVar),
|
|
456
|
+
importMeta,
|
|
441
457
|
}),
|
|
442
458
|
);
|
|
443
459
|
} catch (e) {
|
package/src/module-load.js
CHANGED
|
@@ -63,6 +63,7 @@ const loadRecord = async (
|
|
|
63
63
|
pendingJobs,
|
|
64
64
|
moduleLoads,
|
|
65
65
|
errors,
|
|
66
|
+
importMeta,
|
|
66
67
|
) => {
|
|
67
68
|
const { resolveHook, moduleRecords } = weakmapGet(
|
|
68
69
|
compartmentPrivateFields,
|
|
@@ -80,6 +81,7 @@ const loadRecord = async (
|
|
|
80
81
|
staticModuleRecord,
|
|
81
82
|
moduleSpecifier,
|
|
82
83
|
resolvedImports,
|
|
84
|
+
importMeta,
|
|
83
85
|
});
|
|
84
86
|
|
|
85
87
|
// Enqueue jobs to load this module's shallow dependencies.
|
|
@@ -181,6 +183,7 @@ const loadWithoutErrorAnnotation = async (
|
|
|
181
183
|
compartment: aliasCompartment = compartment,
|
|
182
184
|
specifier: aliasSpecifier = moduleSpecifier,
|
|
183
185
|
record: aliasModuleRecord,
|
|
186
|
+
importMeta,
|
|
184
187
|
} = staticModuleRecord;
|
|
185
188
|
|
|
186
189
|
const aliasRecord = await loadRecord(
|
|
@@ -192,6 +195,7 @@ const loadWithoutErrorAnnotation = async (
|
|
|
192
195
|
pendingJobs,
|
|
193
196
|
moduleLoads,
|
|
194
197
|
errors,
|
|
198
|
+
importMeta,
|
|
195
199
|
);
|
|
196
200
|
mapSet(moduleRecords, moduleSpecifier, aliasRecord);
|
|
197
201
|
return aliasRecord;
|
package/src/transforms.js
CHANGED
|
@@ -93,8 +93,8 @@ export const rejectHtmlComments = src => {
|
|
|
93
93
|
* not change the meaning of the program because it only changes the contents of
|
|
94
94
|
* those comments.
|
|
95
95
|
*
|
|
96
|
-
* @param {
|
|
97
|
-
* @returns {
|
|
96
|
+
* @param {string} src
|
|
97
|
+
* @returns {string}
|
|
98
98
|
*/
|
|
99
99
|
export const evadeHtmlCommentTest = src => {
|
|
100
100
|
const replaceFn = match => (match[0] === '<' ? '< ! --' : '-- >');
|
|
@@ -135,8 +135,8 @@ const importPattern = new FERAL_REG_EXP(
|
|
|
135
135
|
* something like that from something like importnotreally('power.js') which
|
|
136
136
|
* is perfectly safe.
|
|
137
137
|
*
|
|
138
|
-
* @param {
|
|
139
|
-
* @returns {
|
|
138
|
+
* @param {string} src
|
|
139
|
+
* @returns {string}
|
|
140
140
|
*/
|
|
141
141
|
export const rejectImportExpressions = src => {
|
|
142
142
|
const lineNumber = getLineNumber(src, importPattern);
|
|
@@ -162,8 +162,8 @@ export const rejectImportExpressions = src => {
|
|
|
162
162
|
* the meaning of the program, depending on the binding, if any, of the lexical
|
|
163
163
|
* variable `__import__`.
|
|
164
164
|
*
|
|
165
|
-
* @param {
|
|
166
|
-
* @returns {
|
|
165
|
+
* @param {string} src
|
|
166
|
+
* @returns {string}
|
|
167
167
|
*/
|
|
168
168
|
export const evadeImportExpressionTest = src => {
|
|
169
169
|
const replaceFn = (_, p1, p2) => `${p1}__import__${p2}`;
|
|
@@ -206,8 +206,8 @@ const someDirectEvalPattern = new FERAL_REG_EXP(
|
|
|
206
206
|
*
|
|
207
207
|
* Exported for unit tests.
|
|
208
208
|
*
|
|
209
|
-
* @param {
|
|
210
|
-
* @returns {
|
|
209
|
+
* @param {string} src
|
|
210
|
+
* @returns {string}
|
|
211
211
|
*/
|
|
212
212
|
export const rejectSomeDirectEvalExpressions = src => {
|
|
213
213
|
const lineNumber = getLineNumber(src, someDirectEvalPattern);
|
|
@@ -285,6 +285,15 @@ export default function whitelistIntrinsics(
|
|
|
285
285
|
delete obj[prop];
|
|
286
286
|
} catch (err) {
|
|
287
287
|
if (prop in obj) {
|
|
288
|
+
if (typeof obj === 'function' && prop === 'prototype') {
|
|
289
|
+
obj.prototype = undefined;
|
|
290
|
+
if (obj.prototype === undefined) {
|
|
291
|
+
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
292
|
+
console.warn(`Tolerating undeletable ${subPath} === undefined`);
|
|
293
|
+
// eslint-disable-next-line no-continue
|
|
294
|
+
continue;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
288
297
|
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
289
298
|
console.error(`failed to delete ${subPath}`, err);
|
|
290
299
|
} else {
|