File tree Expand file tree Collapse file tree 6 files changed +33
-0
lines changed
lib/codeql/ruby/frameworks
query-tests/security/cwe-078 Expand file tree Collapse file tree 6 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,25 @@ class SubshellLiteralExecution extends SystemCommandExecution::Range {
26
26
override predicate isShellInterpreted ( DataFlow:: Node arg ) { arg = getAnArgument ( ) }
27
27
}
28
28
29
+ /**
30
+ * A system command executed via shell heredoc syntax.
31
+ * E.g.
32
+ * ```ruby
33
+ * <<`EOF`
34
+ * cat foo.text
35
+ * EOF
36
+ * ```
37
+ */
38
+ class SubshellHeredocExecution extends SystemCommandExecution:: Range {
39
+ HereDoc heredoc ;
40
+
41
+ SubshellHeredocExecution ( ) { this .asExpr ( ) .getExpr ( ) = heredoc and heredoc .isSubShell ( ) }
42
+
43
+ override DataFlow:: Node getAnArgument ( ) { result .asExpr ( ) .getExpr ( ) = heredoc .getComponent ( _) }
44
+
45
+ override predicate isShellInterpreted ( DataFlow:: Node arg ) { arg = getAnArgument ( ) }
46
+ }
47
+
29
48
/**
30
49
* A system command executed via the `Kernel.system` method.
31
50
* `Kernel.system` accepts three argument forms:
Original file line number Diff line number Diff line change 63
63
Open3 . pipeline_w ( "echo foo" )
64
64
Open3 . pipeline_start ( "echo foo" )
65
65
Open3 . pipeline ( "echo foo" )
66
+
67
+ <<`EOF`
68
+ echo foo
69
+ EOF
Original file line number Diff line number Diff line change @@ -4,6 +4,8 @@ subshellLiteralExecutions
4
4
| CommandExecution.rb:3:1:3:12 | `echo foo` |
5
5
| CommandExecution.rb:4:1:4:12 | `echo foo` |
6
6
| CommandExecution.rb:5:1:5:12 | `echo foo` |
7
+ subshellHeredocExecutions
8
+ | CommandExecution.rb:67:1:67:7 | <<`EOF` |
7
9
kernelSystemCallExecutions
8
10
| CommandExecution.rb:7:1:7:18 | call to system |
9
11
| CommandExecution.rb:8:1:8:21 | call to system |
Original file line number Diff line number Diff line change @@ -2,6 +2,8 @@ import codeql.ruby.frameworks.StandardLibrary
2
2
3
3
query predicate subshellLiteralExecutions ( SubshellLiteralExecution e ) { any ( ) }
4
4
5
+ query predicate subshellHeredocExecutions ( SubshellHeredocExecution e ) { any ( ) }
6
+
5
7
query predicate kernelSystemCallExecutions ( KernelSystemCall c ) { any ( ) }
6
8
7
9
query predicate kernelExecCallExecutions ( KernelExecCall c ) { any ( ) }
Original file line number Diff line number Diff line change 3
3
| CommandInjection.rb:5:15:5:20 | call to params : | CommandInjection.rb:7:16:7:18 | cmd |
4
4
| CommandInjection.rb:5:15:5:20 | call to params : | CommandInjection.rb:8:14:8:16 | cmd |
5
5
| CommandInjection.rb:5:15:5:20 | call to params : | CommandInjection.rb:9:17:9:22 | #{...} |
6
+ | CommandInjection.rb:5:15:5:20 | call to params : | CommandInjection.rb:11:9:11:14 | #{...} |
6
7
nodes
7
8
| CommandInjection.rb:5:15:5:20 | call to params : | semmle.label | call to params : |
8
9
| CommandInjection.rb:6:10:6:15 | #{...} | semmle.label | #{...} |
9
10
| CommandInjection.rb:7:16:7:18 | cmd | semmle.label | cmd |
10
11
| CommandInjection.rb:8:14:8:16 | cmd | semmle.label | cmd |
11
12
| CommandInjection.rb:9:17:9:22 | #{...} | semmle.label | #{...} |
13
+ | CommandInjection.rb:11:9:11:14 | #{...} | semmle.label | #{...} |
12
14
#select
13
15
| CommandInjection.rb:6:10:6:15 | #{...} | CommandInjection.rb:5:15:5:20 | call to params : | CommandInjection.rb:6:10:6:15 | #{...} | This command depends on $@. | CommandInjection.rb:5:15:5:20 | call to params | a user-provided value |
14
16
| CommandInjection.rb:7:16:7:18 | cmd | CommandInjection.rb:5:15:5:20 | call to params : | CommandInjection.rb:7:16:7:18 | cmd | This command depends on $@. | CommandInjection.rb:5:15:5:20 | call to params | a user-provided value |
15
17
| CommandInjection.rb:8:14:8:16 | cmd | CommandInjection.rb:5:15:5:20 | call to params : | CommandInjection.rb:8:14:8:16 | cmd | This command depends on $@. | CommandInjection.rb:5:15:5:20 | call to params | a user-provided value |
16
18
| CommandInjection.rb:9:17:9:22 | #{...} | CommandInjection.rb:5:15:5:20 | call to params : | CommandInjection.rb:9:17:9:22 | #{...} | This command depends on $@. | CommandInjection.rb:5:15:5:20 | call to params | a user-provided value |
19
+ | CommandInjection.rb:11:9:11:14 | #{...} | CommandInjection.rb:5:15:5:20 | call to params : | CommandInjection.rb:11:9:11:14 | #{...} | This command depends on $@. | CommandInjection.rb:5:15:5:20 | call to params | a user-provided value |
Original file line number Diff line number Diff line change @@ -7,6 +7,9 @@ def create
7
7
system ( cmd )
8
8
exec ( cmd )
9
9
%x(echo #{ cmd } )
10
+ result = <<`EOF`
11
+ #{ cmd }
12
+ EOF
10
13
11
14
safe_cmd = Shellwords . escape ( cmd )
12
15
`echo #{ safe_cmd } `
You can’t perform that action at this time.
0 commit comments