-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ses): Hermes eval and compartment taming
- Loading branch information
Showing
6 changed files
with
104 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
import { TypeError } from './commons.js'; | ||
|
||
/** | ||
* makeEvalFunction() | ||
* A safe version of the native eval function which relies on | ||
* the safety of safeEvaluate for confinement. | ||
* the safety of safeEvaluate for confinement, unless noEval | ||
* is specified (then a TypeError is thrown). | ||
* | ||
* @param {Function} safeEvaluate | ||
* @param {Function} evaluator | ||
* @param legacyHermesTaming | ||
Check warning on line 10 in packages/ses/src/make-eval-function.js
|
||
*/ | ||
export const makeEvalFunction = safeEvaluate => { | ||
export const makeEvalFunction = (evaluator, legacyHermesTaming) => { | ||
// We use the concise method syntax to create an eval without a | ||
// [[Construct]] behavior (such that the invocation "new eval()" throws | ||
// TypeError: eval is not a constructor"), but which still accepts a | ||
|
@@ -19,7 +23,30 @@ export const makeEvalFunction = safeEvaluate => { | |
// rule. Track. | ||
return source; | ||
} | ||
return safeEvaluate(source); | ||
if (legacyHermesTaming === 'unsafe') { | ||
throw TypeError( | ||
`Legacy Hermes unsupported eval() with strings arguments cannot be tamed safe under legacyHermesTaming ${legacyHermesTaming} | ||
See: https://github.com/facebook/hermes/issues/1056 | ||
See: https://github.com/endojs/endo/issues/1561 | ||
Did you mean evalTaming: 'unsafeEval'?`, | ||
); | ||
} | ||
// refactoring to try/catch... | ||
// - error output still 'Uncaught' | ||
// - SES_NO_EVAL no longer encountered first | ||
// try { | ||
// safeEvaluate(source); | ||
// } catch (e) { | ||
// // throw Error(e); // Uncaught Error: SyntaxError: 2:5:invalid statement encountered. | ||
// throw TypeError( | ||
// `legacy Hermes unsupported eval() with strings arguments cannot be tamed safe under legacyHermesTaming ${legacyHermesTaming} | ||
// see: https://github.com/facebook/hermes/issues/1056 | ||
// see: https://github.com/endojs/endo/issues/1561 | ||
// did you mean evalTaming: 'unsafeEval'?`, | ||
// ); | ||
// } | ||
// Disabling safeEvaluate is not enough, since returning the source string is not evaluating it. | ||
return evaluator(source); | ||
}, | ||
}.eval; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters