File tree Expand file tree Collapse file tree 4 files changed +18
-3
lines changed
query-tests/security/cwe-078 Expand file tree Collapse file tree 4 files changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import ruby
11
11
import codeql.ruby.TaintTracking
12
12
import CommandInjectionCustomizations:: CommandInjection
13
13
import codeql.ruby.DataFlow
14
+ import codeql.ruby.dataflow.BarrierGuards
14
15
15
16
/**
16
17
* A taint-tracking configuration for reasoning about command-injection vulnerabilities.
@@ -23,4 +24,9 @@ class Configuration extends TaintTracking::Configuration {
23
24
override predicate isSink ( DataFlow:: Node sink ) { sink instanceof Sink }
24
25
25
26
override predicate isSanitizer ( DataFlow:: Node node ) { node instanceof Sanitizer }
27
+
28
+ override predicate isSanitizerGuard ( DataFlow:: BarrierGuard guard ) {
29
+ guard instanceof StringConstCompare or
30
+ guard instanceof StringConstArrayInclusionCall
31
+ }
26
32
}
Original file line number Diff line number Diff line change 62
62
Open3 . pipeline_r ( "echo foo" )
63
63
Open3 . pipeline_w ( "echo foo" )
64
64
Open3 . pipeline_start ( "echo foo" )
65
- Open3 . pipeline ( "echo foo" )
65
+ Open3 . pipeline ( "echo foo" )
Original file line number Diff line number Diff line change 1
- queries/security/cwe-078/CommandInjection.ql
1
+ queries/security/cwe-078/CommandInjection.ql
Original file line number Diff line number Diff line change @@ -7,8 +7,17 @@ def create
7
7
system ( cmd )
8
8
exec ( cmd )
9
9
%x(echo #{ cmd } )
10
+
10
11
safe_cmd = Shellwords . escape ( cmd )
11
12
`echo #{ safe_cmd } `
13
+
14
+ if cmd == "some constant"
15
+ `echo #{ cmd } `
16
+ end
17
+
18
+ if %w( foo bar ) . include? cmd
19
+ `echo #{ cmd } `
20
+ end
12
21
end
13
22
14
23
def show
@@ -17,4 +26,4 @@ def show
17
26
exec ( "ls" )
18
27
%x(ls)
19
28
end
20
- end
29
+ end
You can’t perform that action at this time.
0 commit comments