ses 0.15.3 → 0.15.7
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 +44 -0
- package/NEWS.md +7 -0
- package/README.md +204 -10
- package/SECURITY.md +28 -15
- package/dist/lockdown.cjs +73 -7
- package/dist/lockdown.mjs +73 -7
- package/dist/lockdown.umd.js +73 -7
- package/dist/lockdown.umd.min.js +1 -1
- package/dist/ses.cjs +73 -7
- package/dist/ses.mjs +73 -7
- package/dist/ses.umd.js +73 -7
- package/dist/ses.umd.min.js +1 -1
- package/index.d.ts +113 -37
- package/package.json +8 -9
- package/src/commons.js +1 -0
- package/src/error/tame-console.js +5 -1
- package/src/lockdown-shim.js +42 -1
- package/src/tame-locale-methods.js +12 -0
- package/src/whitelist.js +6 -0
package/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable no-restricted-globals, vars-on-top, no-var */
|
|
1
2
|
|
|
2
3
|
// It's academically tempting to define a hardened type, but TypeScript doesn't
|
|
3
4
|
// strike a good balance in distinguishing "readonly" in the sense that you
|
|
@@ -31,8 +32,8 @@ export interface LockdownOptions {
|
|
|
31
32
|
|
|
32
33
|
export type Lockdown = (options?: LockdownOptions) => void;
|
|
33
34
|
|
|
34
|
-
export type __LiveExportsMap__ = Record<string, [string, boolean]
|
|
35
|
-
export type __FixedExportsMap__ = Record<string, [string]
|
|
35
|
+
export type __LiveExportsMap__ = Record<string, [string, boolean]>;
|
|
36
|
+
export type __FixedExportsMap__ = Record<string, [string]>;
|
|
36
37
|
|
|
37
38
|
export interface PrecompiledStaticModuleInterface {
|
|
38
39
|
imports: Array<string>;
|
|
@@ -46,33 +47,46 @@ export interface PrecompiledStaticModuleInterface {
|
|
|
46
47
|
export interface ThirdPartyStaticModuleInterface {
|
|
47
48
|
imports: Array<string>;
|
|
48
49
|
exports: Array<string>;
|
|
49
|
-
execute(
|
|
50
|
+
execute(
|
|
51
|
+
proxiedExports: Object,
|
|
52
|
+
compartment: Compartment,
|
|
53
|
+
resolvedImports: Record<string, string>,
|
|
54
|
+
): void;
|
|
50
55
|
}
|
|
51
56
|
|
|
52
|
-
export type FinalStaticModuleType =
|
|
57
|
+
export type FinalStaticModuleType =
|
|
58
|
+
| PrecompiledStaticModuleInterface
|
|
59
|
+
| ThirdPartyStaticModuleInterface;
|
|
53
60
|
|
|
54
61
|
export interface RedirectStaticModuleInterface {
|
|
55
|
-
record: FinalStaticModuleType
|
|
56
|
-
specifier: string
|
|
62
|
+
record: FinalStaticModuleType;
|
|
63
|
+
specifier: string;
|
|
57
64
|
}
|
|
58
65
|
|
|
59
|
-
export type StaticModuleType =
|
|
66
|
+
export type StaticModuleType =
|
|
67
|
+
| RedirectStaticModuleInterface
|
|
68
|
+
| FinalStaticModuleType;
|
|
60
69
|
|
|
61
|
-
export type ModuleExportsNamespace = Record<string, any
|
|
70
|
+
export type ModuleExportsNamespace = Record<string, any>;
|
|
62
71
|
|
|
63
72
|
export type Transform = (source: string) => string;
|
|
64
|
-
export type ResolveHook = (
|
|
73
|
+
export type ResolveHook = (
|
|
74
|
+
importSpecifier: string,
|
|
75
|
+
referrerSpecifier: string,
|
|
76
|
+
) => string;
|
|
65
77
|
export type ModuleMap = Record<string, string | ModuleExportsNamespace>;
|
|
66
|
-
export type ModuleMapHook = (
|
|
78
|
+
export type ModuleMapHook = (
|
|
79
|
+
moduleSpecifier: string,
|
|
80
|
+
) => string | ModuleExportsNamespace | void;
|
|
67
81
|
export type ImportHook = (moduleSpecifier: string) => Promise<StaticModuleType>;
|
|
68
82
|
|
|
69
83
|
export interface CompartmentOptions {
|
|
70
84
|
name?: string;
|
|
71
85
|
transforms?: Array<Transform>;
|
|
72
86
|
globalLexicals?: Record<string, any>;
|
|
73
|
-
moduleMapHook?: ModuleMapHook
|
|
74
|
-
importHook?: ImportHook
|
|
75
|
-
resolveHook?: ResolveHook
|
|
87
|
+
moduleMapHook?: ModuleMapHook;
|
|
88
|
+
importHook?: ImportHook;
|
|
89
|
+
resolveHook?: ResolveHook;
|
|
76
90
|
__shimTransforms__?: Array<Transform>;
|
|
77
91
|
}
|
|
78
92
|
|
|
@@ -85,20 +99,53 @@ export interface EvaluateOptions {
|
|
|
85
99
|
}
|
|
86
100
|
|
|
87
101
|
// The DetailsToken is an empty object literal.
|
|
88
|
-
export type DetailsToken = Record<any, never
|
|
89
|
-
export type Details = string | DetailsToken
|
|
102
|
+
export type DetailsToken = Record<any, never>;
|
|
103
|
+
export type Details = string | DetailsToken;
|
|
90
104
|
|
|
91
105
|
export interface AssertMakeErrorOptions {
|
|
106
|
+
errorName?: string;
|
|
92
107
|
}
|
|
93
108
|
|
|
94
|
-
type AssertTypeofBigint = (
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
type
|
|
100
|
-
|
|
101
|
-
|
|
109
|
+
type AssertTypeofBigint = (
|
|
110
|
+
specimen: any,
|
|
111
|
+
typeName: 'bigint',
|
|
112
|
+
details?: Details,
|
|
113
|
+
) => asserts specimen is bigint;
|
|
114
|
+
type AssertTypeofBoolean = (
|
|
115
|
+
specimen: any,
|
|
116
|
+
typeName: 'boolean',
|
|
117
|
+
details?: Details,
|
|
118
|
+
) => asserts specimen is boolean;
|
|
119
|
+
type AssertTypeofFunction = (
|
|
120
|
+
specimen: any,
|
|
121
|
+
typeName: 'function',
|
|
122
|
+
details?: Details,
|
|
123
|
+
) => asserts specimen is Function;
|
|
124
|
+
type AssertTypeofNumber = (
|
|
125
|
+
specimen: any,
|
|
126
|
+
typeName: 'number',
|
|
127
|
+
details?: Details,
|
|
128
|
+
) => asserts specimen is number;
|
|
129
|
+
type AssertTypeofObject = (
|
|
130
|
+
specimen: any,
|
|
131
|
+
typeName: 'object',
|
|
132
|
+
details?: Details,
|
|
133
|
+
) => asserts specimen is Record<any, any> | null;
|
|
134
|
+
type AssertTypeofString = (
|
|
135
|
+
specimen: any,
|
|
136
|
+
typeName: 'string',
|
|
137
|
+
details?: Details,
|
|
138
|
+
) => asserts specimen is string;
|
|
139
|
+
type AssertTypeofSymbol = (
|
|
140
|
+
specimen: any,
|
|
141
|
+
typeName: 'symbol',
|
|
142
|
+
details?: Details,
|
|
143
|
+
) => asserts specimen is symbol;
|
|
144
|
+
type AssertTypeofUndefined = (
|
|
145
|
+
specimen: any,
|
|
146
|
+
typeName: 'undefined',
|
|
147
|
+
details?: Details,
|
|
148
|
+
) => asserts specimen is undefined;
|
|
102
149
|
|
|
103
150
|
export type AssertTypeof = AssertTypeofBigint &
|
|
104
151
|
AssertTypeofBoolean &
|
|
@@ -109,24 +156,42 @@ export type AssertTypeof = AssertTypeofBigint &
|
|
|
109
156
|
AssertTypeofSymbol &
|
|
110
157
|
AssertTypeofUndefined;
|
|
111
158
|
|
|
112
|
-
export type Raise = (reason: Error) => void;
|
|
113
|
-
export type MakeAssert = (raise?: Raise, unredacted?: boolean) => Assert;
|
|
114
|
-
|
|
115
159
|
interface ToStringable {
|
|
116
|
-
toString(): string
|
|
160
|
+
toString(): string;
|
|
117
161
|
}
|
|
118
162
|
|
|
163
|
+
export type Raise = (reason: Error) => void;
|
|
164
|
+
// Behold: recursion.
|
|
165
|
+
// eslint-disable-next-line no-use-before-define
|
|
166
|
+
export type MakeAssert = (raise?: Raise, unredacted?: boolean) => Assert;
|
|
167
|
+
|
|
119
168
|
export interface Assert {
|
|
120
|
-
(
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
169
|
+
(
|
|
170
|
+
value: any,
|
|
171
|
+
details?: Details,
|
|
172
|
+
errorConstructor?: ErrorConstructor,
|
|
173
|
+
): asserts value;
|
|
174
|
+
typeof: AssertTypeof;
|
|
175
|
+
error(
|
|
176
|
+
details?: Details,
|
|
177
|
+
errorConstructor?: ErrorConstructor,
|
|
178
|
+
options?: AssertMakeErrorOptions,
|
|
179
|
+
): Error;
|
|
180
|
+
fail(details?: Details, errorConstructor?: ErrorConstructor): never;
|
|
181
|
+
equal(
|
|
182
|
+
left: any,
|
|
183
|
+
right: any,
|
|
184
|
+
details?: Details,
|
|
185
|
+
errorConstructor?: ErrorConstructor,
|
|
186
|
+
): void;
|
|
125
187
|
string(specimen: any, details?: Details): asserts specimen is string;
|
|
126
188
|
note(error: Error, details: Details): void;
|
|
127
|
-
details(
|
|
128
|
-
|
|
129
|
-
|
|
189
|
+
details(
|
|
190
|
+
template: TemplateStringsArray | string[],
|
|
191
|
+
...args: any
|
|
192
|
+
): DetailsToken;
|
|
193
|
+
quote(payload: any, spaces?: string | number): ToStringable;
|
|
194
|
+
makeAssert: MakeAssert;
|
|
130
195
|
}
|
|
131
196
|
|
|
132
197
|
declare global {
|
|
@@ -141,13 +206,24 @@ declare global {
|
|
|
141
206
|
* code in a context bound to a new global creates a new compartment.
|
|
142
207
|
*/
|
|
143
208
|
export class Compartment {
|
|
144
|
-
constructor(
|
|
209
|
+
constructor(
|
|
210
|
+
globals?: Object,
|
|
211
|
+
moduleMap?: ModuleMap,
|
|
212
|
+
options?: CompartmentOptions,
|
|
213
|
+
);
|
|
214
|
+
|
|
145
215
|
get globalThis(): Record<string, any>;
|
|
216
|
+
|
|
146
217
|
get name(): string;
|
|
218
|
+
|
|
147
219
|
evaluate(code: string): any;
|
|
148
|
-
|
|
220
|
+
|
|
221
|
+
import(specifier: string): Promise<{ namespace: ModuleExportsNamespace }>;
|
|
222
|
+
|
|
149
223
|
load(specifier: string): Promise<void>;
|
|
224
|
+
|
|
150
225
|
importNow(specifier: string): ModuleExportsNamespace;
|
|
226
|
+
|
|
151
227
|
module(specifier: string): ModuleExportsNamespace;
|
|
152
228
|
}
|
|
153
229
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ses",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.7",
|
|
4
4
|
"description": "Hardened JavaScript for Fearless Cooperation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"lockdown",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"build": "node scripts/bundle.js",
|
|
49
49
|
"clean": "rm -rf dist",
|
|
50
50
|
"cover": "c8 ava",
|
|
51
|
-
"demo": "
|
|
51
|
+
"demo": "python3 -m http.server",
|
|
52
52
|
"lint": "yarn lint:types && yarn lint:js",
|
|
53
53
|
"lint-fix": "eslint --fix .",
|
|
54
54
|
"lint:js": "eslint .",
|
|
@@ -59,10 +59,10 @@
|
|
|
59
59
|
"test:platform-compatability": "node test/package/test.cjs"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
|
-
"@endo/compartment-mapper": "^0.6.
|
|
63
|
-
"@endo/eslint-config": "^0.
|
|
64
|
-
"@endo/static-module-record": "^0.6.
|
|
65
|
-
"@endo/test262-runner": "^0.1.
|
|
62
|
+
"@endo/compartment-mapper": "^0.6.5",
|
|
63
|
+
"@endo/eslint-config": "^0.4.2",
|
|
64
|
+
"@endo/static-module-record": "^0.6.12",
|
|
65
|
+
"@endo/test262-runner": "^0.1.18",
|
|
66
66
|
"ava": "^3.12.1",
|
|
67
67
|
"babel-eslint": "^10.0.3",
|
|
68
68
|
"c8": "^7.7.3",
|
|
@@ -72,11 +72,10 @@
|
|
|
72
72
|
"eslint-plugin-eslint-comments": "^3.1.2",
|
|
73
73
|
"eslint-plugin-import": "^2.19.1",
|
|
74
74
|
"eslint-plugin-prettier": "^3.1.2",
|
|
75
|
-
"http-server": "^0.12.1",
|
|
76
75
|
"prettier": "^1.19.1",
|
|
77
76
|
"sinon": "8.0.4",
|
|
78
77
|
"terser": "^4.8.0",
|
|
79
|
-
"typescript": "^4.
|
|
78
|
+
"typescript": "^4.2.3"
|
|
80
79
|
},
|
|
81
80
|
"files": [
|
|
82
81
|
"LICENSE*",
|
|
@@ -179,5 +178,5 @@
|
|
|
179
178
|
],
|
|
180
179
|
"timeout": "2m"
|
|
181
180
|
},
|
|
182
|
-
"gitHead": "
|
|
181
|
+
"gitHead": "96df4cf238b245cc92c78e4af4667f405b8cf4f0"
|
|
183
182
|
}
|
package/src/commons.js
CHANGED
|
@@ -71,7 +71,11 @@ export const tameConsole = (
|
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
// Browser
|
|
74
|
-
if (
|
|
74
|
+
if (
|
|
75
|
+
errorTrapping !== 'none' &&
|
|
76
|
+
globalThis.window !== undefined &&
|
|
77
|
+
globalThis.window.addEventListener !== undefined
|
|
78
|
+
) {
|
|
75
79
|
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
76
80
|
globalThis.window.addEventListener('error', event => {
|
|
77
81
|
// eslint-disable-next-line @endo/no-polymorphic-call
|
package/src/lockdown-shim.js
CHANGED
|
@@ -15,6 +15,8 @@
|
|
|
15
15
|
// @ts-check
|
|
16
16
|
|
|
17
17
|
import {
|
|
18
|
+
FERAL_FUNCTION,
|
|
19
|
+
FERAL_EVAL,
|
|
18
20
|
TypeError,
|
|
19
21
|
arrayFilter,
|
|
20
22
|
arrayMap,
|
|
@@ -87,6 +89,37 @@ const harden = makeHardener();
|
|
|
87
89
|
// only ever need to be called once and that simplifying lockdown will improve
|
|
88
90
|
// the quality of audits.
|
|
89
91
|
|
|
92
|
+
const assertDirectEvalAvailable = () => {
|
|
93
|
+
let allowed = false;
|
|
94
|
+
try {
|
|
95
|
+
allowed = FERAL_FUNCTION(
|
|
96
|
+
'eval',
|
|
97
|
+
'SES_changed',
|
|
98
|
+
`\
|
|
99
|
+
eval("SES_changed = true");
|
|
100
|
+
return SES_changed;
|
|
101
|
+
`,
|
|
102
|
+
)(FERAL_EVAL, false);
|
|
103
|
+
// If we get here and SES_changed stayed false, that means the eval was sloppy
|
|
104
|
+
// and indirect, which generally creates a new global.
|
|
105
|
+
// We are going to throw an exception for failing to initialize SES, but
|
|
106
|
+
// good neighbors clean up.
|
|
107
|
+
if (!allowed) {
|
|
108
|
+
delete globalThis.SES_changed;
|
|
109
|
+
}
|
|
110
|
+
} catch (_error) {
|
|
111
|
+
// We reach here if eval is outright forbidden by a Content Security Policy.
|
|
112
|
+
// We allow this for SES usage that delegates the responsibility to isolate
|
|
113
|
+
// guest code to production code generation.
|
|
114
|
+
allowed = true;
|
|
115
|
+
}
|
|
116
|
+
if (!allowed) {
|
|
117
|
+
throw new TypeError(
|
|
118
|
+
`SES cannot initialize unless 'eval' is the original intrinsic 'eval', suitable for direct-eval (dynamically scoped eval) (SES_DIRECT_EVAL)`,
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
|
|
90
123
|
/**
|
|
91
124
|
* @param {LockdownOptions} [options]
|
|
92
125
|
* @returns {() => void} repairIntrinsics
|
|
@@ -174,6 +207,8 @@ export const repairIntrinsics = (options = {}) => {
|
|
|
174
207
|
// trace retained:
|
|
175
208
|
priorLockdown.stack;
|
|
176
209
|
|
|
210
|
+
assertDirectEvalAvailable();
|
|
211
|
+
|
|
177
212
|
/**
|
|
178
213
|
* Because of packagers and bundlers, etc, multiple invocations of lockdown
|
|
179
214
|
* might happen in separate instantiations of the source of this module.
|
|
@@ -194,11 +229,14 @@ export const repairIntrinsics = (options = {}) => {
|
|
|
194
229
|
const seemsToBeLockedDown = () => {
|
|
195
230
|
return (
|
|
196
231
|
globalThis.Function.prototype.constructor !== globalThis.Function &&
|
|
232
|
+
// @ts-ignore harden is absent on globalThis type def.
|
|
197
233
|
typeof globalThis.harden === 'function' &&
|
|
234
|
+
// @ts-ignore lockdown is absent on globalThis type def.
|
|
198
235
|
typeof globalThis.lockdown === 'function' &&
|
|
199
236
|
globalThis.Date.prototype.constructor !== globalThis.Date &&
|
|
200
237
|
typeof globalThis.Date.now === 'function' &&
|
|
201
|
-
// @ts-ignore
|
|
238
|
+
// @ts-ignore does not recognize that Date constructor is a special
|
|
239
|
+
// Function.
|
|
202
240
|
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
203
241
|
is(globalThis.Date.prototype.constructor.now(), NaN)
|
|
204
242
|
);
|
|
@@ -254,12 +292,14 @@ export const repairIntrinsics = (options = {}) => {
|
|
|
254
292
|
);
|
|
255
293
|
globalThis.console = /** @type {Console} */ (consoleRecord.console);
|
|
256
294
|
|
|
295
|
+
// @ts-ignore assert is absent on globalThis type def.
|
|
257
296
|
if (errorTaming === 'unsafe' && globalThis.assert === assert) {
|
|
258
297
|
// If errorTaming is 'unsafe' we replace the global assert with
|
|
259
298
|
// one whose `details` template literal tag does not redact
|
|
260
299
|
// unmarked substitution values. IOW, it blabs information that
|
|
261
300
|
// was supposed to be secret from callers, as an aid to debugging
|
|
262
301
|
// at a further cost in safety.
|
|
302
|
+
// @ts-ignore assert is absent on globalThis type def.
|
|
263
303
|
globalThis.assert = makeAssert(undefined, true);
|
|
264
304
|
}
|
|
265
305
|
|
|
@@ -324,6 +364,7 @@ export const repairIntrinsics = (options = {}) => {
|
|
|
324
364
|
// that is portable between JS and SES), the existence of harden in global
|
|
325
365
|
// scope signals whether such code should attempt to use harden in the
|
|
326
366
|
// defense of its own API.
|
|
367
|
+
// @ts-ignore harden not yet recognized on globalThis.
|
|
327
368
|
globalThis.harden = harden;
|
|
328
369
|
|
|
329
370
|
// Returning `true` indicates that this is a JS to SES transition.
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
Number,
|
|
2
3
|
String,
|
|
3
4
|
TypeError,
|
|
4
5
|
defineProperty,
|
|
@@ -33,9 +34,14 @@ const tamedMethods = {
|
|
|
33
34
|
assert(s === that, d`expected ${q(s)} and ${q(that)} to compare`);
|
|
34
35
|
return 0;
|
|
35
36
|
},
|
|
37
|
+
|
|
38
|
+
toString() {
|
|
39
|
+
return `${this}`;
|
|
40
|
+
},
|
|
36
41
|
};
|
|
37
42
|
|
|
38
43
|
const nonLocaleCompare = tamedMethods.localeCompare;
|
|
44
|
+
const numberToString = tamedMethods.toString;
|
|
39
45
|
|
|
40
46
|
export default function tameLocaleMethods(intrinsics, localeTaming = 'safe') {
|
|
41
47
|
if (localeTaming !== 'safe' && localeTaming !== 'unsafe') {
|
|
@@ -70,4 +76,10 @@ export default function tameLocaleMethods(intrinsics, localeTaming = 'safe') {
|
|
|
70
76
|
}
|
|
71
77
|
}
|
|
72
78
|
}
|
|
79
|
+
|
|
80
|
+
// Numbers are special because toString accepts a radix instead of ignoring
|
|
81
|
+
// all of the arguments that we would otherwise forward.
|
|
82
|
+
defineProperty(Number.prototype, 'toLocaleString', {
|
|
83
|
+
value: numberToString,
|
|
84
|
+
});
|
|
73
85
|
}
|
package/src/whitelist.js
CHANGED
|
@@ -288,6 +288,9 @@ function NativeErrorPrototype(constructor) {
|
|
|
288
288
|
name: 'string',
|
|
289
289
|
// Redundantly present only on v8. Safe to remove.
|
|
290
290
|
toString: false,
|
|
291
|
+
// Superfluously present in some versions of V8.
|
|
292
|
+
// https://github.com/tc39/notes/blob/master/meetings/2021-10/oct-26.md#:~:text=However%2C%20Chrome%2093,and%20node%2016.11.
|
|
293
|
+
cause: false,
|
|
291
294
|
};
|
|
292
295
|
}
|
|
293
296
|
|
|
@@ -552,6 +555,9 @@ export const whitelist = {
|
|
|
552
555
|
at: false,
|
|
553
556
|
// Seen on FF and XS
|
|
554
557
|
stack: false,
|
|
558
|
+
// Superfluously present in some versions of V8.
|
|
559
|
+
// https://github.com/tc39/notes/blob/master/meetings/2021-10/oct-26.md#:~:text=However%2C%20Chrome%2093,and%20node%2016.11.
|
|
560
|
+
cause: false,
|
|
555
561
|
},
|
|
556
562
|
|
|
557
563
|
// NativeError
|