Skip to content

Commit 0bf1665

Browse files
committed
fix(security): prohibit Function in "safe" vm; fixes #226
1 parent a04dcba commit 0bf1665

11 files changed

+24
-5
lines changed

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGES for jsonpath-plus
22

3+
## 10.0.1
4+
5+
- fix(security): prohibit `Function` in "safe" vm
6+
37
## 10.0.0
48

59
BREAKING CHANGES:

dist/index-browser-esm.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,6 +1296,9 @@ const SafeEval = {
12961296
const obj = SafeEval.evalAst(ast.object, subs);
12971297
const result = obj[prop];
12981298
if (typeof result === 'function') {
1299+
if (result === Function) {
1300+
throw new Error('Function constructor is disabled');
1301+
}
12991302
return result.bind(obj); // arrow functions aren't affected by bind.
13001303
}
13011304
return result;

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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,6 +1302,9 @@
13021302
const obj = SafeEval.evalAst(ast.object, subs);
13031303
const result = obj[prop];
13041304
if (typeof result === 'function') {
1305+
if (result === Function) {
1306+
throw new Error('Function constructor is disabled');
1307+
}
13051308
return result.bind(obj); // arrow functions aren't affected by bind.
13061309
}
13071310
return result;

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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,6 +1297,9 @@ const SafeEval = {
12971297
const obj = SafeEval.evalAst(ast.object, subs);
12981298
const result = obj[prop];
12991299
if (typeof result === 'function') {
1300+
if (result === Function) {
1301+
throw new Error('Function constructor is disabled');
1302+
}
13001303
return result.bind(obj); // arrow functions aren't affected by bind.
13011304
}
13021305
return result;

dist/index-node-esm.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,6 +1295,9 @@ const SafeEval = {
12951295
const obj = SafeEval.evalAst(ast.object, subs);
12961296
const result = obj[prop];
12971297
if (typeof result === 'function') {
1298+
if (result === Function) {
1299+
throw new Error('Function constructor is disabled');
1300+
}
12981301
return result.bind(obj); // arrow functions aren't affected by bind.
12991302
}
13001303
return result;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"author": "Stefan Goessner",
33
"name": "jsonpath-plus",
4-
"version": "10.0.0",
4+
"version": "10.0.1",
55
"type": "module",
66
"bin": {
77
"jsonpath": "./bin/jsonpath-cli.js",

src/Safe-Script.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ const SafeEval = {
111111
const obj = SafeEval.evalAst(ast.object, subs);
112112
const result = obj[prop];
113113
if (typeof result === 'function') {
114+
if (result === Function) {
115+
throw new Error('Function constructor is disabled');
116+
}
114117
return result.bind(obj); // arrow functions aren't affected by bind.
115118
}
116119
return result;

0 commit comments

Comments
 (0)