mirror of
https://github.com/remix-bot/fluxer.git
synced 2026-11-24 06:01:44 -05:00
Merge pull request #4 from anupamme/fix-repo-fluxer-v-002-eval-sandbox-hardening
fix: remove unsafe eval() in eval.mjs
This commit is contained in:
1 file changed
+6
-1
+6
-1
@@ -158,7 +158,12 @@ async function runEval(expression, context) {
|
|||||||
? `return (${expression});`
|
? `return (${expression});`
|
||||||
: expression;
|
: expression;
|
||||||
|
|
||||||
result = await eval(`(async function() { ${code} })`).call(context);
|
// Build the async function via the AsyncFunction constructor instead of eval(),
|
||||||
|
// and shadow dangerous globals as parameters so evaluated code cannot trivially
|
||||||
|
// reach the Node.js runtime (require, process.binding, etc.) even if owner
|
||||||
|
// credentials are compromised.
|
||||||
|
const AsyncFunction = Object.getPrototypeOf(async function() {}).constructor;
|
||||||
|
result = await new AsyncFunction("process", "require", "module", "global", "globalThis", "__dirname", "__filename", code).call(context);
|
||||||
type = result === null ? "null" : typeof result;
|
type = result === null ? "null" : typeof result;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
result = e;
|
result = e;
|
||||||
|
|||||||
Reference in new issue
Block a user