Skip to content

Commit

Permalink
fix(security): prevent constructor access in safe vm
Browse files Browse the repository at this point in the history
Also:
- docs: add security policy file
  • Loading branch information
brettz9 committed Oct 18, 2024
1 parent 763ada0 commit b70aa71
Show file tree
Hide file tree
Showing 14 changed files with 54 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ labels: Bug - unconfirmed
---
<!--
**PLEASE NOTE: This project is not currently being very actively developed.**
**ALSO: If wishing to report a security bug, please read SECURITY.md**
-->

## Describe the bug
Expand Down
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# CHANGES for jsonpath-plus

## 10.0.7

- fix(security): prevent `constructor` access
- docs: add security policy file

## 10.0.6

- fix(security): prevent `call`/`apply` invocation of `Function`
Expand Down
20 changes: 20 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Security Policy

## Reporting a Vulnerability

**Please do not report security vulnerabilities through public GitHub issues.**

If you believe you’ve found a security vulnerability, please send it to us by emailing [brettz9@yahoo.com](mailto:brettz9@yahoo.com). Please include the following details with your report:

1. Description of the location and potential impact of the vulnerability

2. A detailed description of the steps required to reproduce the vulnerability (POC scripts, etc.).

3. How you would like to be credited.

We will evaluate the vulnerability and, if necessary, release a fix or unertake mitigating steps to address it. We will contact you to let you know the outcome, and will credit you in the report.

Please **do not disclose the vulnerability publicly** until we have sufficient time to release a fix.

Once we have either a) published a fix, b) declined to address the vulnerability for whatever reason, or c) taken more than 30 days to reply, we welcome you to publicly report the vulnerability on our tracker and disclose it publicly. If you intend to
disclose sooner regardless of our requested policy, please at least indicate to us when you plan to disclose.
2 changes: 1 addition & 1 deletion badges/coverage-badge.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions dist/index-browser-esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -1291,6 +1291,9 @@ const SafeEval = {
return ast.value;
},
evalMemberExpression(ast, subs) {
if (ast.property.type === 'Identifier' && ast.property.name === 'constructor' || ast.object.type === 'Identifier' && ast.object.name === 'constructor') {
throw new Error("'constructor' property is disabled");
}
const prop = ast.computed ? SafeEval.evalAst(ast.property) // `object[property]`
: ast.property.name; // `object.property` property is Identifier
const obj = SafeEval.evalAst(ast.object, subs);
Expand Down
2 changes: 1 addition & 1 deletion dist/index-browser-esm.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index-browser-esm.min.js.map

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions dist/index-browser-umd.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -1297,6 +1297,9 @@
return ast.value;
},
evalMemberExpression(ast, subs) {
if (ast.property.type === 'Identifier' && ast.property.name === 'constructor' || ast.object.type === 'Identifier' && ast.object.name === 'constructor') {
throw new Error("'constructor' property is disabled");
}
const prop = ast.computed ? SafeEval.evalAst(ast.property) // `object[property]`
: ast.property.name; // `object.property` property is Identifier
const obj = SafeEval.evalAst(ast.object, subs);
Expand Down
2 changes: 1 addition & 1 deletion dist/index-browser-umd.min.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index-browser-umd.min.cjs.map

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions dist/index-node-cjs.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -1292,6 +1292,9 @@ const SafeEval = {
return ast.value;
},
evalMemberExpression(ast, subs) {
if (ast.property.type === 'Identifier' && ast.property.name === 'constructor' || ast.object.type === 'Identifier' && ast.object.name === 'constructor') {
throw new Error("'constructor' property is disabled");
}
const prop = ast.computed ? SafeEval.evalAst(ast.property) // `object[property]`
: ast.property.name; // `object.property` property is Identifier
const obj = SafeEval.evalAst(ast.object, subs);
Expand Down
3 changes: 3 additions & 0 deletions dist/index-node-esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -1290,6 +1290,9 @@ const SafeEval = {
return ast.value;
},
evalMemberExpression(ast, subs) {
if (ast.property.type === 'Identifier' && ast.property.name === 'constructor' || ast.object.type === 'Identifier' && ast.object.name === 'constructor') {
throw new Error("'constructor' property is disabled");
}
const prop = ast.computed ? SafeEval.evalAst(ast.property) // `object[property]`
: ast.property.name; // `object.property` property is Identifier
const obj = SafeEval.evalAst(ast.object, subs);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"author": "Stefan Goessner",
"name": "jsonpath-plus",
"version": "10.0.6",
"version": "10.0.7",
"type": "module",
"bin": {
"jsonpath": "./bin/jsonpath-cli.js",
Expand Down
9 changes: 9 additions & 0 deletions src/Safe-Script.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,15 @@ const SafeEval = {
return ast.value;
},
evalMemberExpression (ast, subs) {
if (
(ast.property.type === 'Identifier' &&
ast.property.name === 'constructor') ||
(ast.object.type === 'Identifier' &&
ast.object.name === 'constructor')
) {
throw new Error("'constructor' property is disabled");
}

const prop = ast.computed
? SafeEval.evalAst(ast.property) // `object[property]`
: ast.property.name; // `object.property` property is Identifier
Expand Down

0 comments on commit b70aa71

Please sign in to comment.