-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(ses): hostEvaluators
lockdown option
#2723
base: master
Are you sure you want to change the base?
Conversation
if (legacyHermesTaming === 'unsafe') { | ||
globalThis.testCompartmentHooks = undefined; | ||
// @ts-ignore Compartment does exist on globalThis | ||
delete globalThis.Compartment; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IF an environment is lacking the direct eval support, we won't be able to provide the compartment evaluation capabilities, but we can have a constructor that creates instances with fresh tamed copies of compartmentInstance.globalThis that we use in bundling (lavamoat's webpack and browserify) and might want to use in Hermes in the future. So I'm not 100% sure if we want to delete Compartment or make evaluation related functionality throw a descriptive error from the implementation that depends on direct eval.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so currently deleting compartment breaks hermes on webpack (repack)? 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and only disabling compartmentInstance.evaluate would be more ideal?
to still be able to construct instances (with fresh tamed copies of compartmentInstance.globalThis)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i see, bundling ses without compartment-shim proved difficult, partial compartments seem a better alternative
endo/packages/ses/src/make-safe-evaluator.js
Lines 45 to 46 in 3f9b909
// Creating a compartment should be possible in no-eval environments | |
// It also allows more global constants to be captured by the optimizer |
*/ | ||
export const makeFunctionConstructor = safeEvaluate => { | ||
export const makeFunctionConstructor = evaluator => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIR our conclusion was, as long as we don't want compartmentalization, the indirect eval used for tamed eval and tamed Function would transparently work and we don't need to throw an error when that's used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was more a refactor since the arg name and JSDoc both assume safeEvaluate which is incorrect (it could be noEvaluate)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
regardless of compartmentalization, the (hermes) indirect eval used for tamed eval (string args only) and tamed Function doesn't transparently work, since safeEval eventually calls makeSafeEvaluator, which throws Hermes' ambiguousUncaught SyntaxError: 2:5:invalid statement encountered
, so i think it's better to throw an error that safeEval requires an engine that supports with
statement
69a97f5
to
7e2b07a
Compare
fa54256
to
5793270
Compare
1e87397
to
063ec33
Compare
8cf7a5e
to
d0269ff
Compare
hostEvaluators
lockdown option
819c22f
to
de25e68
Compare
de25e68
to
13989af
Compare
13989af
to
88ddc37
Compare
f85b1c8
to
f974d83
Compare
f974d83
to
70fa62e
Compare
@@ -189,6 +188,10 @@ export const repairIntrinsics = (options = {}) => { | |||
/** @param {string} debugName */ | |||
debugName => debugName !== '', | |||
), | |||
hostEvaluators = /** @type { 'all' | 'none' | 'no-direct' } */ ( | |||
// TODO: Breaking change, ensure backwards compatibility under CSP. | |||
getenv('LOCKDOWN_HOST_EVALUATORS', 'all') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
undefined
as default value not currently supported by getEnvironmentOption
70fa62e
to
4f714c0
Compare
Refs: #1891 (tracker), tested on #2334, Endo Sync: 2025-01-29
TODO
legacyHermesTaming: safe (default), unsafe{ hostEvaluators: 'none' }
now explicitly requireddisable: globalThis Compartment and testCompartmentHooksFollow-up: new Compartment() fails on removeUnpermittedIntrinsics at
Tolerating undeletable intrinsics.%CompartmentPrototype%.importNow.prototype === undefined
Uncaught TypeError: property is not configurable
test branch https://github.com/endojs/endo/tree/ses-hermes-p2 (from #2334)
yarn build:hermes
bundle ses for hermesyarn test:hermes
run ses/test/_hermes-smoke.jsHermes eval behaviour on
bin/hermesc
(standalone compiler) andbin/hermes
(vm, eshost)