-
Notifications
You must be signed in to change notification settings - Fork 80
feat(ses): update lockdown init and enable Hermes VM #2723
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
Changes from all commits
c1f38ca
8f97389
db5fd4e
ced6965
77fd7b4
093bdcb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
leotm marked this conversation as resolved.
Show resolved
Hide resolved
|
leotm marked this conversation as resolved.
Show resolved
Hide resolved
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -100,10 +100,32 @@ const safeHarden = makeHardener(); | |
| // only ever need to be called once and that simplifying lockdown will improve | ||
| // the quality of audits. | ||
|
|
||
| const assertDirectEvalAvailable = () => { | ||
leotm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| let allowed = false; | ||
| const probeHostEvaluators = () => { | ||
| let functionAllowed; | ||
| try { | ||
| allowed = FERAL_FUNCTION( | ||
| functionAllowed = FERAL_FUNCTION('return true')(); | ||
| } catch (_error) { | ||
| // We reach here if the Function() constructor is outright forbidden by a | ||
| // strict Content Security Policy (containing either a `default-src` or a | ||
| // `script-src` directive), not been implemented in the host, or the host | ||
| // is configured to throw an exception instead of `new Function`. | ||
|
Comment on lines
+108
to
+111
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is where we check what the capabilities of the host are. If the above is not correct, we have to look into running this earlier or changing the logic of asserting on the results of |
||
| functionAllowed = false; | ||
| } | ||
|
|
||
| let evalAllowed; | ||
| try { | ||
| evalAllowed = FERAL_EVAL('true'); | ||
| } catch (_error) { | ||
| // We reach here if `eval` is outright forbidden by a strict Content Security Policy, | ||
| // not implemented in the host, or the host is configured to throw an exception. | ||
| // We allow this for SES usage that delegates the responsibility to isolate | ||
| // guest code to production code generation. | ||
| evalAllowed = false; | ||
| } | ||
|
|
||
| let directEvalAllowed; | ||
| if (functionAllowed && evalAllowed) { | ||
| directEvalAllowed = FERAL_FUNCTION( | ||
| 'eval', | ||
| 'SES_changed', | ||
| `\ | ||
|
|
@@ -115,21 +137,12 @@ const assertDirectEvalAvailable = () => { | |
| // and indirect, which generally creates a new global. | ||
| // We are going to throw an exception for failing to initialize SES, but | ||
| // good neighbors clean up. | ||
| if (!allowed) { | ||
| if (!directEvalAllowed) { | ||
| delete globalThis.SES_changed; | ||
leotm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } catch (_error) { | ||
| // We reach here if eval is outright forbidden by a Content Security Policy. | ||
| // We allow this for SES usage that delegates the responsibility to isolate | ||
| // guest code to production code generation. | ||
| allowed = true; | ||
| } | ||
| if (!allowed) { | ||
| // See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_DIRECT_EVAL.md | ||
leotm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| throw TypeError( | ||
| `SES cannot initialize unless 'eval' is the original intrinsic 'eval', suitable for direct-eval (dynamically scoped eval) (SES_DIRECT_EVAL)`, | ||
| ); | ||
| } | ||
|
|
||
| return { functionAllowed, evalAllowed, directEvalAllowed }; | ||
| }; | ||
|
|
||
| /** | ||
|
|
@@ -152,11 +165,11 @@ export const repairIntrinsics = (options = {}) => { | |
| // The `stackFiltering` is not a safety issue. Rather it is a tradeoff | ||
| // between relevance and completeness of the stack frames shown on the | ||
| // console. Setting`stackFiltering` to `'verbose'` applies no filters, providing | ||
| // the raw stack frames that can be quite versbose. Setting | ||
| // the raw stack frames that can be quite verbose. Setting | ||
| // `stackFrameFiltering` to`'concise'` limits the display to the stack frame | ||
| // information most likely to be relevant, eliminating distracting frames | ||
| // such as those from the infrastructure. However, the bug you're trying to | ||
| // track down might be in the infrastrure, in which case the `'verbose'` setting | ||
| // track down might be in the infrastructure, in which case the `'verbose'` setting | ||
| // is useful. See | ||
| // [`stackFiltering` options](https://github.com/Agoric/SES-shim/blob/master/packages/ses/docs/lockdown.md#stackfiltering-options) | ||
| // for an explanation. | ||
|
|
@@ -221,13 +234,11 @@ export const repairIntrinsics = (options = {}) => { | |
| const { warn } = reporter; | ||
|
|
||
| if (dateTaming !== undefined) { | ||
| // eslint-disable-next-line no-console | ||
| warn( | ||
| `SES The 'dateTaming' option is deprecated and does nothing. In the future specifying it will be an error.`, | ||
| ); | ||
| } | ||
| if (mathTaming !== undefined) { | ||
| // eslint-disable-next-line no-console | ||
| warn( | ||
| `SES The 'mathTaming' option is deprecated and does nothing. In the future specifying it will be an error.`, | ||
| ); | ||
|
|
@@ -245,7 +256,19 @@ export const repairIntrinsics = (options = {}) => { | |
| // trace retained: | ||
| priorRepairIntrinsics.stack; | ||
|
|
||
| assertDirectEvalAvailable(); | ||
| const { functionAllowed, evalAllowed, directEvalAllowed } = | ||
| probeHostEvaluators(); | ||
|
|
||
| if ( | ||
| directEvalAllowed === false && | ||
| evalTaming === 'safe-eval' && | ||
| (functionAllowed || evalAllowed) | ||
| ) { | ||
| // See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_DIRECT_EVAL.md | ||
| throw TypeError( | ||
| "SES cannot initialize unless 'eval' is the original intrinsic 'eval', suitable for direct eval (dynamically scoped eval) (SES_DIRECT_EVAL)", | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Because of packagers and bundlers, etc, multiple invocations of lockdown | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.