Skip to content

Commit c1dd82f

Browse files
authored
The operations object could be exploited to run arbitrary code (#98)
* The operations object could be exploited to run arbitrary code * Version bump Co-authored-by: Jeremy Wadhams <[email protected]>
1 parent 17e9fed commit c1dd82f

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

Diff for: logic.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -340,18 +340,19 @@ http://ricostacruz.com/cheatsheets/umdjs.html
340340
// The operation is called with "data" bound to its "this" and "values" passed as arguments.
341341
// Structured commands like % or > can name formal arguments while flexible commands (like missing or merge) can operate on the pseudo-array arguments
342342
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments
343-
if (typeof operations[op] === "function") {
343+
if (operations.hasOwnProperty(op) && typeof operations[op] === "function") {
344344
return operations[op].apply(data, values);
345345
} else if (op.indexOf(".") > 0) { // Contains a dot, and not in the 0th position
346346
var sub_ops = String(op).split(".");
347347
var operation = operations;
348348
for (i = 0; i < sub_ops.length; i++) {
349-
// Descending into operations
350-
operation = operation[sub_ops[i]];
351-
if (operation === undefined) {
349+
350+
if (!operation.hasOwnProperty(sub_ops[i])) {
352351
throw new Error("Unrecognized operation " + op +
353352
" (failed at " + sub_ops.slice(0, i+1).join(".") + ")");
354353
}
354+
// Descending into operations
355+
operation = operation[sub_ops[i]];
355356
}
356357

357358
return operation.apply(data, values);

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "json-logic-js",
3-
"version": "2.0.0",
3+
"version": "2.0.1",
44
"description": "Build complex rules, serialize them as JSON, and execute them in JavaScript",
55
"main": "logic.js",
66
"directories": {

0 commit comments

Comments
 (0)