Skip to content

Commit 5a22e3f

Browse files
committed
fix(security): prevent Function calls outside of member expressions
1 parent 0bf1665 commit 5a22e3f

9 files changed

+24
-9
lines changed

dist/index-browser-esm.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1297,7 +1297,7 @@ const SafeEval = {
12971297
const result = obj[prop];
12981298
if (typeof result === 'function') {
12991299
if (result === Function) {
1300-
throw new Error('Function constructor is disabled');
1300+
return result; // Don't bind so can identify and throw later
13011301
}
13021302
return result.bind(obj); // arrow functions aren't affected by bind.
13031303
}
@@ -1319,6 +1319,9 @@ const SafeEval = {
13191319
evalCallExpression(ast, subs) {
13201320
const args = ast.arguments.map(arg => SafeEval.evalAst(arg, subs));
13211321
const func = SafeEval.evalAst(ast.callee, subs);
1322+
if (func === Function) {
1323+
throw new Error('Function constructor is disabled');
1324+
}
13221325
return func(...args);
13231326
},
13241327
evalAssignmentExpression(ast, subs) {

dist/index-browser-esm.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index-browser-esm.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index-browser-umd.cjs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1303,7 +1303,7 @@
13031303
const result = obj[prop];
13041304
if (typeof result === 'function') {
13051305
if (result === Function) {
1306-
throw new Error('Function constructor is disabled');
1306+
return result; // Don't bind so can identify and throw later
13071307
}
13081308
return result.bind(obj); // arrow functions aren't affected by bind.
13091309
}
@@ -1325,6 +1325,9 @@
13251325
evalCallExpression(ast, subs) {
13261326
const args = ast.arguments.map(arg => SafeEval.evalAst(arg, subs));
13271327
const func = SafeEval.evalAst(ast.callee, subs);
1328+
if (func === Function) {
1329+
throw new Error('Function constructor is disabled');
1330+
}
13281331
return func(...args);
13291332
},
13301333
evalAssignmentExpression(ast, subs) {

dist/index-browser-umd.min.cjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

dist/index-browser-umd.min.cjs.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index-node-cjs.cjs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1298,7 +1298,7 @@ const SafeEval = {
12981298
const result = obj[prop];
12991299
if (typeof result === 'function') {
13001300
if (result === Function) {
1301-
throw new Error('Function constructor is disabled');
1301+
return result; // Don't bind so can identify and throw later
13021302
}
13031303
return result.bind(obj); // arrow functions aren't affected by bind.
13041304
}
@@ -1320,6 +1320,9 @@ const SafeEval = {
13201320
evalCallExpression(ast, subs) {
13211321
const args = ast.arguments.map(arg => SafeEval.evalAst(arg, subs));
13221322
const func = SafeEval.evalAst(ast.callee, subs);
1323+
if (func === Function) {
1324+
throw new Error('Function constructor is disabled');
1325+
}
13231326
return func(...args);
13241327
},
13251328
evalAssignmentExpression(ast, subs) {

dist/index-node-esm.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1296,7 +1296,7 @@ const SafeEval = {
12961296
const result = obj[prop];
12971297
if (typeof result === 'function') {
12981298
if (result === Function) {
1299-
throw new Error('Function constructor is disabled');
1299+
return result; // Don't bind so can identify and throw later
13001300
}
13011301
return result.bind(obj); // arrow functions aren't affected by bind.
13021302
}
@@ -1318,6 +1318,9 @@ const SafeEval = {
13181318
evalCallExpression(ast, subs) {
13191319
const args = ast.arguments.map(arg => SafeEval.evalAst(arg, subs));
13201320
const func = SafeEval.evalAst(ast.callee, subs);
1321+
if (func === Function) {
1322+
throw new Error('Function constructor is disabled');
1323+
}
13211324
return func(...args);
13221325
},
13231326
evalAssignmentExpression(ast, subs) {

src/Safe-Script.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ const SafeEval = {
112112
const result = obj[prop];
113113
if (typeof result === 'function') {
114114
if (result === Function) {
115-
throw new Error('Function constructor is disabled');
115+
return result; // Don't bind so can identify and throw later
116116
}
117117
return result.bind(obj); // arrow functions aren't affected by bind.
118118
}
@@ -134,6 +134,9 @@ const SafeEval = {
134134
evalCallExpression (ast, subs) {
135135
const args = ast.arguments.map((arg) => SafeEval.evalAst(arg, subs));
136136
const func = SafeEval.evalAst(ast.callee, subs);
137+
if (func === Function) {
138+
throw new Error('Function constructor is disabled');
139+
}
137140
return func(...args);
138141
},
139142
evalAssignmentExpression (ast, subs) {

0 commit comments

Comments
 (0)