ses 0.15.0 → 0.15.4
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 +51 -0
- package/NEWS.md +25 -0
- package/README.md +204 -10
- package/SECURITY.md +30 -17
- package/dist/lockdown.cjs +1199 -2149
- package/dist/lockdown.mjs +1199 -2149
- package/dist/lockdown.umd.js +1199 -2149
- package/dist/lockdown.umd.min.js +1 -1
- package/dist/ses.cjs +1199 -2149
- package/dist/ses.mjs +1199 -2149
- package/dist/ses.umd.js +1199 -2149
- package/dist/ses.umd.min.js +1 -1
- package/index.d.ts +3 -2
- package/package.json +9 -10
- package/src/commons.js +1 -0
- package/src/error/tame-console.js +1 -3
- package/src/lockdown-shim.js +35 -0
- package/src/make-hardener.js +2 -2
- package/src/tame-locale-methods.js +12 -0
- package/src/whitelist-intrinsics.js +3 -3
- package/src/whitelist.js +19 -0
package/index.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export interface LockdownOptions {
|
|
|
18
18
|
regExpTaming?: 'safe' | 'unsafe';
|
|
19
19
|
localeTaming?: 'safe' | 'unsafe';
|
|
20
20
|
consoleTaming?: 'safe' | 'unsafe';
|
|
21
|
-
errorTrapping?: 'platform' | 'exit' | 'abort' | 'report';
|
|
21
|
+
errorTrapping?: 'platform' | 'exit' | 'abort' | 'report' | 'none';
|
|
22
22
|
errorTaming?: 'safe' | 'unsafe';
|
|
23
23
|
dateTaming?: 'safe' | 'unsafe'; // deprecated
|
|
24
24
|
mathTaming?: 'safe' | 'unsafe'; // deprecated
|
|
@@ -89,6 +89,7 @@ export type DetailsToken = Record<any, never>
|
|
|
89
89
|
export type Details = string | DetailsToken
|
|
90
90
|
|
|
91
91
|
export interface AssertMakeErrorOptions {
|
|
92
|
+
errorName?: string,
|
|
92
93
|
}
|
|
93
94
|
|
|
94
95
|
type AssertTypeofBigint = (specimen: any, typeName: 'bigint', details?: Details) => asserts specimen is bigint;
|
|
@@ -119,7 +120,7 @@ interface ToStringable {
|
|
|
119
120
|
export interface Assert {
|
|
120
121
|
(value: any, details?: Details, errorConstructor?:ErrorConstructor): asserts value;
|
|
121
122
|
typeof: AssertTypeof,
|
|
122
|
-
error(details?: Details, errorConstructor?:ErrorConstructor): Error;
|
|
123
|
+
error(details?: Details, errorConstructor?:ErrorConstructor, options?:AssertMakeErrorOptions): Error;
|
|
123
124
|
fail(details?: Details, errorConstructor?:ErrorConstructor): never;
|
|
124
125
|
equal(left: any, right: any, details?: Details, errorConstructor?:ErrorConstructor): void;
|
|
125
126
|
string(specimen: any, details?: Details): asserts specimen is string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ses",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.4",
|
|
4
4
|
"description": "Hardened JavaScript for Fearless Cooperation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"lockdown",
|
|
@@ -48,10 +48,10 @@
|
|
|
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
|
-
"lint-fix": "eslint --fix
|
|
54
|
-
"lint:js": "eslint
|
|
53
|
+
"lint-fix": "eslint --fix .",
|
|
54
|
+
"lint:js": "eslint .",
|
|
55
55
|
"lint:types": "tsc --build jsconfig.json",
|
|
56
56
|
"prepublish": "yarn run clean && yarn build",
|
|
57
57
|
"qt": "ava",
|
|
@@ -59,10 +59,10 @@
|
|
|
59
59
|
"test:platform-compatability": "node test/package/test.cjs"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
|
-
"@endo/compartment-mapper": "^0.
|
|
63
|
-
"@endo/eslint-config": "^0.3.
|
|
64
|
-
"@endo/static-module-record": "^0.6.
|
|
65
|
-
"@endo/test262-runner": "^0.1.
|
|
62
|
+
"@endo/compartment-mapper": "^0.6.2",
|
|
63
|
+
"@endo/eslint-config": "^0.3.21",
|
|
64
|
+
"@endo/static-module-record": "^0.6.9",
|
|
65
|
+
"@endo/test262-runner": "^0.1.15",
|
|
66
66
|
"ava": "^3.12.1",
|
|
67
67
|
"babel-eslint": "^10.0.3",
|
|
68
68
|
"c8": "^7.7.3",
|
|
@@ -72,7 +72,6 @@
|
|
|
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",
|
|
@@ -179,5 +178,5 @@
|
|
|
179
178
|
],
|
|
180
179
|
"timeout": "2m"
|
|
181
180
|
},
|
|
182
|
-
"gitHead": "
|
|
181
|
+
"gitHead": "b986f1b0afbec1261fb2c047257751b9d418df7c"
|
|
183
182
|
}
|
package/src/commons.js
CHANGED
|
@@ -77,9 +77,7 @@ export const tameConsole = (
|
|
|
77
77
|
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
78
78
|
event.preventDefault();
|
|
79
79
|
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
80
|
-
|
|
81
|
-
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
82
|
-
causalConsole.error(stackString);
|
|
80
|
+
causalConsole.error(event.error);
|
|
83
81
|
if (errorTrapping === 'exit' || errorTrapping === 'abort') {
|
|
84
82
|
globalThis.window.location.href = `about:blank`;
|
|
85
83
|
}
|
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.
|
package/src/make-hardener.js
CHANGED
|
@@ -85,7 +85,7 @@ export const makeHardener = () => {
|
|
|
85
85
|
// Ignore if this is an exit, or we've already visited it
|
|
86
86
|
return;
|
|
87
87
|
}
|
|
88
|
-
// console.
|
|
88
|
+
// console.warn(`adding ${val} to toFreeze`, val);
|
|
89
89
|
setAdd(toFreeze, val);
|
|
90
90
|
weakmapSet(paths, val, path);
|
|
91
91
|
}
|
|
@@ -150,7 +150,7 @@ export const makeHardener = () => {
|
|
|
150
150
|
|
|
151
151
|
enqueue(root);
|
|
152
152
|
dequeue();
|
|
153
|
-
// console.
|
|
153
|
+
// console.warn("toFreeze set:", toFreeze);
|
|
154
154
|
commit();
|
|
155
155
|
|
|
156
156
|
return root;
|
|
@@ -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
|
}
|
|
@@ -244,11 +244,11 @@ export default function whitelistIntrinsics(
|
|
|
244
244
|
// that we are removing it so we know to look into it, as happens when
|
|
245
245
|
// the language evolves new features to existing intrinsics.
|
|
246
246
|
if (subPermit !== false) {
|
|
247
|
-
// This call to `console.
|
|
248
|
-
//
|
|
247
|
+
// This call to `console.warn` is intentional. It is not a vestige of
|
|
248
|
+
// a debugging attempt. See the comment at top of file for an
|
|
249
249
|
// explanation.
|
|
250
250
|
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
251
|
-
console.
|
|
251
|
+
console.warn(`Removing ${subPath}`);
|
|
252
252
|
}
|
|
253
253
|
try {
|
|
254
254
|
delete obj[prop];
|
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
|
|
|
@@ -425,6 +428,8 @@ export const whitelist = {
|
|
|
425
428
|
seal: fn,
|
|
426
429
|
setPrototypeOf: fn,
|
|
427
430
|
values: fn,
|
|
431
|
+
// See https://github.com/tc39/proposal-accessible-object-hasownproperty
|
|
432
|
+
hasOwn: fn,
|
|
428
433
|
},
|
|
429
434
|
|
|
430
435
|
'%ObjectPrototype%': {
|
|
@@ -550,6 +555,9 @@ export const whitelist = {
|
|
|
550
555
|
at: false,
|
|
551
556
|
// Seen on FF and XS
|
|
552
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,
|
|
553
561
|
},
|
|
554
562
|
|
|
555
563
|
// NativeError
|
|
@@ -922,6 +930,9 @@ export const whitelist = {
|
|
|
922
930
|
// Failed tc39 proposal
|
|
923
931
|
// Seen on FF Nightly 88.0a1
|
|
924
932
|
at: false,
|
|
933
|
+
// See https://github.com/tc39/proposal-array-find-from-last
|
|
934
|
+
findLast: fn,
|
|
935
|
+
findLastIndex: fn,
|
|
925
936
|
},
|
|
926
937
|
|
|
927
938
|
'%ArrayIteratorPrototype%': {
|
|
@@ -978,6 +989,9 @@ export const whitelist = {
|
|
|
978
989
|
// Failed tc39 proposal
|
|
979
990
|
// Seen on FF Nightly 88.0a1
|
|
980
991
|
at: false,
|
|
992
|
+
// See https://github.com/tc39/proposal-array-find-from-last
|
|
993
|
+
findLast: fn,
|
|
994
|
+
findLastIndex: fn,
|
|
981
995
|
},
|
|
982
996
|
|
|
983
997
|
// The TypedArray Constructors
|
|
@@ -1117,6 +1131,11 @@ export const whitelist = {
|
|
|
1117
1131
|
'@@toStringTag': 'string',
|
|
1118
1132
|
// See https://github.com/Moddable-OpenSource/moddable/issues/523
|
|
1119
1133
|
concat: false,
|
|
1134
|
+
// See https://github.com/tc39/proposal-resizablearraybuffer
|
|
1135
|
+
transfer: fn,
|
|
1136
|
+
resize: fn,
|
|
1137
|
+
resizable: getter,
|
|
1138
|
+
maxByteLength: getter,
|
|
1120
1139
|
},
|
|
1121
1140
|
|
|
1122
1141
|
// SharedArrayBuffer Objects
|