Skip to content

Commit

Permalink
The operations object could be exploited to run arbitrary code (#98)
Browse files Browse the repository at this point in the history
* The operations object could be exploited to run arbitrary code

* Version bump

Co-authored-by: Jeremy Wadhams <[email protected]>
  • Loading branch information
jwadhams and jwadhams authored Mar 30, 2021
1 parent 17e9fed commit c1dd82f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,18 +340,19 @@ http://ricostacruz.com/cheatsheets/umdjs.html
// The operation is called with "data" bound to its "this" and "values" passed as arguments.
// Structured commands like % or > can name formal arguments while flexible commands (like missing or merge) can operate on the pseudo-array arguments
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments
if (typeof operations[op] === "function") {
if (operations.hasOwnProperty(op) && typeof operations[op] === "function") {
return operations[op].apply(data, values);
} else if (op.indexOf(".") > 0) { // Contains a dot, and not in the 0th position
var sub_ops = String(op).split(".");
var operation = operations;
for (i = 0; i < sub_ops.length; i++) {
// Descending into operations
operation = operation[sub_ops[i]];
if (operation === undefined) {

if (!operation.hasOwnProperty(sub_ops[i])) {
throw new Error("Unrecognized operation " + op +
" (failed at " + sub_ops.slice(0, i+1).join(".") + ")");
}
// Descending into operations
operation = operation[sub_ops[i]];
}

return operation.apply(data, values);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "json-logic-js",
"version": "2.0.0",
"version": "2.0.1",
"description": "Build complex rules, serialize them as JSON, and execute them in JavaScript",
"main": "logic.js",
"directories": {
Expand Down

0 comments on commit c1dd82f

Please sign in to comment.