ses 0.18.2 → 0.18.3
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/NEWS.md +10 -0
- package/dist/lockdown.cjs +583 -239
- package/dist/lockdown.mjs +583 -239
- package/dist/lockdown.umd.js +583 -239
- package/dist/lockdown.umd.min.js +1 -1
- package/dist/ses.cjs +583 -239
- package/dist/ses.mjs +583 -239
- package/dist/ses.umd.js +583 -239
- package/dist/ses.umd.min.js +1 -1
- package/package.json +9 -16
- package/src/commons.js +2 -0
- package/src/enablements.js +1 -1
- package/src/error/assert.js +4 -19
- package/src/error/note-log-args.js +280 -0
- package/src/lockdown-shim.js +7 -4
- package/src/strict-scope-terminator.js +2 -3
- package/src/tame-harden.js +23 -0
- package/src/whitelist.js +9 -1
- package/types.d.ts +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ses",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.3",
|
|
4
4
|
"description": "Hardened JavaScript for Fearless Cooperation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"lockdown",
|
|
@@ -60,22 +60,20 @@
|
|
|
60
60
|
"test:platform-compatibility": "node test/package/test.cjs"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
|
-
"@endo/compartment-mapper": "^0.8.
|
|
64
|
-
"@endo/
|
|
65
|
-
"@endo/
|
|
66
|
-
"@endo/test262-runner": "^0.1.30",
|
|
63
|
+
"@endo/compartment-mapper": "^0.8.3",
|
|
64
|
+
"@endo/static-module-record": "^0.7.18",
|
|
65
|
+
"@endo/test262-runner": "^0.1.31",
|
|
67
66
|
"ava": "^5.2.0",
|
|
68
67
|
"babel-eslint": "^10.0.3",
|
|
69
68
|
"c8": "^7.7.3",
|
|
70
69
|
"eslint": "^7.32.0",
|
|
71
70
|
"eslint-config-airbnb-base": "^14.0.0",
|
|
72
|
-
"eslint-config-prettier": "^
|
|
71
|
+
"eslint-config-prettier": "^8.8.0",
|
|
73
72
|
"eslint-plugin-eslint-comments": "^3.1.2",
|
|
74
73
|
"eslint-plugin-import": "^2.27.5",
|
|
75
|
-
"
|
|
76
|
-
"prettier": "^2.8.0",
|
|
74
|
+
"prettier": "^2.8.5",
|
|
77
75
|
"sinon": "8.0.4",
|
|
78
|
-
"terser": "^
|
|
76
|
+
"terser": "^5.16.6",
|
|
79
77
|
"tsd": "^0.24.1",
|
|
80
78
|
"typescript": "~4.9.5"
|
|
81
79
|
},
|
|
@@ -95,7 +93,7 @@
|
|
|
95
93
|
},
|
|
96
94
|
"eslintConfig": {
|
|
97
95
|
"extends": [
|
|
98
|
-
"
|
|
96
|
+
"plugin:@endo/internal"
|
|
99
97
|
],
|
|
100
98
|
"rules": {
|
|
101
99
|
"no-restricted-globals": [
|
|
@@ -171,16 +169,11 @@
|
|
|
171
169
|
}
|
|
172
170
|
]
|
|
173
171
|
},
|
|
174
|
-
"prettier": {
|
|
175
|
-
"arrowParens": "avoid",
|
|
176
|
-
"trailingComma": "all",
|
|
177
|
-
"singleQuote": true
|
|
178
|
-
},
|
|
179
172
|
"ava": {
|
|
180
173
|
"files": [
|
|
181
174
|
"test/**/test-*.js"
|
|
182
175
|
],
|
|
183
176
|
"timeout": "2m"
|
|
184
177
|
},
|
|
185
|
-
"gitHead": "
|
|
178
|
+
"gitHead": "8141f58debaec420cbc2a7cb698e888566d430ba"
|
|
186
179
|
}
|
package/src/commons.js
CHANGED
package/src/enablements.js
CHANGED
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
* <ul>
|
|
42
42
|
* <li>true, in which case this property is simply repaired. The
|
|
43
43
|
* value associated with that property is not traversed. For
|
|
44
|
-
*
|
|
44
|
+
* example, {@code "Function.prototype.name"} leads to true,
|
|
45
45
|
* meaning that the {@code "name"} property of {@code
|
|
46
46
|
* "Function.prototype"} should be repaired (which is needed
|
|
47
47
|
* when inheriting from @code{Function} and setting the subclass's
|
package/src/error/assert.js
CHANGED
|
@@ -36,6 +36,7 @@ import {
|
|
|
36
36
|
import { an, bestEffortStringify } from './stringify-utils.js';
|
|
37
37
|
import './types.js';
|
|
38
38
|
import './internal-types.js';
|
|
39
|
+
import { makeNoteLogArgsArrayKit } from './note-log-args.js';
|
|
39
40
|
|
|
40
41
|
// For our internal debugging purposes, uncomment
|
|
41
42
|
// const internalDebugConsole = console;
|
|
@@ -251,17 +252,7 @@ freeze(makeError);
|
|
|
251
252
|
|
|
252
253
|
// /////////////////////////////////////////////////////////////////////////////
|
|
253
254
|
|
|
254
|
-
|
|
255
|
-
* @type {WeakMap<Error, LogArgs[]>}
|
|
256
|
-
*
|
|
257
|
-
* Maps from an error to an array of log args, where each log args is
|
|
258
|
-
* remembered as an annotation on that error. This can be used, for example,
|
|
259
|
-
* to keep track of additional causes of the error. The elements of any
|
|
260
|
-
* log args may include errors which are associated with further annotations.
|
|
261
|
-
* An augmented console, like the causal console of `console.js`, could
|
|
262
|
-
* then retrieve the graph of such annotations.
|
|
263
|
-
*/
|
|
264
|
-
const hiddenNoteLogArgsArrays = new WeakMap();
|
|
255
|
+
const { addLogArgs, takeLogArgsArray } = makeNoteLogArgsArrayKit();
|
|
265
256
|
|
|
266
257
|
/**
|
|
267
258
|
* @type {WeakMap<Error, NoteCallback[]>}
|
|
@@ -295,12 +286,7 @@ const note = (error, detailsNote) => {
|
|
|
295
286
|
callback(error, logArgs);
|
|
296
287
|
}
|
|
297
288
|
} else {
|
|
298
|
-
|
|
299
|
-
if (logArgsArray !== undefined) {
|
|
300
|
-
arrayPush(logArgsArray, logArgs);
|
|
301
|
-
} else {
|
|
302
|
-
weakmapSet(hiddenNoteLogArgsArrays, error, [logArgs]);
|
|
303
|
-
}
|
|
289
|
+
addLogArgs(error, logArgs);
|
|
304
290
|
}
|
|
305
291
|
};
|
|
306
292
|
freeze(note);
|
|
@@ -339,8 +325,7 @@ const loggedErrorHandler = {
|
|
|
339
325
|
return result;
|
|
340
326
|
},
|
|
341
327
|
takeNoteLogArgsArray: (error, callback) => {
|
|
342
|
-
const result =
|
|
343
|
-
weakmapDelete(hiddenNoteLogArgsArrays, error);
|
|
328
|
+
const result = takeLogArgsArray(error);
|
|
344
329
|
if (callback !== undefined) {
|
|
345
330
|
const callbacks = weakmapGet(hiddenNoteCallbackArrays, error);
|
|
346
331
|
if (callbacks) {
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
/* eslint-disable @endo/no-polymorphic-call */
|
|
3
|
+
/* eslint-disable no-restricted-globals */
|
|
4
|
+
|
|
5
|
+
import './internal-types.js';
|
|
6
|
+
|
|
7
|
+
const { freeze } = Object;
|
|
8
|
+
const { isSafeInteger } = Number;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @template Data
|
|
12
|
+
* @typedef {object} DoublyLinkedCell
|
|
13
|
+
* A cell of a doubly-linked ring, i.e., a doubly-linked circular list.
|
|
14
|
+
* DoublyLinkedCells are not frozen, and so should be closely encapsulated by
|
|
15
|
+
* any abstraction that uses them.
|
|
16
|
+
* @property {DoublyLinkedCell<Data>} next
|
|
17
|
+
* @property {DoublyLinkedCell<Data>} prev
|
|
18
|
+
* @property {Data} data
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Makes a new self-linked cell. There are two reasons to do so:
|
|
23
|
+
* * To make the head sigil of a new initially-empty doubly-linked ring.
|
|
24
|
+
* * To make a non-sigil cell to be `spliceAfter`ed.
|
|
25
|
+
*
|
|
26
|
+
* @template Data
|
|
27
|
+
* @param {Data} data
|
|
28
|
+
* @returns {DoublyLinkedCell<Data>}
|
|
29
|
+
*/
|
|
30
|
+
const makeSelfCell = data => {
|
|
31
|
+
/** @type {Partial<DoublyLinkedCell<Data>>} */
|
|
32
|
+
const incompleteCell = {
|
|
33
|
+
next: undefined,
|
|
34
|
+
prev: undefined,
|
|
35
|
+
data,
|
|
36
|
+
};
|
|
37
|
+
const selfCell = /** @type {DoublyLinkedCell<Data>} */ (incompleteCell);
|
|
38
|
+
selfCell.next = selfCell;
|
|
39
|
+
selfCell.prev = selfCell;
|
|
40
|
+
// Not frozen!
|
|
41
|
+
return selfCell;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Splices a self-linked non-sigil cell into a ring after `prev`.
|
|
46
|
+
* `prev` could be the head sigil, or it could be some other non-sigil
|
|
47
|
+
* cell within a ring.
|
|
48
|
+
*
|
|
49
|
+
* @template Data
|
|
50
|
+
* @param {DoublyLinkedCell<Data>} prev
|
|
51
|
+
* @param {DoublyLinkedCell<Data>} selfCell
|
|
52
|
+
*/
|
|
53
|
+
const spliceAfter = (prev, selfCell) => {
|
|
54
|
+
if (prev === selfCell) {
|
|
55
|
+
throw TypeError('Cannot splice a cell into itself');
|
|
56
|
+
}
|
|
57
|
+
if (selfCell.next !== selfCell || selfCell.prev !== selfCell) {
|
|
58
|
+
throw TypeError('Expected self-linked cell');
|
|
59
|
+
}
|
|
60
|
+
const cell = selfCell;
|
|
61
|
+
// rename variable cause it isn't self-linked after this point.
|
|
62
|
+
|
|
63
|
+
const next = prev.next;
|
|
64
|
+
cell.prev = prev;
|
|
65
|
+
cell.next = next;
|
|
66
|
+
prev.next = cell;
|
|
67
|
+
next.prev = cell;
|
|
68
|
+
// Not frozen!
|
|
69
|
+
return cell;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @template Data
|
|
74
|
+
* @param {DoublyLinkedCell<Data>} cell
|
|
75
|
+
* No-op if the cell is self-linked.
|
|
76
|
+
*/
|
|
77
|
+
const spliceOut = cell => {
|
|
78
|
+
const { prev, next } = cell;
|
|
79
|
+
prev.next = next;
|
|
80
|
+
next.prev = prev;
|
|
81
|
+
cell.prev = cell;
|
|
82
|
+
cell.next = cell;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* The LRUCacheMap is used within the implementation of `assert` and so
|
|
87
|
+
* at a layer below SES or harden. Thus, we give it a `WeakMap`-like interface
|
|
88
|
+
* rather than a `WeakMapStore`-like interface. To work before `lockdown`,
|
|
89
|
+
* the implementation must use `freeze` manually, but still exhaustively.
|
|
90
|
+
*
|
|
91
|
+
* It implements the WeakMap interface, and holds its keys weakly. Cached
|
|
92
|
+
* values are only held while the key is held by the user and the key/value
|
|
93
|
+
* bookkeeping cell has not been pushed off the end of the cache by `budget`
|
|
94
|
+
* number of more recently referenced cells. If the key is dropped by the user,
|
|
95
|
+
* the value will no longer be held by the cache, but the bookkeeping cell
|
|
96
|
+
* itself will stay in memory.
|
|
97
|
+
*
|
|
98
|
+
* @template {{}} K
|
|
99
|
+
* @template {unknown} V
|
|
100
|
+
* @param {number} keysBudget
|
|
101
|
+
* @returns {WeakMap<K,V>}
|
|
102
|
+
*/
|
|
103
|
+
export const makeLRUCacheMap = keysBudget => {
|
|
104
|
+
if (!isSafeInteger(keysBudget) || keysBudget < 0) {
|
|
105
|
+
throw new TypeError(
|
|
106
|
+
'keysBudget must be a safe non-negative integer number',
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
/** @typedef {DoublyLinkedCell<WeakMap<K, V> | undefined>} LRUCacheCell */
|
|
110
|
+
/** @type {WeakMap<K, LRUCacheCell>} */
|
|
111
|
+
const keyToCell = new WeakMap();
|
|
112
|
+
let size = 0; // `size` must remain <= `keysBudget`
|
|
113
|
+
// As a sigil, `head` uniquely is not in the `keyToCell` map.
|
|
114
|
+
/** @type {LRUCacheCell} */
|
|
115
|
+
const head = makeSelfCell(undefined);
|
|
116
|
+
|
|
117
|
+
const touchCell = key => {
|
|
118
|
+
const cell = keyToCell.get(key);
|
|
119
|
+
if (cell === undefined || cell.data === undefined) {
|
|
120
|
+
// Either the key was GCed, or the cell was condemned.
|
|
121
|
+
return undefined;
|
|
122
|
+
}
|
|
123
|
+
// Becomes most recently used
|
|
124
|
+
spliceOut(cell);
|
|
125
|
+
spliceAfter(head, cell);
|
|
126
|
+
return cell;
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* @param {K} key
|
|
131
|
+
*/
|
|
132
|
+
const has = key => touchCell(key) !== undefined;
|
|
133
|
+
freeze(has);
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* @param {K} key
|
|
137
|
+
*/
|
|
138
|
+
// TODO Change to the following line, once our tools don't choke on `?.`.
|
|
139
|
+
// See https://github.com/endojs/endo/issues/1514
|
|
140
|
+
// const get = key => touchCell(key)?.data?.get(key);
|
|
141
|
+
const get = key => {
|
|
142
|
+
const cell = touchCell(key);
|
|
143
|
+
return cell && cell.data && cell.data.get(key);
|
|
144
|
+
};
|
|
145
|
+
freeze(get);
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* @param {K} key
|
|
149
|
+
* @param {V} value
|
|
150
|
+
*/
|
|
151
|
+
const set = (key, value) => {
|
|
152
|
+
if (keysBudget < 1) {
|
|
153
|
+
// eslint-disable-next-line no-use-before-define
|
|
154
|
+
return lruCacheMap; // Implements WeakMap.set
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
let cell = touchCell(key);
|
|
158
|
+
if (cell === undefined) {
|
|
159
|
+
cell = makeSelfCell(undefined);
|
|
160
|
+
spliceAfter(head, cell); // start most recently used
|
|
161
|
+
}
|
|
162
|
+
if (!cell.data) {
|
|
163
|
+
// Either a fresh cell or a reused condemned cell.
|
|
164
|
+
size += 1;
|
|
165
|
+
// Add its data.
|
|
166
|
+
cell.data = new WeakMap();
|
|
167
|
+
// Advertise the cell for this key.
|
|
168
|
+
keyToCell.set(key, cell);
|
|
169
|
+
while (size > keysBudget) {
|
|
170
|
+
const condemned = head.prev;
|
|
171
|
+
spliceOut(condemned); // Drop least recently used
|
|
172
|
+
condemned.data = undefined;
|
|
173
|
+
size -= 1;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// Update the data.
|
|
178
|
+
cell.data.set(key, value);
|
|
179
|
+
|
|
180
|
+
// eslint-disable-next-line no-use-before-define
|
|
181
|
+
return lruCacheMap; // Implements WeakMap.set
|
|
182
|
+
};
|
|
183
|
+
freeze(set);
|
|
184
|
+
|
|
185
|
+
// "delete" is a keyword.
|
|
186
|
+
/**
|
|
187
|
+
* @param {K} key
|
|
188
|
+
*/
|
|
189
|
+
const deleteIt = key => {
|
|
190
|
+
const cell = keyToCell.get(key);
|
|
191
|
+
if (cell === undefined) {
|
|
192
|
+
return false;
|
|
193
|
+
}
|
|
194
|
+
spliceOut(cell);
|
|
195
|
+
keyToCell.delete(key);
|
|
196
|
+
if (cell.data === undefined) {
|
|
197
|
+
// Already condemned.
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
cell.data = undefined;
|
|
202
|
+
size -= 1;
|
|
203
|
+
return true;
|
|
204
|
+
};
|
|
205
|
+
freeze(deleteIt);
|
|
206
|
+
|
|
207
|
+
const lruCacheMap = freeze({
|
|
208
|
+
has,
|
|
209
|
+
get,
|
|
210
|
+
set,
|
|
211
|
+
delete: deleteIt,
|
|
212
|
+
[Symbol.toStringTag]: 'LRUCacheMap',
|
|
213
|
+
});
|
|
214
|
+
return lruCacheMap;
|
|
215
|
+
};
|
|
216
|
+
freeze(makeLRUCacheMap);
|
|
217
|
+
|
|
218
|
+
const defaultLoggedErrorsBudget = 1000;
|
|
219
|
+
const defaultArgsPerErrorBudget = 100;
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* @param {number} [errorsBudget]
|
|
223
|
+
* @param {number} [argsPerErrorBudget]
|
|
224
|
+
*/
|
|
225
|
+
export const makeNoteLogArgsArrayKit = (
|
|
226
|
+
errorsBudget = defaultLoggedErrorsBudget,
|
|
227
|
+
argsPerErrorBudget = defaultArgsPerErrorBudget,
|
|
228
|
+
) => {
|
|
229
|
+
if (!isSafeInteger(argsPerErrorBudget) || argsPerErrorBudget < 1) {
|
|
230
|
+
throw new TypeError(
|
|
231
|
+
'argsPerErrorBudget must be a safe positive integer number',
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* @type {WeakMap<Error, LogArgs[]>}
|
|
237
|
+
*
|
|
238
|
+
* Maps from an error to an array of log args, where each log args is
|
|
239
|
+
* remembered as an annotation on that error. This can be used, for example,
|
|
240
|
+
* to keep track of additional causes of the error. The elements of any
|
|
241
|
+
* log args may include errors which are associated with further annotations.
|
|
242
|
+
* An augmented console, like the causal console of `console.js`, could
|
|
243
|
+
* then retrieve the graph of such annotations.
|
|
244
|
+
*/
|
|
245
|
+
const noteLogArgsArrayMap = makeLRUCacheMap(errorsBudget);
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* @param {Error} error
|
|
249
|
+
* @param {LogArgs} logArgs
|
|
250
|
+
*/
|
|
251
|
+
const addLogArgs = (error, logArgs) => {
|
|
252
|
+
const logArgsArray = noteLogArgsArrayMap.get(error);
|
|
253
|
+
if (logArgsArray !== undefined) {
|
|
254
|
+
if (logArgsArray.length >= argsPerErrorBudget) {
|
|
255
|
+
logArgsArray.shift();
|
|
256
|
+
}
|
|
257
|
+
logArgsArray.push(logArgs);
|
|
258
|
+
} else {
|
|
259
|
+
noteLogArgsArrayMap.set(error, [logArgs]);
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
freeze(addLogArgs);
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* @param {Error} error
|
|
266
|
+
* @returns {LogArgs[] | undefined}
|
|
267
|
+
*/
|
|
268
|
+
const takeLogArgsArray = error => {
|
|
269
|
+
const result = noteLogArgsArrayMap.get(error);
|
|
270
|
+
noteLogArgsArrayMap.delete(error);
|
|
271
|
+
return result;
|
|
272
|
+
};
|
|
273
|
+
freeze(takeLogArgsArray);
|
|
274
|
+
|
|
275
|
+
return freeze({
|
|
276
|
+
addLogArgs,
|
|
277
|
+
takeLogArgsArray,
|
|
278
|
+
});
|
|
279
|
+
};
|
|
280
|
+
freeze(makeNoteLogArgsArrayKit);
|
package/src/lockdown-shim.js
CHANGED
|
@@ -52,6 +52,7 @@ import { assert, makeAssert } from './error/assert.js';
|
|
|
52
52
|
import { makeEnvironmentCaptor } from './environment-options.js';
|
|
53
53
|
import { getAnonymousIntrinsics } from './get-anonymous-intrinsics.js';
|
|
54
54
|
import { makeCompartmentConstructor } from './compartment-shim.js';
|
|
55
|
+
import { tameHarden } from './tame-harden.js';
|
|
55
56
|
|
|
56
57
|
/** @typedef {import('../types.js').LockdownOptions} LockdownOptions */
|
|
57
58
|
|
|
@@ -67,7 +68,7 @@ let priorLockdown;
|
|
|
67
68
|
* @param {T} ref
|
|
68
69
|
* @returns {T}
|
|
69
70
|
*/
|
|
70
|
-
const
|
|
71
|
+
const safeHarden = makeHardener();
|
|
71
72
|
|
|
72
73
|
/**
|
|
73
74
|
* @callback Transform
|
|
@@ -174,6 +175,7 @@ export const repairIntrinsics = (options = {}) => {
|
|
|
174
175
|
/** @param {string} debugName */
|
|
175
176
|
debugName => debugName !== '',
|
|
176
177
|
),
|
|
178
|
+
__hardenTaming__ = getenv('LOCKDOWN_HARDEN_TAMING', 'safe'),
|
|
177
179
|
dateTaming = 'safe', // deprecated
|
|
178
180
|
mathTaming = 'safe', // deprecated
|
|
179
181
|
...extraOptions
|
|
@@ -264,7 +266,8 @@ export const repairIntrinsics = (options = {}) => {
|
|
|
264
266
|
const { addIntrinsics, completePrototypes, finalIntrinsics } =
|
|
265
267
|
makeIntrinsicsCollector();
|
|
266
268
|
|
|
267
|
-
|
|
269
|
+
const tamedHarden = tameHarden(safeHarden, __hardenTaming__);
|
|
270
|
+
addIntrinsics({ harden: tamedHarden });
|
|
268
271
|
|
|
269
272
|
addIntrinsics(tameFunctionConstructors());
|
|
270
273
|
|
|
@@ -377,7 +380,7 @@ export const repairIntrinsics = (options = {}) => {
|
|
|
377
380
|
|
|
378
381
|
// Finally register and optionally freeze all the intrinsics. This
|
|
379
382
|
// must be the operation that modifies the intrinsics.
|
|
380
|
-
|
|
383
|
+
tamedHarden(intrinsics);
|
|
381
384
|
|
|
382
385
|
// Reveal harden after lockdown.
|
|
383
386
|
// Harden is dangerous before lockdown because hardening just
|
|
@@ -387,7 +390,7 @@ export const repairIntrinsics = (options = {}) => {
|
|
|
387
390
|
// scope signals whether such code should attempt to use harden in the
|
|
388
391
|
// defense of its own API.
|
|
389
392
|
// @ts-ignore harden not yet recognized on globalThis.
|
|
390
|
-
globalThis.harden =
|
|
393
|
+
globalThis.harden = tamedHarden;
|
|
391
394
|
|
|
392
395
|
// Returning `true` indicates that this is a JS to SES transition.
|
|
393
396
|
return true;
|
|
@@ -57,9 +57,8 @@ const scopeProxyHandlerProperties = {
|
|
|
57
57
|
return null;
|
|
58
58
|
},
|
|
59
59
|
|
|
60
|
-
//
|
|
61
|
-
// TODO
|
|
62
|
-
// TODO report as bug to v8 or Chrome, and record issue link here.
|
|
60
|
+
// See https://github.com/endojs/endo/issues/1510
|
|
61
|
+
// TODO: report as bug to v8 or Chrome, and record issue link here.
|
|
63
62
|
getOwnPropertyDescriptor(_target, prop) {
|
|
64
63
|
// Coerce with `String` in case prop is a symbol.
|
|
65
64
|
const quotedProp = q(String(prop));
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/* eslint-disable no-restricted-globals */
|
|
2
|
+
import { TypeError, freeze } from './commons.js';
|
|
3
|
+
|
|
4
|
+
export const tameHarden = (safeHarden, hardenTaming) => {
|
|
5
|
+
if (hardenTaming !== 'safe' && hardenTaming !== 'unsafe') {
|
|
6
|
+
throw new TypeError(`unrecognized fakeHardenOption ${hardenTaming}`);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
if (hardenTaming === 'safe') {
|
|
10
|
+
return safeHarden;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// In on the joke
|
|
14
|
+
Object.isExtensible = () => false;
|
|
15
|
+
Object.isFrozen = () => true;
|
|
16
|
+
Object.isSealed = () => true;
|
|
17
|
+
Reflect.isExtensible = () => false;
|
|
18
|
+
|
|
19
|
+
const fakeHarden = arg => arg;
|
|
20
|
+
fakeHarden.isFake = true;
|
|
21
|
+
return freeze(fakeHarden);
|
|
22
|
+
};
|
|
23
|
+
freeze(tameHarden);
|
package/src/whitelist.js
CHANGED
|
@@ -1221,6 +1221,10 @@ export const whitelist = {
|
|
|
1221
1221
|
'[[Proto]]': '%FunctionPrototype%',
|
|
1222
1222
|
constructor: '%InertAsyncGeneratorFunction%',
|
|
1223
1223
|
prototype: '%AsyncGeneratorPrototype%',
|
|
1224
|
+
// length prop added here for React Native jsc-android
|
|
1225
|
+
// https://github.com/endojs/endo/issues/660
|
|
1226
|
+
// https://github.com/react-native-community/jsc-android-buildscripts/issues/181
|
|
1227
|
+
length: 'number',
|
|
1224
1228
|
'@@toStringTag': 'string',
|
|
1225
1229
|
},
|
|
1226
1230
|
|
|
@@ -1303,6 +1307,10 @@ export const whitelist = {
|
|
|
1303
1307
|
// Properties of the AsyncFunction Prototype Object
|
|
1304
1308
|
'[[Proto]]': '%FunctionPrototype%',
|
|
1305
1309
|
constructor: '%InertAsyncFunction%',
|
|
1310
|
+
// length prop added here for React Native jsc-android
|
|
1311
|
+
// https://github.com/endojs/endo/issues/660
|
|
1312
|
+
// https://github.com/react-native-community/jsc-android-buildscripts/issues/181
|
|
1313
|
+
length: 'number',
|
|
1306
1314
|
'@@toStringTag': 'string',
|
|
1307
1315
|
},
|
|
1308
1316
|
|
|
@@ -1368,7 +1376,7 @@ export const whitelist = {
|
|
|
1368
1376
|
},
|
|
1369
1377
|
|
|
1370
1378
|
lockdown: fn,
|
|
1371
|
-
harden: fn,
|
|
1379
|
+
harden: { ...fn, isFake: 'boolean' },
|
|
1372
1380
|
|
|
1373
1381
|
'%InitialGetStackString%': fn,
|
|
1374
1382
|
};
|
package/types.d.ts
CHANGED
|
@@ -33,6 +33,7 @@ export interface LockdownOptions {
|
|
|
33
33
|
overrideTaming?: 'moderate' | 'min' | 'severe';
|
|
34
34
|
overrideDebug?: Array<string>;
|
|
35
35
|
domainTaming?: 'safe' | 'unsafe';
|
|
36
|
+
__hardenTaming__?: 'safe' | 'unsafe';
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
export type Lockdown = (options?: LockdownOptions) => void;
|