Skip to content

Commit 8bed3fb

Browse files
committed
Ruby: Add basic model for Terrapin library
1 parent 9d13a1f commit 8bed3fb

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
extensions:
2+
- addsTo:
3+
pack: codeql/ruby-all
4+
extensible: sourceModel
5+
data: []
6+
7+
- addsTo:
8+
pack: codeql/ruby-all
9+
extensible: sinkModel
10+
data:
11+
- ["Terrapin::CommandLine!","Method[new].Argument[0]","command-injection"]
12+
- ["Terrapin::CommandLine!","Method[new].Argument[1]","command-injection"]
13+
14+
- addsTo:
15+
pack: codeql/ruby-all
16+
extensible: summaryModel
17+
data:
18+
- ["Terrapin::CommandLine::Output!","Method[new]","Argument[1]","ReturnValue","value"]
19+
- ["Terrapin::CommandLine!","Method[path=]","Argument[0]","ReturnValue","taint"]
20+
- ["Terrapin::CommandLine!","Method[new]","Argument[2]","ReturnValue","taint"]
21+
22+
- addsTo:
23+
pack: codeql/ruby-all
24+
extensible: neutralModel
25+
data: []
26+
27+
- addsTo:
28+
pack: codeql/ruby-all
29+
extensible: typeModel
30+
data:
31+
- ["Terrapin::CommandLine::Output","Terrapin::CommandLine::MultiPipe","Method[output].ReturnValue"]
32+
- ["Terrapin::CommandLine::Output","Terrapin::CommandLine::FakeRunner","Method[call].ReturnValue"]
33+
- ["Terrapin::CommandLine::Output","Terrapin::CommandLine::ProcessRunner","Method[call].ReturnValue"]
34+
- ["Terrapin::CommandLine::Output","Terrapin::CommandLine!","Method[runner].ReturnValue.ReturnValue"]
35+
- ["Terrapin::CommandLine::FakeRunner","Terrapin::CommandLine!","Method[runner].ReturnValue"]
36+
- ["Terrapin::CommandLine::Output","Terrapin::CommandLine!","Method[fake!].ReturnValue.ReturnValue"]
37+
- ["Terrapin::CommandLine::FakeRunner","Terrapin::CommandLine!","Method[fake!].ReturnValue"]
38+
- ["Terrapin::CommandLine::Output","Terrapin::CommandLine","Method[output].ReturnValue"]
39+
- ["Terrapin::CommandLineError","Terrapin::CommandNotFoundError",""]
40+
- ["Terrapin::CommandLineError","Terrapin::ExitStatusError",""]
41+
- ["Terrapin::CommandLineError","Terrapin::InterpolationError",""]

ruby/ql/test/query-tests/security/cwe-078/CommandInjection/CommandInjection.expected

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ edges
2121
| CommandInjection.rb:103:9:103:12 | file | CommandInjection.rb:104:16:104:28 | "cat #{...}" | provenance | |
2222
| CommandInjection.rb:103:16:103:21 | call to params | CommandInjection.rb:103:16:103:28 | ...[...] | provenance | |
2323
| CommandInjection.rb:103:16:103:28 | ...[...] | CommandInjection.rb:103:9:103:12 | file | provenance | |
24+
| CommandInjection.rb:111:33:111:38 | call to params | CommandInjection.rb:111:33:111:44 | ...[...] | provenance | |
25+
| CommandInjection.rb:113:44:113:49 | call to params | CommandInjection.rb:113:44:113:54 | ...[...] | provenance | |
26+
| CommandInjection.rb:113:44:113:54 | ...[...] | CommandInjection.rb:113:41:113:56 | "#{...}" | provenance | |
2427
nodes
2528
| CommandInjection.rb:6:9:6:11 | cmd | semmle.label | cmd |
2629
| CommandInjection.rb:6:15:6:20 | call to params | semmle.label | call to params |
@@ -51,6 +54,11 @@ nodes
5154
| CommandInjection.rb:103:16:103:21 | call to params | semmle.label | call to params |
5255
| CommandInjection.rb:103:16:103:28 | ...[...] | semmle.label | ...[...] |
5356
| CommandInjection.rb:104:16:104:28 | "cat #{...}" | semmle.label | "cat #{...}" |
57+
| CommandInjection.rb:111:33:111:38 | call to params | semmle.label | call to params |
58+
| CommandInjection.rb:111:33:111:44 | ...[...] | semmle.label | ...[...] |
59+
| CommandInjection.rb:113:41:113:56 | "#{...}" | semmle.label | "#{...}" |
60+
| CommandInjection.rb:113:44:113:49 | call to params | semmle.label | call to params |
61+
| CommandInjection.rb:113:44:113:54 | ...[...] | semmle.label | ...[...] |
5462
subpaths
5563
#select
5664
| CommandInjection.rb:7:10:7:15 | #{...} | CommandInjection.rb:6:15:6:20 | call to params | CommandInjection.rb:7:10:7:15 | #{...} | This command depends on a $@. | CommandInjection.rb:6:15:6:20 | call to params | user-provided value |
@@ -67,3 +75,5 @@ subpaths
6775
| CommandInjection.rb:82:14:82:34 | "echo #{...}" | CommandInjection.rb:81:23:81:33 | blah_number | CommandInjection.rb:82:14:82:34 | "echo #{...}" | This command depends on a $@. | CommandInjection.rb:81:23:81:33 | blah_number | user-provided value |
6876
| CommandInjection.rb:91:14:91:39 | "echo #{...}" | CommandInjection.rb:91:22:91:37 | ...[...] | CommandInjection.rb:91:14:91:39 | "echo #{...}" | This command depends on a $@. | CommandInjection.rb:91:22:91:37 | ...[...] | user-provided value |
6977
| CommandInjection.rb:104:16:104:28 | "cat #{...}" | CommandInjection.rb:103:16:103:21 | call to params | CommandInjection.rb:104:16:104:28 | "cat #{...}" | This command depends on a $@. | CommandInjection.rb:103:16:103:21 | call to params | user-provided value |
78+
| CommandInjection.rb:111:33:111:44 | ...[...] | CommandInjection.rb:111:33:111:38 | call to params | CommandInjection.rb:111:33:111:44 | ...[...] | This command depends on a $@. | CommandInjection.rb:111:33:111:38 | call to params | user-provided value |
79+
| CommandInjection.rb:113:41:113:56 | "#{...}" | CommandInjection.rb:113:44:113:49 | call to params | CommandInjection.rb:113:41:113:56 | "#{...}" | This command depends on a $@. | CommandInjection.rb:113:44:113:49 | call to params | user-provided value |

ruby/ql/test/query-tests/security/cwe-078/CommandInjection/CommandInjection.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,13 @@ def create
106106
system("cat #{file.shellescape}") # OK, because file is shell escaped
107107

108108
end
109-
end
109+
110+
def index
111+
Terrapin::CommandLine.new(params[:foo], "bar") # BAD
112+
113+
Terrapin::CommandLine.new("echo", "#{params[foo]}") # BAD
114+
115+
cmd = Terrapin::CommandLine.new("echo", ":msg")
116+
cmd.run(msg: params[:foo]) # GOOD
117+
end
118+
end

0 commit comments

Comments
 (0)