ses 0.14.3 → 0.14.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 +16 -0
- package/NEWS.md +15 -1
- package/dist/lockdown.cjs +278 -191
- package/dist/lockdown.mjs +278 -191
- package/dist/lockdown.umd.js +278 -191
- package/dist/lockdown.umd.min.js +1 -1
- package/dist/ses.cjs +278 -191
- package/dist/ses.mjs +278 -191
- package/dist/ses.umd.js +278 -191
- package/dist/ses.umd.min.js +1 -1
- package/package.json +6 -6
- package/src/compartment-evaluate.js +58 -28
- package/src/compartment-shim.js +44 -27
- package/src/global-object.js +33 -26
- package/src/lockdown-shim.js +15 -9
- package/src/make-eval-function.js +3 -5
- package/src/make-function-constructor.js +3 -4
- package/src/make-safe-evaluator.js +117 -0
- package/src/scope-handler.js +13 -2
- package/src/evaluate.js +0 -102
package/dist/lockdown.mjs
CHANGED
|
@@ -182,11 +182,12 @@ applyTransforms: cell("applyTransforms"),
|
|
|
182
182
|
|
|
183
183
|
|
|
184
184
|
},{
|
|
185
|
-
|
|
185
|
+
makeSafeEvaluator: cell("makeSafeEvaluator"),
|
|
186
186
|
|
|
187
187
|
|
|
188
188
|
},{
|
|
189
|
-
|
|
189
|
+
provideCompartmentEvaluator: cell("provideCompartmentEvaluator"),
|
|
190
|
+
compartmentEvaluate: cell("compartmentEvaluate"),
|
|
190
191
|
|
|
191
192
|
|
|
192
193
|
},{
|
|
@@ -210,7 +211,8 @@ whitelist: cell("whitelist"),
|
|
|
210
211
|
|
|
211
212
|
|
|
212
213
|
},{
|
|
213
|
-
|
|
214
|
+
setGlobalObjectConstantProperties: cell("setGlobalObjectConstantProperties"),
|
|
215
|
+
setGlobalObjectMutableProperties: cell("setGlobalObjectMutableProperties"),
|
|
214
216
|
|
|
215
217
|
|
|
216
218
|
},{
|
|
@@ -758,7 +760,7 @@ makeLockdown: cell("makeLockdown"),
|
|
|
758
760
|
|
|
759
761
|
},
|
|
760
762
|
onceVar: {
|
|
761
|
-
|
|
763
|
+
makeSafeEvaluator: cells[10].makeSafeEvaluator.set,
|
|
762
764
|
|
|
763
765
|
},
|
|
764
766
|
});
|
|
@@ -774,7 +776,7 @@ makeLockdown: cell("makeLockdown"),
|
|
|
774
776
|
cell.observe(observer);
|
|
775
777
|
}
|
|
776
778
|
}
|
|
777
|
-
for (const [name, observers] of map.get("./
|
|
779
|
+
for (const [name, observers] of map.get("./make-safe-evaluator.js")) {
|
|
778
780
|
const cell = cells[10][name];
|
|
779
781
|
if (cell === undefined) {
|
|
780
782
|
throw new ReferenceError(`Cannot import name ${name}`);
|
|
@@ -798,23 +800,15 @@ makeLockdown: cell("makeLockdown"),
|
|
|
798
800
|
|
|
799
801
|
},
|
|
800
802
|
onceVar: {
|
|
801
|
-
|
|
803
|
+
provideCompartmentEvaluator: cells[11].provideCompartmentEvaluator.set,
|
|
804
|
+
compartmentEvaluate: cells[11].compartmentEvaluate.set,
|
|
802
805
|
|
|
803
806
|
},
|
|
804
807
|
});
|
|
805
808
|
functors[12]({
|
|
806
809
|
imports(entries) {
|
|
807
810
|
const map = new Map(entries);
|
|
808
|
-
|
|
809
|
-
const cell = cells[10][name];
|
|
810
|
-
if (cell === undefined) {
|
|
811
|
-
throw new ReferenceError(`Cannot import name ${name}`);
|
|
812
|
-
}
|
|
813
|
-
for (const observer of observers) {
|
|
814
|
-
cell.observe(observer);
|
|
815
|
-
}
|
|
816
|
-
}
|
|
817
|
-
|
|
811
|
+
|
|
818
812
|
},
|
|
819
813
|
liveVar: {
|
|
820
814
|
|
|
@@ -844,15 +838,6 @@ makeLockdown: cell("makeLockdown"),
|
|
|
844
838
|
for (const observer of observers) {
|
|
845
839
|
cell.observe(observer);
|
|
846
840
|
}
|
|
847
|
-
}
|
|
848
|
-
for (const [name, observers] of map.get("./evaluate.js")) {
|
|
849
|
-
const cell = cells[10][name];
|
|
850
|
-
if (cell === undefined) {
|
|
851
|
-
throw new ReferenceError(`Cannot import name ${name}`);
|
|
852
|
-
}
|
|
853
|
-
for (const observer of observers) {
|
|
854
|
-
cell.observe(observer);
|
|
855
|
-
}
|
|
856
841
|
}
|
|
857
842
|
|
|
858
843
|
},
|
|
@@ -930,7 +915,8 @@ makeLockdown: cell("makeLockdown"),
|
|
|
930
915
|
|
|
931
916
|
},
|
|
932
917
|
onceVar: {
|
|
933
|
-
|
|
918
|
+
setGlobalObjectConstantProperties: cells[15].setGlobalObjectConstantProperties.set,
|
|
919
|
+
setGlobalObjectMutableProperties: cells[15].setGlobalObjectMutableProperties.set,
|
|
934
920
|
|
|
935
921
|
},
|
|
936
922
|
});
|
|
@@ -1136,6 +1122,15 @@ makeLockdown: cell("makeLockdown"),
|
|
|
1136
1122
|
for (const observer of observers) {
|
|
1137
1123
|
cell.observe(observer);
|
|
1138
1124
|
}
|
|
1125
|
+
}
|
|
1126
|
+
for (const [name, observers] of map.get("./make-safe-evaluator.js")) {
|
|
1127
|
+
const cell = cells[10][name];
|
|
1128
|
+
if (cell === undefined) {
|
|
1129
|
+
throw new ReferenceError(`Cannot import name ${name}`);
|
|
1130
|
+
}
|
|
1131
|
+
for (const observer of observers) {
|
|
1132
|
+
cell.observe(observer);
|
|
1133
|
+
}
|
|
1139
1134
|
}
|
|
1140
1135
|
for (const [name, observers] of map.get("./module-link.js")) {
|
|
1141
1136
|
const cell = cells[19][name];
|
|
@@ -1759,6 +1754,15 @@ makeLockdown: cell("makeLockdown"),
|
|
|
1759
1754
|
for (const observer of observers) {
|
|
1760
1755
|
cell.observe(observer);
|
|
1761
1756
|
}
|
|
1757
|
+
}
|
|
1758
|
+
for (const [name, observers] of map.get("./make-safe-evaluator.js")) {
|
|
1759
|
+
const cell = cells[10][name];
|
|
1760
|
+
if (cell === undefined) {
|
|
1761
|
+
throw new ReferenceError(`Cannot import name ${name}`);
|
|
1762
|
+
}
|
|
1763
|
+
for (const observer of observers) {
|
|
1764
|
+
cell.observe(observer);
|
|
1765
|
+
}
|
|
1762
1766
|
}
|
|
1763
1767
|
for (const [name, observers] of map.get("./tame-date-constructor.js")) {
|
|
1764
1768
|
const cell = cells[30][name];
|
|
@@ -3534,7 +3538,7 @@ freeze({
|
|
|
3534
3538
|
/*
|
|
3535
3539
|
* createScopeHandler()
|
|
3536
3540
|
* ScopeHandler manages a Proxy which serves as the global scope for the
|
|
3537
|
-
*
|
|
3541
|
+
* safeEvaluate operation (the Proxy is the argument of a 'with' binding).
|
|
3538
3542
|
* As described in createSafeEvaluator(), it has several functions:
|
|
3539
3543
|
* - allow the very first (and only the very first) use of 'eval' to map to
|
|
3540
3544
|
* the real (unsafe) eval function, so it acts as a 'direct eval' and can
|
|
@@ -3647,9 +3651,20 @@ localObject = {},
|
|
|
3647
3651
|
// at the expense of 'typeof' being wrong for those properties. For
|
|
3648
3652
|
// example, in the browser, evaluating 'document = 3', will add
|
|
3649
3653
|
// a property to globalObject instead of throwing a ReferenceError.
|
|
3654
|
+
|
|
3655
|
+
// !!!!! WARNING: DANGER ZONE !!!!!!
|
|
3656
|
+
// The order of the conditions in the `||` expression below is of the
|
|
3657
|
+
// utmost importance. Under no circumstances should `eval` be checked
|
|
3658
|
+
// after `globalObject`. The prototype of the global object is under
|
|
3659
|
+
// full control of user code and may be replaced by a proxy with a
|
|
3660
|
+
// `has` trap. If we allow that trap to trigger while the
|
|
3661
|
+
// `allowNextEvalToBeUnsafe` flag is down, it could allow user code
|
|
3662
|
+
// to get a hold of `FERAL_EVAL`, resulting in a complete escape of
|
|
3663
|
+
// the compartment.
|
|
3664
|
+
// !!!!! WARNING: DANGER ZONE !!!!!!
|
|
3650
3665
|
return (
|
|
3651
3666
|
sloppyGlobalsMode ||
|
|
3652
|
-
prop === 'eval' ||
|
|
3667
|
+
allowNextEvalToBeUnsafe && prop === 'eval' ||
|
|
3653
3668
|
prop in localObject ||
|
|
3654
3669
|
prop in globalObject ||
|
|
3655
3670
|
prop in globalThis);
|
|
@@ -4020,39 +4035,27 @@ const applyTransforms = (source, transforms) => {
|
|
|
4020
4035
|
|
|
4021
4036
|
const { details: d } = assert;
|
|
4022
4037
|
|
|
4038
|
+
// TODO: rename localObject to scopeObject
|
|
4039
|
+
|
|
4023
4040
|
/**
|
|
4024
|
-
*
|
|
4025
|
-
*
|
|
4026
|
-
* eval(), Function(),
|
|
4041
|
+
* makeSafeEvaluator()
|
|
4042
|
+
* Build the low-level operation used by all evaluators:
|
|
4043
|
+
* eval(), Function(), Compartment.prototype.evaluate().
|
|
4027
4044
|
*
|
|
4028
|
-
* @param {
|
|
4029
|
-
* @param {Object} globalObject
|
|
4030
|
-
* @param {
|
|
4031
|
-
* @param {Object} [options]
|
|
4032
|
-
* @param {Array<Transform>} [options.localTransforms]
|
|
4045
|
+
* @param {Object} options
|
|
4046
|
+
* @param {Object} options.globalObject
|
|
4047
|
+
* @param {Object} [options.localObject]
|
|
4033
4048
|
* @param {Array<Transform>} [options.globalTransforms]
|
|
4034
4049
|
* @param {bool} [options.sloppyGlobalsMode]
|
|
4035
4050
|
* @param {WeakSet} [options.knownScopeProxies]
|
|
4036
4051
|
*/
|
|
4037
|
-
const
|
|
4038
|
-
|
|
4039
|
-
|
|
4040
|
-
localObject = {},
|
|
4041
|
-
{
|
|
4042
|
-
localTransforms = [],
|
|
4052
|
+
const makeSafeEvaluator = ({
|
|
4053
|
+
globalObject,
|
|
4054
|
+
localObject = {},
|
|
4043
4055
|
globalTransforms = [],
|
|
4044
4056
|
sloppyGlobalsMode = false,
|
|
4045
4057
|
knownScopeProxies = new WeakSet() } =
|
|
4046
|
-
{}) =>
|
|
4047
|
-
{
|
|
4048
|
-
// Execute the mandatory transforms last to ensure that any rewritten code
|
|
4049
|
-
// meets those mandatory requirements.
|
|
4050
|
-
source = applyTransforms(source, [
|
|
4051
|
-
...localTransforms,
|
|
4052
|
-
...globalTransforms,
|
|
4053
|
-
mandatoryTransforms]);
|
|
4054
|
-
|
|
4055
|
-
|
|
4058
|
+
{}) => {
|
|
4056
4059
|
const {
|
|
4057
4060
|
scopeHandler,
|
|
4058
4061
|
admitOneUnsafeEvalNext,
|
|
@@ -4064,50 +4067,82 @@ localObject = {},
|
|
|
4064
4067
|
immutableObject,
|
|
4065
4068
|
scopeHandler);
|
|
4066
4069
|
|
|
4070
|
+
weaksetAdd(knownScopeProxies, scopeProxy);
|
|
4071
|
+
|
|
4072
|
+
// Defer creating the actual evaluator to first use.
|
|
4073
|
+
// Creating a compartment should be possible in no-eval environments
|
|
4074
|
+
// It also allows more global constants to be captured by the optimizer
|
|
4075
|
+
let evaluate;
|
|
4076
|
+
const makeEvaluate = () => {
|
|
4077
|
+
if (!evaluate) {
|
|
4078
|
+
const constants = getScopeConstants(globalObject, localObject);
|
|
4079
|
+
const evaluateFactory = makeEvaluateFactory(constants);
|
|
4080
|
+
evaluate = apply(evaluateFactory, scopeProxy, []);
|
|
4081
|
+
}
|
|
4082
|
+
};
|
|
4067
4083
|
|
|
4068
|
-
|
|
4069
|
-
|
|
4070
|
-
|
|
4084
|
+
/**
|
|
4085
|
+
* @param {string} source
|
|
4086
|
+
* @param {Object} [options]
|
|
4087
|
+
* @param {Array<Transform>} [options.localTransforms]
|
|
4088
|
+
*/
|
|
4089
|
+
const safeEvaluate = (source, { localTransforms = [] } = {}) => {
|
|
4090
|
+
makeEvaluate();
|
|
4071
4091
|
|
|
4072
|
-
|
|
4073
|
-
|
|
4074
|
-
|
|
4075
|
-
|
|
4076
|
-
|
|
4077
|
-
|
|
4078
|
-
|
|
4079
|
-
|
|
4080
|
-
|
|
4081
|
-
|
|
4082
|
-
|
|
4083
|
-
|
|
4084
|
-
|
|
4085
|
-
|
|
4086
|
-
//
|
|
4087
|
-
|
|
4088
|
-
|
|
4089
|
-
|
|
4090
|
-
|
|
4091
|
-
|
|
4092
|
-
|
|
4093
|
-
|
|
4094
|
-
|
|
4095
|
-
|
|
4096
|
-
|
|
4097
|
-
|
|
4098
|
-
|
|
4099
|
-
|
|
4100
|
-
|
|
4101
|
-
|
|
4102
|
-
|
|
4103
|
-
|
|
4092
|
+
// Execute the mandatory transforms last to ensure that any rewritten code
|
|
4093
|
+
// meets those mandatory requirements.
|
|
4094
|
+
source = applyTransforms(source, [
|
|
4095
|
+
...localTransforms,
|
|
4096
|
+
...globalTransforms,
|
|
4097
|
+
mandatoryTransforms]);
|
|
4098
|
+
|
|
4099
|
+
|
|
4100
|
+
admitOneUnsafeEvalNext();
|
|
4101
|
+
let err;
|
|
4102
|
+
try {
|
|
4103
|
+
// Ensure that "this" resolves to the safe global.
|
|
4104
|
+
return apply(evaluate, globalObject, [source]);
|
|
4105
|
+
} catch (e) {
|
|
4106
|
+
// stash the child-code error in hopes of debugging the internal failure
|
|
4107
|
+
err = e;
|
|
4108
|
+
throw e;
|
|
4109
|
+
} finally {
|
|
4110
|
+
if (resetOneUnsafeEvalNext()) {
|
|
4111
|
+
// Barring a defect in the SES shim, the scope proxy should allow the
|
|
4112
|
+
// powerful, unsafe `eval` to be used by `evaluate` exactly once, as the
|
|
4113
|
+
// very first name that it attempts to access from the lexical scope.
|
|
4114
|
+
// A defect in the SES shim could throw an exception after our call to
|
|
4115
|
+
// `admitOneUnsafeEvalNext()` and before `evaluate` calls `eval`
|
|
4116
|
+
// internally.
|
|
4117
|
+
// If we get here, SES is very broken.
|
|
4118
|
+
// This condition is one where this vat is now hopelessly confused, and
|
|
4119
|
+
// the vat as a whole should be aborted.
|
|
4120
|
+
// No further code should run.
|
|
4121
|
+
// All immediately reachable state should be abandoned.
|
|
4122
|
+
// However, that is not yet possible, so we at least prevent further
|
|
4123
|
+
// variable resolution via the scopeHandler, and throw an error with
|
|
4124
|
+
// diagnostic info including the thrown error if any from evaluating the
|
|
4125
|
+
// source code.
|
|
4126
|
+
revokeScopeProxy();
|
|
4127
|
+
// TODO A GOOD PLACE TO PANIC(), i.e., kill the vat incarnation.
|
|
4128
|
+
// See https://github.com/Agoric/SES-shim/issues/490
|
|
4129
|
+
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
4130
|
+
assert.fail(d`handler did not reset allowNextEvalToBeUnsafe ${err}`);
|
|
4131
|
+
}
|
|
4104
4132
|
}
|
|
4105
|
-
}
|
|
4106
|
-
|
|
4133
|
+
};
|
|
4134
|
+
|
|
4135
|
+
return { safeEvaluate };
|
|
4136
|
+
};$h_once.makeSafeEvaluator(makeSafeEvaluator);
|
|
4107
4137
|
})
|
|
4108
4138
|
|
|
4109
4139
|
,
|
|
4110
|
-
(({ imports: $h_imports, liveVar: $h_live, onceVar: $h_once, }) => { let TypeError,arrayPush,create,defineProperties,getOwnPropertyDescriptors,evadeHtmlCommentTest,evadeImportExpressionTest,rejectSomeDirectEvalExpressions,
|
|
4140
|
+
(({ imports: $h_imports, liveVar: $h_live, onceVar: $h_once, }) => { let TypeError,arrayPush,create,defineProperties,getOwnPropertyDescriptors,evadeHtmlCommentTest,evadeImportExpressionTest,rejectSomeDirectEvalExpressions,makeSafeEvaluator;$h_imports([["./commons.js", [["TypeError", [$h_a => (TypeError = $h_a)]],["arrayPush", [$h_a => (arrayPush = $h_a)]],["create", [$h_a => (create = $h_a)]],["defineProperties", [$h_a => (defineProperties = $h_a)]],["getOwnPropertyDescriptors", [$h_a => (getOwnPropertyDescriptors = $h_a)]]]],["./transforms.js", [["evadeHtmlCommentTest", [$h_a => (evadeHtmlCommentTest = $h_a)]],["evadeImportExpressionTest", [$h_a => (evadeImportExpressionTest = $h_a)]],["rejectSomeDirectEvalExpressions", [$h_a => (rejectSomeDirectEvalExpressions = $h_a)]]]],["./make-safe-evaluator.js", [["makeSafeEvaluator", [$h_a => (makeSafeEvaluator = $h_a)]]]]]);
|
|
4141
|
+
|
|
4142
|
+
|
|
4143
|
+
|
|
4144
|
+
|
|
4145
|
+
|
|
4111
4146
|
|
|
4112
4147
|
|
|
4113
4148
|
|
|
@@ -4117,10 +4152,57 @@ localObject = {},
|
|
|
4117
4152
|
|
|
4118
4153
|
|
|
4119
4154
|
|
|
4155
|
+
const provideCompartmentEvaluator = (compartmentFields, options) => {
|
|
4156
|
+
const {
|
|
4157
|
+
sloppyGlobalsMode = false,
|
|
4158
|
+
__moduleShimLexicals__ = undefined } =
|
|
4159
|
+
options;
|
|
4160
|
+
|
|
4161
|
+
let safeEvaluate;
|
|
4162
|
+
|
|
4163
|
+
if (__moduleShimLexicals__ === undefined && !sloppyGlobalsMode) {
|
|
4164
|
+
({ safeEvaluate } = compartmentFields);
|
|
4165
|
+
} else {
|
|
4166
|
+
// The scope proxy or global lexicals are different from the
|
|
4167
|
+
// shared evaluator so we need to build a new one
|
|
4168
|
+
|
|
4169
|
+
let { globalTransforms } = compartmentFields;
|
|
4170
|
+
const {
|
|
4171
|
+
globalObject,
|
|
4172
|
+
globalLexicals,
|
|
4173
|
+
knownScopeProxies } =
|
|
4174
|
+
compartmentFields;
|
|
4175
|
+
|
|
4176
|
+
let localObject = globalLexicals;
|
|
4177
|
+
if (__moduleShimLexicals__ !== undefined) {
|
|
4178
|
+
// When using `evaluate` for ESM modules, as should only occur from the
|
|
4179
|
+
// module-shim's module-instance.js, we do not reveal the SES-shim's
|
|
4180
|
+
// module-to-program translation, as this is not standardizable behavior.
|
|
4181
|
+
// However, the `localTransforms` will come from the `__shimTransforms__`
|
|
4182
|
+
// Compartment option in this case, which is a non-standardizable escape
|
|
4183
|
+
// hatch so programs designed specifically for the SES-shim
|
|
4184
|
+
// implementation may opt-in to use the same transforms for `evaluate`
|
|
4185
|
+
// and `import`, at the expense of being tightly coupled to SES-shim.
|
|
4186
|
+
globalTransforms = undefined;
|
|
4187
|
+
|
|
4188
|
+
localObject = create(null, getOwnPropertyDescriptors(globalLexicals));
|
|
4189
|
+
defineProperties(
|
|
4190
|
+
localObject,
|
|
4191
|
+
getOwnPropertyDescriptors(__moduleShimLexicals__));
|
|
4120
4192
|
|
|
4193
|
+
}
|
|
4121
4194
|
|
|
4195
|
+
({ safeEvaluate } = makeSafeEvaluator({
|
|
4196
|
+
globalObject,
|
|
4197
|
+
localObject,
|
|
4198
|
+
globalTransforms,
|
|
4199
|
+
sloppyGlobalsMode,
|
|
4200
|
+
knownScopeProxies }));
|
|
4122
4201
|
|
|
4202
|
+
}
|
|
4123
4203
|
|
|
4204
|
+
return { safeEvaluate };
|
|
4205
|
+
};$h_once.provideCompartmentEvaluator(provideCompartmentEvaluator);
|
|
4124
4206
|
|
|
4125
4207
|
const compartmentEvaluate = (compartmentFields, source, options) => {
|
|
4126
4208
|
// Perform this check first to avoid unecessary sanitizing.
|
|
@@ -4133,8 +4215,6 @@ const compartmentEvaluate = (compartmentFields, source, options) => {
|
|
|
4133
4215
|
// Extract options, and shallow-clone transforms.
|
|
4134
4216
|
const {
|
|
4135
4217
|
transforms = [],
|
|
4136
|
-
sloppyGlobalsMode = false,
|
|
4137
|
-
__moduleShimLexicals__ = undefined,
|
|
4138
4218
|
__evadeHtmlCommentTest__ = false,
|
|
4139
4219
|
__evadeImportExpressionTest__ = false,
|
|
4140
4220
|
__rejectSomeDirectEvalExpressions__ = true // Note default on
|
|
@@ -4150,46 +4230,24 @@ const compartmentEvaluate = (compartmentFields, source, options) => {
|
|
|
4150
4230
|
arrayPush(localTransforms, rejectSomeDirectEvalExpressions);
|
|
4151
4231
|
}
|
|
4152
4232
|
|
|
4153
|
-
|
|
4154
|
-
|
|
4155
|
-
|
|
4156
|
-
let localObject = globalLexicals;
|
|
4157
|
-
if (__moduleShimLexicals__ !== undefined) {
|
|
4158
|
-
// When using `evaluate` for ESM modules, as should only occur from the
|
|
4159
|
-
// module-shim's module-instance.js, we do not reveal the SES-shim's
|
|
4160
|
-
// module-to-program translation, as this is not standardizable behavior.
|
|
4161
|
-
// However, the `localTransforms` will come from the `__shimTransforms__`
|
|
4162
|
-
// Compartment option in this case, which is a non-standardizable escape
|
|
4163
|
-
// hatch so programs designed specifically for the SES-shim
|
|
4164
|
-
// implementation may opt-in to use the same transforms for `evaluate`
|
|
4165
|
-
// and `import`, at the expense of being tightly coupled to SES-shim.
|
|
4166
|
-
globalTransforms = undefined;
|
|
4167
|
-
|
|
4168
|
-
localObject = create(null, getOwnPropertyDescriptors(globalLexicals));
|
|
4169
|
-
defineProperties(
|
|
4170
|
-
localObject,
|
|
4171
|
-
getOwnPropertyDescriptors(__moduleShimLexicals__));
|
|
4233
|
+
const { safeEvaluate } = provideCompartmentEvaluator(
|
|
4234
|
+
compartmentFields,
|
|
4235
|
+
options);
|
|
4172
4236
|
|
|
4173
|
-
}
|
|
4174
4237
|
|
|
4175
|
-
return
|
|
4176
|
-
|
|
4177
|
-
localTransforms,
|
|
4178
|
-
sloppyGlobalsMode,
|
|
4179
|
-
knownScopeProxies });
|
|
4238
|
+
return safeEvaluate(source, {
|
|
4239
|
+
localTransforms });
|
|
4180
4240
|
|
|
4181
4241
|
};$h_once.compartmentEvaluate(compartmentEvaluate);
|
|
4182
4242
|
})
|
|
4183
4243
|
|
|
4184
4244
|
,
|
|
4185
|
-
(({ imports: $h_imports, liveVar: $h_live, onceVar: $h_once, }) => {
|
|
4186
|
-
|
|
4187
|
-
/*
|
|
4245
|
+
(({ imports: $h_imports, liveVar: $h_live, onceVar: $h_once, }) => { $h_imports([]); /*
|
|
4188
4246
|
* makeEvalFunction()
|
|
4189
4247
|
* A safe version of the native eval function which relies on
|
|
4190
|
-
* the safety of
|
|
4248
|
+
* the safety of safeEvaluate for confinement.
|
|
4191
4249
|
*/
|
|
4192
|
-
const makeEvalFunction = (
|
|
4250
|
+
const makeEvalFunction = (safeEvaluate) => {
|
|
4193
4251
|
// We use the the concise method syntax to create an eval without a
|
|
4194
4252
|
// [[Construct]] behavior (such that the invocation "new eval()" throws
|
|
4195
4253
|
// TypeError: eval is not a constructor"), but which still accepts a
|
|
@@ -4203,7 +4261,7 @@ const makeEvalFunction = (globalObject, options = {}) => {
|
|
|
4203
4261
|
// rule. Track.
|
|
4204
4262
|
return source;
|
|
4205
4263
|
}
|
|
4206
|
-
return
|
|
4264
|
+
return safeEvaluate(source);
|
|
4207
4265
|
} }.
|
|
4208
4266
|
eval;
|
|
4209
4267
|
|
|
@@ -4212,8 +4270,7 @@ const makeEvalFunction = (globalObject, options = {}) => {
|
|
|
4212
4270
|
})
|
|
4213
4271
|
|
|
4214
4272
|
,
|
|
4215
|
-
(({ imports: $h_imports, liveVar: $h_live, onceVar: $h_once, }) => { let FERAL_FUNCTION,arrayJoin,arrayPop,defineProperties,getPrototypeOf,
|
|
4216
|
-
|
|
4273
|
+
(({ imports: $h_imports, liveVar: $h_live, onceVar: $h_once, }) => { let FERAL_FUNCTION,arrayJoin,arrayPop,defineProperties,getPrototypeOf,assert;$h_imports([["./commons.js", [["FERAL_FUNCTION", [$h_a => (FERAL_FUNCTION = $h_a)]],["arrayJoin", [$h_a => (arrayJoin = $h_a)]],["arrayPop", [$h_a => (arrayPop = $h_a)]],["defineProperties", [$h_a => (defineProperties = $h_a)]],["getPrototypeOf", [$h_a => (getPrototypeOf = $h_a)]]]],["./error/assert.js", [["assert", [$h_a => (assert = $h_a)]]]]]);
|
|
4217
4274
|
|
|
4218
4275
|
|
|
4219
4276
|
|
|
@@ -4225,9 +4282,9 @@ const makeEvalFunction = (globalObject, options = {}) => {
|
|
|
4225
4282
|
/*
|
|
4226
4283
|
* makeFunctionConstructor()
|
|
4227
4284
|
* A safe version of the native Function which relies on
|
|
4228
|
-
* the safety of
|
|
4285
|
+
* the safety of safeEvaluate for confinement.
|
|
4229
4286
|
*/
|
|
4230
|
-
const makeFunctionConstructor = (
|
|
4287
|
+
const makeFunctionConstructor = (safeEvaluate) => {
|
|
4231
4288
|
// Define an unused parameter to ensure Function.length === 1
|
|
4232
4289
|
const newFunction = function Function(_body) {
|
|
4233
4290
|
// Sanitize all parameters at the entry point.
|
|
@@ -4267,7 +4324,7 @@ const makeFunctionConstructor = (globaObject, options = {}) => {
|
|
|
4267
4324
|
// TODO: since we create an anonymous function, the 'this' value
|
|
4268
4325
|
// isn't bound to the global object as per specs, but set as undefined.
|
|
4269
4326
|
const src = `(function anonymous(${parameters}\n) {\n${bodyText}\n})`;
|
|
4270
|
-
return
|
|
4327
|
+
return safeEvaluate(src);
|
|
4271
4328
|
};
|
|
4272
4329
|
|
|
4273
4330
|
defineProperties(newFunction, {
|
|
@@ -5658,29 +5715,14 @@ const whitelist = {
|
|
|
5658
5715
|
|
|
5659
5716
|
|
|
5660
5717
|
/**
|
|
5661
|
-
*
|
|
5662
|
-
*
|
|
5663
|
-
* (
|
|
5664
|
-
* `
|
|
5665
|
-
* `sharedGlobalPropertyNames`.
|
|
5718
|
+
* setGlobalObjectConstantProperties()
|
|
5719
|
+
* Initializes a new global object using a process similar to ECMA specifications
|
|
5720
|
+
* (SetDefaultGlobalBindings). This process is split between this function and
|
|
5721
|
+
* `setGlobalObjectMutableProperties`.
|
|
5666
5722
|
*
|
|
5667
5723
|
* @param {Object} globalObject
|
|
5668
|
-
* @param {Object} intrinsics
|
|
5669
|
-
* @param {Object} newGlobalPropertyNames
|
|
5670
|
-
* @param {Function} makeCompartmentConstructor
|
|
5671
|
-
* @param {Object} compartmentPrototype
|
|
5672
|
-
* @param {Object} [options]
|
|
5673
|
-
* @param {Array<Transform>} [options.globalTransforms]
|
|
5674
|
-
* @param {(Object) => void} [options.markVirtualizedNativeFunction]
|
|
5675
5724
|
*/
|
|
5676
|
-
const
|
|
5677
|
-
globalObject,
|
|
5678
|
-
intrinsics,
|
|
5679
|
-
newGlobalPropertyNames,
|
|
5680
|
-
makeCompartmentConstructor,
|
|
5681
|
-
compartmentPrototype,
|
|
5682
|
-
{ globalTransforms, markVirtualizedNativeFunction }) =>
|
|
5683
|
-
{
|
|
5725
|
+
const setGlobalObjectConstantProperties = (globalObject) => {
|
|
5684
5726
|
for (const [name, constant] of entries(constantProperties)) {
|
|
5685
5727
|
defineProperty(globalObject, name, {
|
|
5686
5728
|
value: constant,
|
|
@@ -5689,7 +5731,33 @@ compartmentPrototype,
|
|
|
5689
5731
|
configurable: false });
|
|
5690
5732
|
|
|
5691
5733
|
}
|
|
5734
|
+
};
|
|
5692
5735
|
|
|
5736
|
+
/**
|
|
5737
|
+
* setGlobalObjectMutableProperties()
|
|
5738
|
+
* Create new global object using a process similar to ECMA specifications
|
|
5739
|
+
* (portions of SetRealmGlobalObject and SetDefaultGlobalBindings).
|
|
5740
|
+
* `newGlobalPropertyNames` should be either `initialGlobalPropertyNames` or
|
|
5741
|
+
* `sharedGlobalPropertyNames`.
|
|
5742
|
+
*
|
|
5743
|
+
* @param {Object} globalObject
|
|
5744
|
+
* @param {Object} param1
|
|
5745
|
+
* @param {Object} param1.intrinsics
|
|
5746
|
+
* @param {Object} param1.newGlobalPropertyNames
|
|
5747
|
+
* @param {Function} param1.makeCompartmentConstructor
|
|
5748
|
+
* @param {(string, Object?) => any} param1.safeEvaluate
|
|
5749
|
+
* @param {(Object) => void} param1.markVirtualizedNativeFunction
|
|
5750
|
+
*/$h_once.setGlobalObjectConstantProperties(setGlobalObjectConstantProperties);
|
|
5751
|
+
const setGlobalObjectMutableProperties = (
|
|
5752
|
+
globalObject,
|
|
5753
|
+
{
|
|
5754
|
+
intrinsics,
|
|
5755
|
+
newGlobalPropertyNames,
|
|
5756
|
+
makeCompartmentConstructor,
|
|
5757
|
+
safeEvaluate,
|
|
5758
|
+
markVirtualizedNativeFunction }) =>
|
|
5759
|
+
|
|
5760
|
+
{
|
|
5693
5761
|
for (const [name, intrinsicName] of entries(universalPropertyNames)) {
|
|
5694
5762
|
if (objectHasOwnProperty(intrinsics, intrinsicName)) {
|
|
5695
5763
|
defineProperty(globalObject, name, {
|
|
@@ -5714,12 +5782,8 @@ compartmentPrototype,
|
|
|
5714
5782
|
|
|
5715
5783
|
const perCompartmentGlobals = {
|
|
5716
5784
|
globalThis: globalObject,
|
|
5717
|
-
eval: makeEvalFunction(
|
|
5718
|
-
|
|
5719
|
-
|
|
5720
|
-
Function: makeFunctionConstructor(globalObject, {
|
|
5721
|
-
globalTransforms }) };
|
|
5722
|
-
|
|
5785
|
+
eval: makeEvalFunction(safeEvaluate),
|
|
5786
|
+
Function: makeFunctionConstructor(safeEvaluate) };
|
|
5723
5787
|
|
|
5724
5788
|
|
|
5725
5789
|
perCompartmentGlobals.Compartment = makeCompartmentConstructor(
|
|
@@ -5741,7 +5805,7 @@ compartmentPrototype,
|
|
|
5741
5805
|
markVirtualizedNativeFunction(value);
|
|
5742
5806
|
}
|
|
5743
5807
|
}
|
|
5744
|
-
};$h_once.
|
|
5808
|
+
};$h_once.setGlobalObjectMutableProperties(setGlobalObjectMutableProperties);
|
|
5745
5809
|
})
|
|
5746
5810
|
|
|
5747
5811
|
,
|
|
@@ -6893,7 +6957,11 @@ moduleRecord) =>
|
|
|
6893
6957
|
})
|
|
6894
6958
|
|
|
6895
6959
|
,
|
|
6896
|
-
(({ imports: $h_imports, liveVar: $h_live, onceVar: $h_once, }) => { let Map,ReferenceError,TypeError,WeakMap,WeakSet,arrayFilter,arrayJoin,assign,defineProperties,entries,freeze,getOwnPropertyNames,promiseThen,weakmapGet,weakmapSet,weaksetHas,
|
|
6960
|
+
(({ imports: $h_imports, liveVar: $h_live, onceVar: $h_once, }) => { let Map,ReferenceError,TypeError,WeakMap,WeakSet,arrayFilter,arrayJoin,assign,defineProperties,entries,freeze,getOwnPropertyNames,promiseThen,weakmapGet,weakmapSet,weaksetHas,setGlobalObjectConstantProperties,setGlobalObjectMutableProperties,isValidIdentifierName,sharedGlobalPropertyNames,load,link,getDeferredExports,assert,compartmentEvaluate,makeSafeEvaluator;$h_imports([["./commons.js", [["Map", [$h_a => (Map = $h_a)]],["ReferenceError", [$h_a => (ReferenceError = $h_a)]],["TypeError", [$h_a => (TypeError = $h_a)]],["WeakMap", [$h_a => (WeakMap = $h_a)]],["WeakSet", [$h_a => (WeakSet = $h_a)]],["arrayFilter", [$h_a => (arrayFilter = $h_a)]],["arrayJoin", [$h_a => (arrayJoin = $h_a)]],["assign", [$h_a => (assign = $h_a)]],["defineProperties", [$h_a => (defineProperties = $h_a)]],["entries", [$h_a => (entries = $h_a)]],["freeze", [$h_a => (freeze = $h_a)]],["getOwnPropertyNames", [$h_a => (getOwnPropertyNames = $h_a)]],["promiseThen", [$h_a => (promiseThen = $h_a)]],["weakmapGet", [$h_a => (weakmapGet = $h_a)]],["weakmapSet", [$h_a => (weakmapSet = $h_a)]],["weaksetHas", [$h_a => (weaksetHas = $h_a)]]]],["./global-object.js", [["setGlobalObjectConstantProperties", [$h_a => (setGlobalObjectConstantProperties = $h_a)]],["setGlobalObjectMutableProperties", [$h_a => (setGlobalObjectMutableProperties = $h_a)]]]],["./scope-constants.js", [["isValidIdentifierName", [$h_a => (isValidIdentifierName = $h_a)]]]],["./whitelist.js", [["sharedGlobalPropertyNames", [$h_a => (sharedGlobalPropertyNames = $h_a)]]]],["./module-load.js", [["load", [$h_a => (load = $h_a)]]]],["./module-link.js", [["link", [$h_a => (link = $h_a)]]]],["./module-proxy.js", [["getDeferredExports", [$h_a => (getDeferredExports = $h_a)]]]],["./error/assert.js", [["assert", [$h_a => (assert = $h_a)]]]],["./compartment-evaluate.js", [["compartmentEvaluate", [$h_a => (compartmentEvaluate = $h_a)]]]],["./make-safe-evaluator.js", [["makeSafeEvaluator", [$h_a => (makeSafeEvaluator = $h_a)]]]]]);
|
|
6961
|
+
|
|
6962
|
+
|
|
6963
|
+
|
|
6964
|
+
|
|
6897
6965
|
|
|
6898
6966
|
|
|
6899
6967
|
|
|
@@ -7101,7 +7169,7 @@ markVirtualizedNativeFunction) =>
|
|
|
7101
7169
|
name = '<unknown>',
|
|
7102
7170
|
transforms = [],
|
|
7103
7171
|
__shimTransforms__ = [],
|
|
7104
|
-
globalLexicals = {},
|
|
7172
|
+
globalLexicals: globalLexicalsOption = {},
|
|
7105
7173
|
resolveHook,
|
|
7106
7174
|
importHook,
|
|
7107
7175
|
moduleMapHook } =
|
|
@@ -7139,23 +7207,8 @@ markVirtualizedNativeFunction) =>
|
|
|
7139
7207
|
}
|
|
7140
7208
|
}
|
|
7141
7209
|
|
|
7142
|
-
const globalObject = {};
|
|
7143
|
-
initGlobalObject(
|
|
7144
|
-
globalObject,
|
|
7145
|
-
intrinsics,
|
|
7146
|
-
sharedGlobalPropertyNames,
|
|
7147
|
-
targetMakeCompartmentConstructor,
|
|
7148
|
-
this.constructor.prototype,
|
|
7149
|
-
{
|
|
7150
|
-
globalTransforms,
|
|
7151
|
-
markVirtualizedNativeFunction });
|
|
7152
|
-
|
|
7153
|
-
|
|
7154
|
-
|
|
7155
|
-
assign(globalObject, endowments);
|
|
7156
|
-
|
|
7157
7210
|
const invalidNames = arrayFilter(
|
|
7158
|
-
getOwnPropertyNames(
|
|
7211
|
+
getOwnPropertyNames(globalLexicalsOption),
|
|
7159
7212
|
(identifier) => !isValidIdentifierName(identifier));
|
|
7160
7213
|
|
|
7161
7214
|
if (invalidNames.length) {
|
|
@@ -7166,23 +7219,51 @@ markVirtualizedNativeFunction) =>
|
|
|
7166
7219
|
}; these names would not be lexically mentionable`);
|
|
7167
7220
|
|
|
7168
7221
|
}
|
|
7222
|
+
// The caller continues to own the globalLexicals object they passed to
|
|
7223
|
+
// the compartment constructor, but the compartment only respects the
|
|
7224
|
+
// original values and they are constants in the scope of evaluated
|
|
7225
|
+
// programs and executed modules.
|
|
7226
|
+
// This shallow copy captures only the values of enumerable own
|
|
7227
|
+
// properties, erasing accessors.
|
|
7228
|
+
// The snapshot is frozen to ensure that the properties are immutable
|
|
7229
|
+
// when transferred-by-property-descriptor onto local scope objects.
|
|
7230
|
+
const globalLexicals = freeze({ ...globalLexicalsOption });
|
|
7231
|
+
|
|
7232
|
+
const globalObject = {};
|
|
7233
|
+
|
|
7234
|
+
// We must initialize all constant properties first because
|
|
7235
|
+
// `makeSafeEvaluator` may use them to create optimized bindings
|
|
7236
|
+
// in the evaluator.
|
|
7237
|
+
// TODO: consider merging into a single initialization if internal
|
|
7238
|
+
// evaluator is no longer eagerly created
|
|
7239
|
+
setGlobalObjectConstantProperties(globalObject);
|
|
7169
7240
|
|
|
7170
7241
|
const knownScopeProxies = new WeakSet();
|
|
7242
|
+
const { safeEvaluate } = makeSafeEvaluator({
|
|
7243
|
+
globalObject,
|
|
7244
|
+
localObject: globalLexicals,
|
|
7245
|
+
globalTransforms,
|
|
7246
|
+
sloppyGlobalsMode: false,
|
|
7247
|
+
knownScopeProxies });
|
|
7248
|
+
|
|
7249
|
+
|
|
7250
|
+
setGlobalObjectMutableProperties(globalObject, {
|
|
7251
|
+
intrinsics,
|
|
7252
|
+
newGlobalPropertyNames: sharedGlobalPropertyNames,
|
|
7253
|
+
makeCompartmentConstructor: targetMakeCompartmentConstructor,
|
|
7254
|
+
safeEvaluate,
|
|
7255
|
+
markVirtualizedNativeFunction });
|
|
7256
|
+
|
|
7257
|
+
|
|
7258
|
+
assign(globalObject, endowments);
|
|
7171
7259
|
|
|
7172
7260
|
weakmapSet(privateFields, this, {
|
|
7173
7261
|
name,
|
|
7174
7262
|
globalTransforms,
|
|
7175
7263
|
globalObject,
|
|
7176
7264
|
knownScopeProxies,
|
|
7177
|
-
|
|
7178
|
-
|
|
7179
|
-
// original values and they are constants in the scope of evaluated
|
|
7180
|
-
// programs and executed modules.
|
|
7181
|
-
// This shallow copy captures only the values of enumerable own
|
|
7182
|
-
// properties, erasing accessors.
|
|
7183
|
-
// The snapshot is frozen to ensure that the properties are immutable
|
|
7184
|
-
// when transferred-by-property-descriptor onto local scope objects.
|
|
7185
|
-
globalLexicals: freeze({ ...globalLexicals }),
|
|
7265
|
+
globalLexicals,
|
|
7266
|
+
safeEvaluate,
|
|
7186
7267
|
resolveHook,
|
|
7187
7268
|
importHook,
|
|
7188
7269
|
moduleMap,
|
|
@@ -9833,7 +9914,11 @@ markVirtualizedNativeFunction)
|
|
|
9833
9914
|
})
|
|
9834
9915
|
|
|
9835
9916
|
,
|
|
9836
|
-
(({ imports: $h_imports, liveVar: $h_live, onceVar: $h_once, }) => { let globalThis,is,keys,ownKeys,makeHardener,makeIntrinsicsCollector,whitelistIntrinsics,tameFunctionConstructors,tameDateConstructor,tameMathObject,tameRegExpConstructor,enablePropertyOverrides,tameLocaleMethods,
|
|
9917
|
+
(({ imports: $h_imports, liveVar: $h_live, onceVar: $h_once, }) => { let globalThis,is,keys,ownKeys,makeHardener,makeIntrinsicsCollector,whitelistIntrinsics,tameFunctionConstructors,tameDateConstructor,tameMathObject,tameRegExpConstructor,enablePropertyOverrides,tameLocaleMethods,setGlobalObjectConstantProperties,setGlobalObjectMutableProperties,makeSafeEvaluator,initialGlobalPropertyNames,tameFunctionToString,tameDomains,tameConsole,tameErrorConstructor,assert,makeAssert;$h_imports([["./commons.js", [["globalThis", [$h_a => (globalThis = $h_a)]],["is", [$h_a => (is = $h_a)]],["keys", [$h_a => (keys = $h_a)]],["ownKeys", [$h_a => (ownKeys = $h_a)]]]],["./make-hardener.js", [["makeHardener", [$h_a => (makeHardener = $h_a)]]]],["./intrinsics.js", [["makeIntrinsicsCollector", [$h_a => (makeIntrinsicsCollector = $h_a)]]]],["./whitelist-intrinsics.js", [["default", [$h_a => (whitelistIntrinsics = $h_a)]]]],["./tame-function-constructors.js", [["default", [$h_a => (tameFunctionConstructors = $h_a)]]]],["./tame-date-constructor.js", [["default", [$h_a => (tameDateConstructor = $h_a)]]]],["./tame-math-object.js", [["default", [$h_a => (tameMathObject = $h_a)]]]],["./tame-regexp-constructor.js", [["default", [$h_a => (tameRegExpConstructor = $h_a)]]]],["./enable-property-overrides.js", [["default", [$h_a => (enablePropertyOverrides = $h_a)]]]],["./tame-locale-methods.js", [["default", [$h_a => (tameLocaleMethods = $h_a)]]]],["./global-object.js", [["setGlobalObjectConstantProperties", [$h_a => (setGlobalObjectConstantProperties = $h_a)]],["setGlobalObjectMutableProperties", [$h_a => (setGlobalObjectMutableProperties = $h_a)]]]],["./make-safe-evaluator.js", [["makeSafeEvaluator", [$h_a => (makeSafeEvaluator = $h_a)]]]],["./whitelist.js", [["initialGlobalPropertyNames", [$h_a => (initialGlobalPropertyNames = $h_a)]]]],["./tame-function-tostring.js", [["tameFunctionToString", [$h_a => (tameFunctionToString = $h_a)]]]],["./tame-domains.js", [["tameDomains", [$h_a => (tameDomains = $h_a)]]]],["./error/tame-console.js", [["tameConsole", [$h_a => (tameConsole = $h_a)]]]],["./error/tame-error-constructor.js", [["default", [$h_a => (tameErrorConstructor = $h_a)]]]],["./error/assert.js", [["assert", [$h_a => (assert = $h_a)]],["makeAssert", [$h_a => (makeAssert = $h_a)]]]]]);
|
|
9918
|
+
|
|
9919
|
+
|
|
9920
|
+
|
|
9921
|
+
|
|
9837
9922
|
|
|
9838
9923
|
|
|
9839
9924
|
|
|
@@ -10124,15 +10209,17 @@ options = {}) =>
|
|
|
10124
10209
|
|
|
10125
10210
|
// Initialize the powerful initial global, i.e., the global of the
|
|
10126
10211
|
// start compartment, from the intrinsics.
|
|
10127
|
-
initGlobalObject(
|
|
10128
|
-
globalThis,
|
|
10129
|
-
intrinsics,
|
|
10130
|
-
initialGlobalPropertyNames,
|
|
10131
|
-
makeCompartmentConstructor,
|
|
10132
|
-
compartmentPrototype,
|
|
10133
|
-
{
|
|
10134
|
-
markVirtualizedNativeFunction });
|
|
10135
10212
|
|
|
10213
|
+
setGlobalObjectConstantProperties(globalThis);
|
|
10214
|
+
|
|
10215
|
+
const { safeEvaluate } = makeSafeEvaluator({ globalObject: globalThis });
|
|
10216
|
+
|
|
10217
|
+
setGlobalObjectMutableProperties(globalThis, {
|
|
10218
|
+
intrinsics,
|
|
10219
|
+
newGlobalPropertyNames: initialGlobalPropertyNames,
|
|
10220
|
+
makeCompartmentConstructor,
|
|
10221
|
+
safeEvaluate,
|
|
10222
|
+
markVirtualizedNativeFunction });
|
|
10136
10223
|
|
|
10137
10224
|
|
|
10138
10225
|
/**
|