Skip to content

Commit

Permalink
refactor(ses): hostEvaluators assertions to failures
Browse files Browse the repository at this point in the history
  • Loading branch information
leotm committed Mar 6, 2025
1 parent 4651175 commit 8f0c31a
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions packages/ses/src/lockdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,22 +279,16 @@ export const repairIntrinsics = (options = {}) => {
const noEvaluators = !evalAllowed && !functionAllowed; // eval() itself and the Function() constructor are not allowed to execute.

hostEvaluators === 'all' &&
assert(
!noEvaluators,
"'hostEvaluators' was set to 'all', but the Function() constructor and eval() are not allowed to execute (SES_DIRECT_EVAL)",
);
noEvaluators &&
Fail`'hostEvaluators' was set to 'all', but the Function() constructor and eval() are not allowed to execute (SES_DIRECT_EVAL)`;

hostEvaluators === 'none' &&
assert(
noEvaluators,
"'hostEvaluators' was set to 'none', but the Function() constructor and eval() are allowed to execute (SES_DIRECT_EVAL)",
);
!noEvaluators &&
Fail`'hostEvaluators' was set to 'none', but the Function() constructor and eval() are allowed to execute (SES_DIRECT_EVAL)`;

hostEvaluators === 'no-direct' &&
assert(
!directEvalAllowed,
`'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)`,
);
directEvalAllowed &&
Fail`'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)`;

// TODO: Remove '_legacy' when 'all' introduced as the new default option (breaking change).
// For backwards compatibility under '_legacy', we do not error with a strict CSP, since directEvalAllowed remains undefined.
Expand Down

0 comments on commit 8f0c31a

Please sign in to comment.