Skip to content

Commit 599dc28

Browse files
committed
Add another test for shell interpretation
1 parent f835976 commit 599dc28

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ edges
77
| CommandInjection.rb:6:15:6:20 | call to params : | CommandInjection.rb:26:19:26:24 | #{...} |
88
| CommandInjection.rb:6:15:6:20 | call to params : | CommandInjection.rb:30:24:30:36 | "echo #{...}" |
99
| CommandInjection.rb:6:15:6:20 | call to params : | CommandInjection.rb:31:39:31:51 | "grep #{...}" |
10-
| CommandInjection.rb:42:15:42:20 | call to params : | CommandInjection.rb:46:24:46:36 | "echo #{...}" |
10+
| CommandInjection.rb:43:15:43:20 | call to params : | CommandInjection.rb:47:24:47:36 | "echo #{...}" |
1111
nodes
1212
| CommandInjection.rb:6:15:6:20 | call to params : | semmle.label | call to params : |
1313
| CommandInjection.rb:7:10:7:15 | #{...} | semmle.label | #{...} |
@@ -18,8 +18,8 @@ nodes
1818
| CommandInjection.rb:26:19:26:24 | #{...} | semmle.label | #{...} |
1919
| CommandInjection.rb:30:24:30:36 | "echo #{...}" | semmle.label | "echo #{...}" |
2020
| CommandInjection.rb:31:39:31:51 | "grep #{...}" | semmle.label | "grep #{...}" |
21-
| CommandInjection.rb:42:15:42:20 | call to params : | semmle.label | call to params : |
22-
| CommandInjection.rb:46:24:46:36 | "echo #{...}" | semmle.label | "echo #{...}" |
21+
| CommandInjection.rb:43:15:43:20 | call to params : | semmle.label | call to params : |
22+
| CommandInjection.rb:47:24:47:36 | "echo #{...}" | semmle.label | "echo #{...}" |
2323
#select
2424
| 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 $@. | CommandInjection.rb:6:15:6:20 | call to params | a user-provided value |
2525
| CommandInjection.rb:8:16:8:18 | cmd | CommandInjection.rb:6:15:6:20 | call to params : | CommandInjection.rb:8:16:8:18 | cmd | This command depends on $@. | CommandInjection.rb:6:15:6:20 | call to params | a user-provided value |
@@ -29,4 +29,4 @@ nodes
2929
| CommandInjection.rb:26:19:26:24 | #{...} | CommandInjection.rb:6:15:6:20 | call to params : | CommandInjection.rb:26:19:26:24 | #{...} | This command depends on $@. | CommandInjection.rb:6:15:6:20 | call to params | a user-provided value |
3030
| CommandInjection.rb:30:24:30:36 | "echo #{...}" | CommandInjection.rb:6:15:6:20 | call to params : | CommandInjection.rb:30:24:30:36 | "echo #{...}" | This command depends on $@. | CommandInjection.rb:6:15:6:20 | call to params | a user-provided value |
3131
| CommandInjection.rb:31:39:31:51 | "grep #{...}" | CommandInjection.rb:6:15:6:20 | call to params : | CommandInjection.rb:31:39:31:51 | "grep #{...}" | This command depends on $@. | CommandInjection.rb:6:15:6:20 | call to params | a user-provided value |
32-
| CommandInjection.rb:46:24:46:36 | "echo #{...}" | CommandInjection.rb:42:15:42:20 | call to params : | CommandInjection.rb:46:24:46:36 | "echo #{...}" | This command depends on $@. | CommandInjection.rb:42:15:42:20 | call to params | a user-provided value |
32+
| CommandInjection.rb:47:24:47:36 | "echo #{...}" | CommandInjection.rb:43:15:43:20 | call to params : | CommandInjection.rb:47:24:47:36 | "echo #{...}" | This command depends on $@. | CommandInjection.rb:43:15:43:20 | call to params | a user-provided value |

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ def create
66
cmd = params[:cmd]
77
`#{cmd}`
88
system(cmd)
9-
system("echo", cmd)
9+
system("echo", cmd) # OK, because cmd is not shell interpreted
1010
exec(cmd)
1111
%x(echo #{cmd})
1212
result = <<`EOF`
@@ -29,6 +29,7 @@ def create
2929
# Open3 methods
3030
Open3.capture2("echo #{cmd}")
3131
Open3.pipeline("cat foo.txt", "grep #{cmd}")
32+
Open3.pipeline(["echo", cmd], "tail") # OK, because cmd is not shell interpreted
3233
end
3334

3435
def show

0 commit comments

Comments
 (0)