You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**Background**: Hermes is a JavaScript engine that does not yet support direct `eval()` nor the `with` statement. The SES `evalTaming` default option `"safeEval"` uses multiple nested `with` statements to create a restricted scope chain, so on Hermes we must run under the `"unsafeEval"` option. However SES cannot initialize unless 'eval' is the original intrinsic 'eval', suitable for direct-eval (dynamically scoped eval), which is where we introduce the `hostEvaluators` option `"no-direct"`.
625
+
626
+
```js
627
+
lockdown(); // Warn user to set `hostEvaluators`, which will soon default to 'all' (breaking change with a strict Content Security Policy)
628
+
// or
629
+
lockdown({ hostEvaluators:'all' }); // SES fails to initialize if direct-eval is not functional or evaluators are not allowed to execute
630
+
// vs
631
+
lockdown({ hostEvaluators:'none' }); // SES initializes when evaluators are not allowed to execute (e.g. a strict CSP)
632
+
// vs
633
+
lockdown({ hostEvaluators:'no-direct' }); // SES initializes without direct-eval (e.g. on Hermes) but does not allow Compartment evaluate
634
+
```
635
+
636
+
```js
637
+
lockdown({ evalTaming:'unsafeEval', hostEvaluators:'no-direct' }); // Both options required on Hermes to initialize SES
638
+
```
639
+
640
+
If `lockdown` does not receive a `hostEvaluators` option, it will respect
641
+
`process.env.LOCKDOWN_HOST_EVALUATORS`.
642
+
643
+
```console
644
+
LOCKDOWN_HOST_EVALUATORS=all
645
+
LOCKDOWN_HOST_EVALUATORS=none
646
+
LOCKDOWN_HOST_EVALUATORS=no-direct
647
+
```
648
+
620
649
## `stackFiltering` Options
621
650
622
651
**Background**: The error stacks shown by many JavaScript engines are
// This could be a strict Content Security Policy containing either a `default-src` or a `script-src` directive, or an ES host with broken APIs.
279
+
constnoEvaluators=!evalAllowed&&!functionAllowed;// eval() itself and the Function() constructor are not allowed to execute.
280
+
281
+
hostEvaluators==='all'&&
282
+
assert(
283
+
!noEvaluators,
284
+
"'hostEvaluators' was set to 'all', but the Function() constructor and eval() are not allowed to execute (SES_DIRECT_EVAL)",
285
+
);
286
+
287
+
hostEvaluators==='none'&&
288
+
assert(
289
+
noEvaluators,
290
+
"'hostEvaluators' was set to 'none', but the Function() constructor and eval() are allowed to execute (SES_DIRECT_EVAL)",
291
+
);
292
+
293
+
hostEvaluators==='no-direct'&&
294
+
assert(
295
+
!directEvalAllowed,
296
+
`'hostEvaluators' was set to 'no-direct', but ${directEvalAllowed===true ? 'direct eval is functional' : 'the Function() constructor and eval() are not allowed to execute'} (SES_DIRECT_EVAL)`,
297
+
);
298
+
299
+
// TODO: Remove '_legacy' when 'all' introduced as the new default option (breaking change).
300
+
// For backwards compatibility under '_legacy', we do not error with a strict CSP, since directEvalAllowed remains undefined.
0 commit comments