Skip to content

Commit 7714ec9

Browse files
committed
fix(ses): lockdown options should be kebob-case
1 parent a7954e9 commit 7714ec9

9 files changed

+56
-33
lines changed

packages/ses/docs/lockdown.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Each option is explained in its own section below.
2929
| `errorTrapping` | `'platform'` | `'exit'` `'abort'` `'report'` `'none'` | handling of uncaught exceptions ([details](#errortrapping-options)) |
3030
| `reporting` | `'platform'` | `'console'` `'none'` | where to report warnings ([details](#reporting-options))
3131
| `unhandledRejectionTrapping` | `'report'` | `'none'` | handling of finalized unhandled rejections ([details](#unhandledrejectiontrapping-options)) |
32-
| `evalTaming` | `'safeEval'` | `'unsafeEval'` `'noEval'` | `eval` and `Function` of the start compartment ([details](#evaltaming-options)) |
32+
| `evalTaming` | `'safe-eval'` | `'unsafe-eval'` `'no-eval'` | `eval` and `Function` of the start compartment ([details](#evaltaming-options)) |
3333
| `stackFiltering` | `'concise'` | `'verbose'` | deep stacks signal/noise ([details](#stackfiltering-options)) |
3434
| `overrideTaming` | `'moderate'` | `'min'` or `'severe'` | override mistake antidote ([details](#overridetaming-options)) |
3535
| `overrideDebug` | `[]` | array of property names | detect override mistake ([details](#overridedebug-options)) |
@@ -574,15 +574,15 @@ The default lockdown behavior isolates all of these evaluators.
574574

575575
Replacing the realm's initial evaluators is not necessary to ensure the
576576
isolation of guest code because guest code must not run in the start compartment.
577-
Although the code run in the start compartment is normally referred to as "trusted", we mean only that we assume it was not written maliciously. It may still be buggy, and it may be buggy in a way that is exploitable by malicious guest code. To limit the harm that such vulnerabilities can cause, the default (`"safeEval"`) setting replaces the evaluators of the start compartment with their safe alternatives.
577+
Although the code run in the start compartment is normally referred to as "trusted", we mean only that we assume it was not written maliciously. It may still be buggy, and it may be buggy in a way that is exploitable by malicious guest code. To limit the harm that such vulnerabilities can cause, the default (`"safe-eval"`) setting replaces the evaluators of the start compartment with their safe alternatives.
578578

579579
However, in the shim, only the exact `eval` function from the start compartment can be used to
580-
perform direct-eval, which runs in the lexical scope in which the direct-eval syntax appears (direct-eval is a special form rather than a function call).
580+
perform direct-eval, which runs in the lexical scope in which the direct-eval syntax appears (the direct-eval syntax is a special form rather than a function call).
581581
The SES shim itself uses direct-eval internally to construct an isolated
582582
evaluator, so replacing the initial `eval` prevents any subsequent program
583583
from using the same mechanism to isolate a guest program.
584584

585-
The `"unsafeEval"` option for `evalTaming` leaves the original `eval` in place
585+
The `"unsafe-eval"` option for `evalTaming` leaves the original `eval` in place
586586
for other isolation mechanisms like isolation code generators that work in
587587
tandem with SES.
588588
This option may be useful for web pages with an environment that allows `unsafe-eval`,
@@ -593,28 +593,28 @@ In these cases, SES cannot be responsible for maintaining the isolation of
593593
guest code. If you're going to use `eval`, [Trusted
594594
Types](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/trusted-types) may help maintain security.
595595

596-
The `"noEval"` option emulates a Content Security Policy that disallows
596+
The `"no-eval"` option emulates a Content Security Policy that disallows
597597
`unsafe-eval` by replacing all evaluators with functions that throw an
598598
exception.
599599

600600
```js
601-
lockdown(); // evalTaming defaults to 'safeEval'
601+
lockdown(); // evalTaming defaults to 'safe-eval'
602602
// or
603-
lockdown({ evalTaming: 'noEval' }); // disallowing calling eval like there is a CSP limitation.
603+
lockdown({ evalTaming: 'no-eval' }); // disallowing calling eval like there is a CSP limitation.
604604
// vs
605605

606606
// Please use this option with caution.
607607
// You may want to use Trusted Types or Content Security Policy with this option.
608-
lockdown({ evalTaming: 'unsafeEval' });
608+
lockdown({ evalTaming: 'unsafe-eval' });
609609
```
610610

611611
If `lockdown` does not receive an `evalTaming` option, it will respect
612612
`process.env.LOCKDOWN_EVAL_TAMING`.
613613

614614
```console
615-
LOCKDOWN_EVAL_TAMING=safeEval
616-
LOCKDOWN_EVAL_TAMING=noEval
617-
LOCKDOWN_EVAL_TAMING=unsafeEval
615+
LOCKDOWN_EVAL_TAMING=safe-eval
616+
LOCKDOWN_EVAL_TAMING=no-eval
617+
LOCKDOWN_EVAL_TAMING=unsafe-eval
618618
```
619619

620620
## `stackFiltering` Options
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# SES is disallowing eval in the current compartment (`SES_NO_EVAL`)
22

3-
The SES Hardened JavaScript shim is configured to reject any source evaluation in the current compartment. This is configured in the `lockdown` option. To mitigate this error, change the [lockdown option `"evalTaming"`](../docs/lockdown.md) from `"noEval"` to either `"safeEval"` (default) or `"unsafeEval"`.
3+
The SES Hardened JavaScript shim is configured to reject any source evaluation in the current compartment. This is configured in the `lockdown` option. To mitigate this error, change the [lockdown option `"evalTaming"`](../docs/lockdown.md) from `"no-eval"` to either `"safe-eval"` (default) or `"unsafe-eval"`.

packages/ses/src/commons.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ export const FERAL_FUNCTION = Function;
320320

321321
export const noEvalEvaluate = () => {
322322
// See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_NO_EVAL.md
323-
throw TypeError('Cannot eval with evalTaming set to "noEval" (SES_NO_EVAL)');
323+
throw TypeError('Cannot eval with evalTaming set to "no-eval" (SES_NO_EVAL)');
324324
};
325325

326326
// ////////////////// FERAL_STACK_GETTER FERAL_STACK_SETTER ////////////////////

packages/ses/src/eval-scope.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ const { Fail } = assert;
2727
// prepareStack(depth, () => {
2828
// (eval)('');
2929
// });
30-
// const unsafeEval = (eval);
31-
// const safeEval = (eval);
32-
// const realGlobal = unsafeEval('globalThis');
30+
// const unsafe-eval = (eval);
31+
// const safe-eval = (eval);
32+
// const realGlobal = unsafe-eval('globalThis');
3333
//
3434
// To protect against that case, we also delete `eval` from the `evalScope` in
3535
// a `finally` block surrounding the call to the safe evaluator.

packages/ses/src/lockdown.js

+26-10
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ export const repairIntrinsics = (options = {}) => {
183183
),
184184
stackFiltering = getenv('LOCKDOWN_STACK_FILTERING', 'concise'),
185185
domainTaming = getenv('LOCKDOWN_DOMAIN_TAMING', 'safe'),
186-
evalTaming = getenv('LOCKDOWN_EVAL_TAMING', 'safeEval'),
186+
evalTaming = getenv('LOCKDOWN_EVAL_TAMING', 'safe-eval'),
187187
overrideDebug = arrayFilter(
188188
stringSplit(getenv('LOCKDOWN_OVERRIDE_DEBUG', ''), ','),
189189
/** @param {string} debugName */
@@ -203,9 +203,12 @@ export const repairIntrinsics = (options = {}) => {
203203
legacyRegeneratorRuntimeTaming === 'unsafe-ignore' ||
204204
Fail`lockdown(): non supported option legacyRegeneratorRuntimeTaming: ${q(legacyRegeneratorRuntimeTaming)}`;
205205

206-
evalTaming === 'unsafeEval' ||
207-
evalTaming === 'safeEval' ||
208-
evalTaming === 'noEval' ||
206+
evalTaming === 'unsafe-eval' ||
207+
evalTaming === 'unsafeEval' || // deprecated
208+
evalTaming === 'safe-eval' ||
209+
evalTaming === 'safeEval' || // deprecated
210+
evalTaming === 'no-eval' ||
211+
evalTaming === 'noEval' || // deprecated
209212
Fail`lockdown(): non supported option evalTaming: ${q(evalTaming)}`;
210213

211214
// Assert that only supported options were passed.
@@ -408,23 +411,36 @@ export const repairIntrinsics = (options = {}) => {
408411
markVirtualizedNativeFunction,
409412
});
410413

411-
if (evalTaming === 'noEval') {
414+
if (
415+
evalTaming === 'no-eval' ||
416+
// deprecated
417+
evalTaming === 'noEval'
418+
) {
412419
setGlobalObjectEvaluators(
413420
globalThis,
414421
noEvalEvaluate,
415422
markVirtualizedNativeFunction,
416423
);
417-
} else if (evalTaming === 'safeEval') {
424+
} else if (
425+
evalTaming === 'safe-eval' ||
426+
// deprecated
427+
evalTaming === 'safeEval'
428+
) {
418429
const { safeEvaluate } = makeSafeEvaluator({ globalObject: globalThis });
419430
setGlobalObjectEvaluators(
420431
globalThis,
421432
safeEvaluate,
422433
markVirtualizedNativeFunction,
423434
);
424-
} else if (evalTaming === 'unsafeEval') {
425-
// Leave eval function and Function constructor of the initial compartment in-tact.
426-
// Other compartments will not have access to these evaluators unless a guest program
427-
// escapes containment.
435+
} else if (
436+
evalTaming === 'unsafe-eval' ||
437+
// deprecated
438+
evalTaming === 'unsafeEval'
439+
) {
440+
// Leave eval function and Function constructor of the initial
441+
// compartment intact.
442+
// Other compartments will not have access to these evaluators unless a
443+
// guest program escapes containment.
428444
}
429445

430446
/**

packages/ses/test/evalTaming-noEval.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import test from 'ava';
22
import '../index.js';
33

4-
lockdown({ evalTaming: 'noEval' });
4+
lockdown({ evalTaming: 'no-eval' });
55

6-
test('no eval when evalTaming is noEval.', t => {
6+
test('no eval when evalTaming is no-eval.', t => {
77
// eslint-disable-next-line no-eval
88
t.throws(() => eval('1+1'));
99

packages/ses/test/evalTaming-safeEval.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import test from 'ava';
22
import '../index.js';
33

4-
lockdown({ evalTaming: 'safeEval' });
4+
lockdown({ evalTaming: 'safe-eval' });
55

6-
test('safe eval when evalTaming is safeEval.', t => {
6+
test('safe eval when evalTaming is safe-eval.', t => {
77
// eslint-disable-next-line no-unused-vars
88
const a = 0;
99
// eslint-disable-next-line no-eval

packages/ses/test/evalTaming-unsafe.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import test from 'ava';
22
import '../index.js';
33

4-
lockdown({ evalTaming: 'unsafeEval' });
4+
lockdown({ evalTaming: 'unsafe-eval' });
55

6-
test('direct eval is possible when evalTaming is unsafe.', t => {
6+
test('direct eval is possible when evalTaming is unsafe-eval.', t => {
77
// eslint-disable-next-line no-unused-vars
88
const a = 0;
99
// eslint-disable-next-line no-eval

packages/ses/types.d.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,14 @@ export interface RepairOptions {
3535
* @deprecated Deprecated and does nothing. In the future specifying it will be an error.
3636
*/
3737
mathTaming?: 'safe' | 'unsafe';
38-
evalTaming?: 'safeEval' | 'unsafeEval' | 'noEval';
38+
evalTaming?:
39+
| 'safe-eval'
40+
| 'unsafe-eval'
41+
| 'no-eval'
42+
// deprecated
43+
| 'safeEval'
44+
| 'unsafeEval'
45+
| 'noEval';
3946
stackFiltering?: 'concise' | 'verbose';
4047
overrideTaming?: 'moderate' | 'min' | 'severe';
4148
overrideDebug?: Array<string>;

0 commit comments

Comments
 (0)