Skip to content

Commit 7db5a99

Browse files
authored
Merge pull request #4919 from erik-krogh/revertSum
Approved by esbena
2 parents 6cbff13 + bfd8d1b commit 7db5a99

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

javascript/ql/src/semmle/javascript/security/dataflow/UnsafeShellCommandConstruction.qll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,15 @@ module UnsafeShellCommandConstruction {
4141
mid.getPathSummary().hasReturn() = false
4242
)
4343
}
44+
45+
override predicate isAdditionalTaintStep(DataFlow::Node pred, DataFlow::Node succ) {
46+
// flow-step from a property written in the constructor to a use in an instance method.
47+
// "simulates" client usage of a class, and regains some flow-steps lost by `hasFlowPath` above.
48+
exists(DataFlow::ClassNode clz, string name |
49+
pred =
50+
DataFlow::thisNode(clz.getConstructor().getFunction()).getAPropertyWrite(name).getRhs() and
51+
succ = DataFlow::thisNode(clz.getInstanceMethod(_).getFunction()).getAPropertyRead(name)
52+
)
53+
}
4454
}
4555
}

javascript/ql/test/query-tests/Security/CWE-078/UnsafeShellCommandConstruction.expected

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,12 @@ nodes
195195
| lib/lib.js:349:29:349:34 | unsafe |
196196
| lib/lib.js:351:22:351:27 | unsafe |
197197
| lib/lib.js:351:22:351:27 | unsafe |
198+
| lib/lib.js:360:20:360:23 | opts |
199+
| lib/lib.js:360:20:360:23 | opts |
200+
| lib/lib.js:361:20:361:23 | opts |
201+
| lib/lib.js:361:20:361:34 | opts.learn_args |
202+
| lib/lib.js:366:28:366:42 | this.learn_args |
203+
| lib/lib.js:366:28:366:42 | this.learn_args |
198204
edges
199205
| lib/lib2.js:3:28:3:31 | name | lib/lib2.js:4:22:4:25 | name |
200206
| lib/lib2.js:3:28:3:31 | name | lib/lib2.js:4:22:4:25 | name |
@@ -425,6 +431,11 @@ edges
425431
| lib/lib.js:349:29:349:34 | unsafe | lib/lib.js:351:22:351:27 | unsafe |
426432
| lib/lib.js:349:29:349:34 | unsafe | lib/lib.js:351:22:351:27 | unsafe |
427433
| lib/lib.js:349:29:349:34 | unsafe | lib/lib.js:351:22:351:27 | unsafe |
434+
| lib/lib.js:360:20:360:23 | opts | lib/lib.js:361:20:361:23 | opts |
435+
| lib/lib.js:360:20:360:23 | opts | lib/lib.js:361:20:361:23 | opts |
436+
| lib/lib.js:361:20:361:23 | opts | lib/lib.js:361:20:361:34 | opts.learn_args |
437+
| lib/lib.js:361:20:361:34 | opts.learn_args | lib/lib.js:366:28:366:42 | this.learn_args |
438+
| lib/lib.js:361:20:361:34 | opts.learn_args | lib/lib.js:366:28:366:42 | this.learn_args |
428439
#select
429440
| lib/lib2.js:4:10:4:25 | "rm -rf " + name | lib/lib2.js:3:28:3:31 | name | lib/lib2.js:4:22:4:25 | name | $@ based on library input is later used in $@. | lib/lib2.js:4:10:4:25 | "rm -rf " + name | String concatenation | lib/lib2.js:4:2:4:26 | cp.exec ... + name) | shell command |
430441
| lib/lib2.js:8:10:8:25 | "rm -rf " + name | lib/lib2.js:7:32:7:35 | name | lib/lib2.js:8:22:8:25 | name | $@ based on library input is later used in $@. | lib/lib2.js:8:10:8:25 | "rm -rf " + name | String concatenation | lib/lib2.js:8:2:8:26 | cp.exec ... + name) | shell command |
@@ -481,3 +492,4 @@ edges
481492
| lib/lib.js:325:12:325:51 | "MyWind ... " + arg | lib/lib.js:324:40:324:42 | arg | lib/lib.js:325:49:325:51 | arg | $@ based on library input is later used in $@. | lib/lib.js:325:12:325:51 | "MyWind ... " + arg | String concatenation | lib/lib.js:326:2:326:13 | cp.exec(cmd) | shell command |
482493
| lib/lib.js:340:10:340:26 | "rm -rf " + id(n) | lib/lib.js:339:39:339:39 | n | lib/lib.js:340:22:340:26 | id(n) | $@ based on library input is later used in $@. | lib/lib.js:340:10:340:26 | "rm -rf " + id(n) | String concatenation | lib/lib.js:340:2:340:27 | cp.exec ... id(n)) | shell command |
483494
| lib/lib.js:351:10:351:27 | "rm -rf " + unsafe | lib/lib.js:349:29:349:34 | unsafe | lib/lib.js:351:22:351:27 | unsafe | $@ based on library input is later used in $@. | lib/lib.js:351:10:351:27 | "rm -rf " + unsafe | String concatenation | lib/lib.js:351:2:351:28 | cp.exec ... unsafe) | shell command |
495+
| lib/lib.js:366:17:366:56 | "learn ... + model | lib/lib.js:360:20:360:23 | opts | lib/lib.js:366:28:366:42 | this.learn_args | $@ based on library input is later used in $@. | lib/lib.js:366:17:366:56 | "learn ... + model | String concatenation | lib/lib.js:367:3:367:18 | cp.exec(command) | shell command |

javascript/ql/test/query-tests/Security/CWE-078/lib/lib.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,3 +356,15 @@ Object.defineProperty(module.exports, "boundProblem", {
356356
return boundProblem.bind(this, "safe");
357357
}
358358
});
359+
360+
function MyTrainer(opts) {
361+
this.learn_args = opts.learn_args
362+
}
363+
364+
MyTrainer.prototype = {
365+
train: function() {
366+
var command = "learn " + this.learn_args + " " + model; // NOT OK
367+
cp.exec(command);
368+
}
369+
};
370+
module.exports.MyTrainer = MyTrainer;

0 commit comments

Comments
 (0)