ses 0.14.3 → 0.15.2
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 +60 -0
- package/NEWS.md +51 -1
- package/dist/lockdown.cjs +3090 -3792
- package/dist/lockdown.mjs +3090 -3792
- package/dist/lockdown.umd.js +3090 -3792
- package/dist/lockdown.umd.min.js +1 -1
- package/dist/ses.cjs +3090 -3792
- package/dist/ses.mjs +3090 -3792
- package/dist/ses.umd.js +3090 -3792
- package/dist/ses.umd.min.js +1 -1
- package/index.d.ts +1 -1
- package/index.js +3 -11
- package/package.json +8 -8
- package/src/compartment-evaluate.js +58 -28
- package/src/compartment-shim.js +44 -27
- package/src/environment-options.js +125 -0
- package/src/error/stringify-utils.js +24 -1
- package/src/error/tame-console.js +1 -3
- package/src/global-object.js +33 -26
- package/src/lockdown-shim.js +91 -109
- package/src/make-eval-function.js +3 -5
- package/src/make-function-constructor.js +3 -4
- package/src/make-hardener.js +2 -2
- package/src/make-safe-evaluator.js +117 -0
- package/src/scope-handler.js +13 -2
- package/src/whitelist-intrinsics.js +3 -3
- package/src/whitelist.js +13 -0
- package/src/evaluate.js +0 -102
package/src/evaluate.js
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
// Portions adapted from V8 - Copyright 2016 the V8 project authors.
|
|
2
|
-
// https://github.com/v8/v8/blob/master/src/builtins/builtins-function.cc
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
WeakSet,
|
|
6
|
-
apply,
|
|
7
|
-
immutableObject,
|
|
8
|
-
proxyRevocable,
|
|
9
|
-
weaksetAdd,
|
|
10
|
-
} from './commons.js';
|
|
11
|
-
import { getScopeConstants } from './scope-constants.js';
|
|
12
|
-
import { createScopeHandler } from './scope-handler.js';
|
|
13
|
-
import { applyTransforms, mandatoryTransforms } from './transforms.js';
|
|
14
|
-
import { makeEvaluateFactory } from './make-evaluate-factory.js';
|
|
15
|
-
import { assert } from './error/assert.js';
|
|
16
|
-
|
|
17
|
-
const { details: d } = assert;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* performEval()
|
|
21
|
-
* The low-level operation used by all evaluators:
|
|
22
|
-
* eval(), Function(), Evalutator.prototype.evaluate().
|
|
23
|
-
*
|
|
24
|
-
* @param {string} source
|
|
25
|
-
* @param {Object} globalObject
|
|
26
|
-
* @param {Objeect} localObject
|
|
27
|
-
* @param {Object} [options]
|
|
28
|
-
* @param {Array<Transform>} [options.localTransforms]
|
|
29
|
-
* @param {Array<Transform>} [options.globalTransforms]
|
|
30
|
-
* @param {bool} [options.sloppyGlobalsMode]
|
|
31
|
-
* @param {WeakSet} [options.knownScopeProxies]
|
|
32
|
-
*/
|
|
33
|
-
export const performEval = (
|
|
34
|
-
source,
|
|
35
|
-
globalObject,
|
|
36
|
-
localObject = {},
|
|
37
|
-
{
|
|
38
|
-
localTransforms = [],
|
|
39
|
-
globalTransforms = [],
|
|
40
|
-
sloppyGlobalsMode = false,
|
|
41
|
-
knownScopeProxies = new WeakSet(),
|
|
42
|
-
} = {},
|
|
43
|
-
) => {
|
|
44
|
-
// Execute the mandatory transforms last to ensure that any rewritten code
|
|
45
|
-
// meets those mandatory requirements.
|
|
46
|
-
source = applyTransforms(source, [
|
|
47
|
-
...localTransforms,
|
|
48
|
-
...globalTransforms,
|
|
49
|
-
mandatoryTransforms,
|
|
50
|
-
]);
|
|
51
|
-
|
|
52
|
-
const {
|
|
53
|
-
scopeHandler,
|
|
54
|
-
admitOneUnsafeEvalNext,
|
|
55
|
-
resetOneUnsafeEvalNext,
|
|
56
|
-
} = createScopeHandler(globalObject, localObject, {
|
|
57
|
-
sloppyGlobalsMode,
|
|
58
|
-
});
|
|
59
|
-
const { proxy: scopeProxy, revoke: revokeScopeProxy } = proxyRevocable(
|
|
60
|
-
immutableObject,
|
|
61
|
-
scopeHandler,
|
|
62
|
-
);
|
|
63
|
-
|
|
64
|
-
const constants = getScopeConstants(globalObject, localObject);
|
|
65
|
-
const evaluateFactory = makeEvaluateFactory(constants);
|
|
66
|
-
const evaluate = apply(evaluateFactory, scopeProxy, []);
|
|
67
|
-
|
|
68
|
-
admitOneUnsafeEvalNext();
|
|
69
|
-
let err;
|
|
70
|
-
try {
|
|
71
|
-
// Ensure that "this" resolves to the safe global.
|
|
72
|
-
weaksetAdd(knownScopeProxies, scopeProxy);
|
|
73
|
-
return apply(evaluate, globalObject, [source]);
|
|
74
|
-
} catch (e) {
|
|
75
|
-
// stash the child-code error in hopes of debugging the internal failure
|
|
76
|
-
err = e;
|
|
77
|
-
throw e;
|
|
78
|
-
} finally {
|
|
79
|
-
if (resetOneUnsafeEvalNext()) {
|
|
80
|
-
// Barring a defect in the SES shim, the scope proxy should allow the
|
|
81
|
-
// powerful, unsafe `eval` to be used by `evaluate` exactly once, as the
|
|
82
|
-
// very first name that it attempts to access from the lexical scope.
|
|
83
|
-
// A defect in the SES shim could throw an exception after our call to
|
|
84
|
-
// `admitOneUnsafeEvalNext()` and before `evaluate` calls `eval`
|
|
85
|
-
// internally.
|
|
86
|
-
// If we get here, SES is very broken.
|
|
87
|
-
// This condition is one where this vat is now hopelessly confused, and
|
|
88
|
-
// the vat as a whole should be aborted.
|
|
89
|
-
// No further code should run.
|
|
90
|
-
// All immediately reachable state should be abandoned.
|
|
91
|
-
// However, that is not yet possible, so we at least prevent further
|
|
92
|
-
// variable resolution via the scopeHandler, and throw an error with
|
|
93
|
-
// diagnostic info including the thrown error if any from evaluating the
|
|
94
|
-
// source code.
|
|
95
|
-
revokeScopeProxy();
|
|
96
|
-
// TODO A GOOD PLACE TO PANIC(), i.e., kill the vat incarnation.
|
|
97
|
-
// See https://github.com/Agoric/SES-shim/issues/490
|
|
98
|
-
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
99
|
-
assert.fail(d`handler did not reset allowNextEvalToBeUnsafe ${err}`);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
};
|