Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d446444

Browse files
committed
JS: Port ShellCommandInjectionFromEnvironment
1 parent 06835a8 commit d446444

3 files changed

Lines changed: 42 additions & 28 deletions

File tree

javascript/ql/lib/semmle/javascript/security/dataflow/ShellCommandInjectionFromEnvironmentQuery.qll

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,31 @@ import IndirectCommandArgument
1414
/**
1515
* A taint-tracking configuration for reasoning about command-injection vulnerabilities.
1616
*/
17-
class Configuration extends TaintTracking::Configuration {
17+
module ShellCommandInjectionFromEnvironmentConfig implements DataFlow::ConfigSig {
18+
predicate isSource(DataFlow::Node source) { source instanceof Source }
19+
20+
/** Holds if `sink` is a command-injection sink with `highlight` as the corresponding alert location. */
21+
additional predicate isSinkWithHighlight(DataFlow::Node sink, DataFlow::Node highlight) {
22+
sink instanceof Sink and highlight = sink
23+
or
24+
isIndirectCommandArgument(sink, highlight)
25+
}
26+
27+
predicate isSink(DataFlow::Node sink) { isSinkWithHighlight(sink, _) }
28+
29+
predicate isBarrier(DataFlow::Node node) { node instanceof Sanitizer }
30+
}
31+
32+
/**
33+
* Taint-tracking for reasoning about command-injection vulnerabilities.
34+
*/
35+
module ShellCommandInjectionFromEnvironmentFlow =
36+
TaintTracking::Global<ShellCommandInjectionFromEnvironmentConfig>;
37+
38+
/**
39+
* DEPRECATED. Use the `ShellCommandInjectionFromEnvironmentFlow` module instead.
40+
*/
41+
deprecated class Configuration extends TaintTracking::Configuration {
1842
Configuration() { this = "ShellCommandInjectionFromEnvironment" }
1943

2044
override predicate isSource(DataFlow::Node source) { source instanceof Source }

javascript/ql/src/Security/CWE-078/ShellCommandInjectionFromEnvironment.ql

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,18 @@
1414
*/
1515

1616
import javascript
17-
import DataFlow::PathGraph
1817
import semmle.javascript.security.dataflow.ShellCommandInjectionFromEnvironmentQuery
18+
import ShellCommandInjectionFromEnvironmentFlow::PathGraph
1919

2020
from
21-
Configuration cfg, DataFlow::PathNode source, DataFlow::PathNode sink, DataFlow::Node highlight,
21+
ShellCommandInjectionFromEnvironmentFlow::PathNode source,
22+
ShellCommandInjectionFromEnvironmentFlow::PathNode sink, DataFlow::Node highlight,
2223
Source sourceNode
2324
where
2425
sourceNode = source.getNode() and
25-
cfg.hasFlowPath(source, sink) and
26-
if cfg.isSinkWithHighlight(sink.getNode(), _)
27-
then cfg.isSinkWithHighlight(sink.getNode(), highlight)
26+
ShellCommandInjectionFromEnvironmentFlow::flowPath(source, sink) and
27+
if ShellCommandInjectionFromEnvironmentConfig::isSinkWithHighlight(sink.getNode(), _)
28+
then ShellCommandInjectionFromEnvironmentConfig::isSinkWithHighlight(sink.getNode(), highlight)
2829
else highlight = sink.getNode()
2930
select highlight, source, sink, "This shell command depends on an uncontrolled $@.", sourceNode,
3031
sourceNode.getSourceType()

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

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,21 @@
1-
nodes
2-
| tst_shell-command-injection-from-environment.js:6:14:6:53 | 'rm -rf ... "temp") |
3-
| tst_shell-command-injection-from-environment.js:6:14:6:53 | 'rm -rf ... "temp") |
4-
| tst_shell-command-injection-from-environment.js:6:26:6:53 | path.jo ... "temp") |
5-
| tst_shell-command-injection-from-environment.js:6:36:6:44 | __dirname |
6-
| tst_shell-command-injection-from-environment.js:6:36:6:44 | __dirname |
7-
| tst_shell-command-injection-from-environment.js:8:14:8:53 | 'rm -rf ... "temp") |
8-
| tst_shell-command-injection-from-environment.js:8:14:8:53 | 'rm -rf ... "temp") |
9-
| tst_shell-command-injection-from-environment.js:8:26:8:53 | path.jo ... "temp") |
10-
| tst_shell-command-injection-from-environment.js:8:36:8:44 | __dirname |
11-
| tst_shell-command-injection-from-environment.js:8:36:8:44 | __dirname |
12-
| tst_shell-command-injection-from-environment.js:9:18:9:57 | 'rm -rf ... "temp") |
13-
| tst_shell-command-injection-from-environment.js:9:18:9:57 | 'rm -rf ... "temp") |
14-
| tst_shell-command-injection-from-environment.js:9:30:9:57 | path.jo ... "temp") |
15-
| tst_shell-command-injection-from-environment.js:9:40:9:48 | __dirname |
16-
| tst_shell-command-injection-from-environment.js:9:40:9:48 | __dirname |
171
edges
182
| tst_shell-command-injection-from-environment.js:6:26:6:53 | path.jo ... "temp") | tst_shell-command-injection-from-environment.js:6:14:6:53 | 'rm -rf ... "temp") |
19-
| tst_shell-command-injection-from-environment.js:6:26:6:53 | path.jo ... "temp") | tst_shell-command-injection-from-environment.js:6:14:6:53 | 'rm -rf ... "temp") |
203
| tst_shell-command-injection-from-environment.js:6:36:6:44 | __dirname | tst_shell-command-injection-from-environment.js:6:26:6:53 | path.jo ... "temp") |
21-
| tst_shell-command-injection-from-environment.js:6:36:6:44 | __dirname | tst_shell-command-injection-from-environment.js:6:26:6:53 | path.jo ... "temp") |
22-
| tst_shell-command-injection-from-environment.js:8:26:8:53 | path.jo ... "temp") | tst_shell-command-injection-from-environment.js:8:14:8:53 | 'rm -rf ... "temp") |
234
| tst_shell-command-injection-from-environment.js:8:26:8:53 | path.jo ... "temp") | tst_shell-command-injection-from-environment.js:8:14:8:53 | 'rm -rf ... "temp") |
245
| tst_shell-command-injection-from-environment.js:8:36:8:44 | __dirname | tst_shell-command-injection-from-environment.js:8:26:8:53 | path.jo ... "temp") |
25-
| tst_shell-command-injection-from-environment.js:8:36:8:44 | __dirname | tst_shell-command-injection-from-environment.js:8:26:8:53 | path.jo ... "temp") |
26-
| tst_shell-command-injection-from-environment.js:9:30:9:57 | path.jo ... "temp") | tst_shell-command-injection-from-environment.js:9:18:9:57 | 'rm -rf ... "temp") |
276
| tst_shell-command-injection-from-environment.js:9:30:9:57 | path.jo ... "temp") | tst_shell-command-injection-from-environment.js:9:18:9:57 | 'rm -rf ... "temp") |
287
| tst_shell-command-injection-from-environment.js:9:40:9:48 | __dirname | tst_shell-command-injection-from-environment.js:9:30:9:57 | path.jo ... "temp") |
29-
| tst_shell-command-injection-from-environment.js:9:40:9:48 | __dirname | tst_shell-command-injection-from-environment.js:9:30:9:57 | path.jo ... "temp") |
8+
nodes
9+
| tst_shell-command-injection-from-environment.js:6:14:6:53 | 'rm -rf ... "temp") | semmle.label | 'rm -rf ... "temp") |
10+
| tst_shell-command-injection-from-environment.js:6:26:6:53 | path.jo ... "temp") | semmle.label | path.jo ... "temp") |
11+
| tst_shell-command-injection-from-environment.js:6:36:6:44 | __dirname | semmle.label | __dirname |
12+
| tst_shell-command-injection-from-environment.js:8:14:8:53 | 'rm -rf ... "temp") | semmle.label | 'rm -rf ... "temp") |
13+
| tst_shell-command-injection-from-environment.js:8:26:8:53 | path.jo ... "temp") | semmle.label | path.jo ... "temp") |
14+
| tst_shell-command-injection-from-environment.js:8:36:8:44 | __dirname | semmle.label | __dirname |
15+
| tst_shell-command-injection-from-environment.js:9:18:9:57 | 'rm -rf ... "temp") | semmle.label | 'rm -rf ... "temp") |
16+
| tst_shell-command-injection-from-environment.js:9:30:9:57 | path.jo ... "temp") | semmle.label | path.jo ... "temp") |
17+
| tst_shell-command-injection-from-environment.js:9:40:9:48 | __dirname | semmle.label | __dirname |
18+
subpaths
3019
#select
3120
| tst_shell-command-injection-from-environment.js:6:14:6:53 | 'rm -rf ... "temp") | tst_shell-command-injection-from-environment.js:6:36:6:44 | __dirname | tst_shell-command-injection-from-environment.js:6:14:6:53 | 'rm -rf ... "temp") | This shell command depends on an uncontrolled $@. | tst_shell-command-injection-from-environment.js:6:36:6:44 | __dirname | absolute path |
3221
| tst_shell-command-injection-from-environment.js:8:14:8:53 | 'rm -rf ... "temp") | tst_shell-command-injection-from-environment.js:8:36:8:44 | __dirname | tst_shell-command-injection-from-environment.js:8:14:8:53 | 'rm -rf ... "temp") | This shell command depends on an uncontrolled $@. | tst_shell-command-injection-from-environment.js:8:36:8:44 | __dirname | absolute path |

0 commit comments

Comments
 (0)