Skip to content

Commit 39a0d03

Browse files
authored
Merge pull request #237 from 80avin/fix-10.2.0-rce
fix(eval): rce using non-string prop names
2 parents 8e4acf8 + 3094289 commit 39a0d03

27 files changed

+166
-87
lines changed

badges/tests-badge.svg

Lines changed: 1 addition & 1 deletion
Loading

dist/index-browser-esm.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,8 +1297,13 @@ const SafeEval = {
12971297
return ast.value;
12981298
},
12991299
evalMemberExpression(ast, subs) {
1300-
const prop = ast.computed ? SafeEval.evalAst(ast.property) // `object[property]`
1301-
: ast.property.name; // `object.property` property is Identifier
1300+
const prop = String(
1301+
// NOTE: `String(value)` throws error when
1302+
// value has overwritten the toString method to return non-string
1303+
// i.e. `value = {toString: () => []}`
1304+
ast.computed ? SafeEval.evalAst(ast.property) // `object[property]`
1305+
: ast.property.name // `object.property` property is Identifier
1306+
);
13021307
const obj = SafeEval.evalAst(ast.object, subs);
13031308
if (obj === undefined || obj === null) {
13041309
throw TypeError(`Cannot read properties of ${obj} (reading '${prop}')`);

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: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,8 +1303,13 @@
13031303
return ast.value;
13041304
},
13051305
evalMemberExpression(ast, subs) {
1306-
const prop = ast.computed ? SafeEval.evalAst(ast.property) // `object[property]`
1307-
: ast.property.name; // `object.property` property is Identifier
1306+
const prop = String(
1307+
// NOTE: `String(value)` throws error when
1308+
// value has overwritten the toString method to return non-string
1309+
// i.e. `value = {toString: () => []}`
1310+
ast.computed ? SafeEval.evalAst(ast.property) // `object[property]`
1311+
: ast.property.name // `object.property` property is Identifier
1312+
);
13081313
const obj = SafeEval.evalAst(ast.object, subs);
13091314
if (obj === undefined || obj === null) {
13101315
throw TypeError(`Cannot read properties of ${obj} (reading '${prop}')`);

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: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,8 +1298,13 @@ const SafeEval = {
12981298
return ast.value;
12991299
},
13001300
evalMemberExpression(ast, subs) {
1301-
const prop = ast.computed ? SafeEval.evalAst(ast.property) // `object[property]`
1302-
: ast.property.name; // `object.property` property is Identifier
1301+
const prop = String(
1302+
// NOTE: `String(value)` throws error when
1303+
// value has overwritten the toString method to return non-string
1304+
// i.e. `value = {toString: () => []}`
1305+
ast.computed ? SafeEval.evalAst(ast.property) // `object[property]`
1306+
: ast.property.name // `object.property` property is Identifier
1307+
);
13031308
const obj = SafeEval.evalAst(ast.object, subs);
13041309
if (obj === undefined || obj === null) {
13051310
throw TypeError(`Cannot read properties of ${obj} (reading '${prop}')`);

dist/index-node-esm.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,8 +1296,13 @@ const SafeEval = {
12961296
return ast.value;
12971297
},
12981298
evalMemberExpression(ast, subs) {
1299-
const prop = ast.computed ? SafeEval.evalAst(ast.property) // `object[property]`
1300-
: ast.property.name; // `object.property` property is Identifier
1299+
const prop = String(
1300+
// NOTE: `String(value)` throws error when
1301+
// value has overwritten the toString method to return non-string
1302+
// i.e. `value = {toString: () => []}`
1303+
ast.computed ? SafeEval.evalAst(ast.property) // `object[property]`
1304+
: ast.property.name // `object.property` property is Identifier
1305+
);
13011306
const obj = SafeEval.evalAst(ast.object, subs);
13021307
if (obj === undefined || obj === null) {
13031308
throw TypeError(`Cannot read properties of ${obj} (reading '${prop}')`);

docs/ts/assets/icons.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.

0 commit comments

Comments
 (0)