Skip to content

Commit c2e8206

Browse files
committed
add more array taint steps that taint the entire array
1 parent 962465f commit c2e8206

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

ruby/ql/lib/codeql/ruby/frameworks/core/Array.qll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1833,6 +1833,16 @@ module Array {
18331833
succ = call and
18341834
pred = call.getArgument(_)
18351835
)
1836+
or
1837+
exists(DataFlow::CallNode call | call.getMethodName() = "join" |
1838+
pred = call.getReceiver() and
1839+
succ = call
1840+
)
1841+
or
1842+
exists(DataFlow::CallNode call | call.getMethodName() = "Array" |
1843+
pred = call.getArgument(_) and
1844+
succ = call
1845+
)
18361846
}
18371847
}
18381848

ruby/ql/test/query-tests/security/cwe-094/UnsafeCodeConstruction/UnsafeCodeConstruction.expected

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ edges
88
| impl/unsafeCode.rb:37:15:37:15 | x : | impl/unsafeCode.rb:44:10:44:12 | arr |
99
| impl/unsafeCode.rb:47:15:47:15 | x : | impl/unsafeCode.rb:49:9:49:12 | #{...} |
1010
| impl/unsafeCode.rb:54:21:54:21 | x : | impl/unsafeCode.rb:55:22:55:22 | x |
11+
| impl/unsafeCode.rb:59:21:59:21 | x : | impl/unsafeCode.rb:61:10:61:12 | arr |
12+
| impl/unsafeCode.rb:59:21:59:21 | x : | impl/unsafeCode.rb:64:10:64:12 | arr |
1113
nodes
1214
| impl/unsafeCode.rb:2:12:2:17 | target : | semmle.label | target : |
1315
| impl/unsafeCode.rb:3:17:3:25 | #{...} | semmle.label | #{...} |
@@ -26,6 +28,9 @@ nodes
2628
| impl/unsafeCode.rb:49:9:49:12 | #{...} | semmle.label | #{...} |
2729
| impl/unsafeCode.rb:54:21:54:21 | x : | semmle.label | x : |
2830
| impl/unsafeCode.rb:55:22:55:22 | x | semmle.label | x |
31+
| impl/unsafeCode.rb:59:21:59:21 | x : | semmle.label | x : |
32+
| impl/unsafeCode.rb:61:10:61:12 | arr | semmle.label | arr |
33+
| impl/unsafeCode.rb:64:10:64:12 | arr | semmle.label | arr |
2934
subpaths
3035
#select
3136
| impl/unsafeCode.rb:3:17:3:25 | #{...} | impl/unsafeCode.rb:2:12:2:17 | target : | impl/unsafeCode.rb:3:17:3:25 | #{...} | This string interpolation which depends on $@ is later $@. | impl/unsafeCode.rb:2:12:2:17 | target | library input | impl/unsafeCode.rb:3:5:3:27 | call to eval | interpreted as code |
@@ -37,3 +42,5 @@ subpaths
3742
| impl/unsafeCode.rb:44:10:44:12 | arr | impl/unsafeCode.rb:37:15:37:15 | x : | impl/unsafeCode.rb:44:10:44:12 | arr | This array which depends on $@ is later $@. | impl/unsafeCode.rb:37:15:37:15 | x | library input | impl/unsafeCode.rb:44:5:44:24 | call to eval | interpreted as code |
3843
| impl/unsafeCode.rb:49:9:49:12 | #{...} | impl/unsafeCode.rb:47:15:47:15 | x : | impl/unsafeCode.rb:49:9:49:12 | #{...} | This string interpolation which depends on $@ is later $@. | impl/unsafeCode.rb:47:15:47:15 | x | library input | impl/unsafeCode.rb:51:5:51:13 | call to eval | interpreted as code |
3944
| impl/unsafeCode.rb:55:22:55:22 | x | impl/unsafeCode.rb:54:21:54:21 | x : | impl/unsafeCode.rb:55:22:55:22 | x | This string concatenation which depends on $@ is later $@. | impl/unsafeCode.rb:54:21:54:21 | x | library input | impl/unsafeCode.rb:56:5:56:13 | call to eval | interpreted as code |
45+
| impl/unsafeCode.rb:61:10:61:12 | arr | impl/unsafeCode.rb:59:21:59:21 | x : | impl/unsafeCode.rb:61:10:61:12 | arr | This array which depends on $@ is later $@. | impl/unsafeCode.rb:59:21:59:21 | x | library input | impl/unsafeCode.rb:61:5:61:23 | call to eval | interpreted as code |
46+
| impl/unsafeCode.rb:64:10:64:12 | arr | impl/unsafeCode.rb:59:21:59:21 | x : | impl/unsafeCode.rb:64:10:64:12 | arr | This array which depends on $@ is later $@. | impl/unsafeCode.rb:59:21:59:21 | x | library input | impl/unsafeCode.rb:64:5:64:24 | call to eval | interpreted as code |

ruby/ql/test/query-tests/security/cwe-094/UnsafeCodeConstruction/impl/unsafeCode.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,12 @@ def string_concat(x)
5555
foo = "foo = " + x
5656
eval(foo) # NOT OK
5757
end
58+
59+
def join_indirect(x, y)
60+
arr = Array("foo = ", x)
61+
eval(arr.join(" ")) # NOT OK
62+
63+
arr2 = [Array("foo = ", y).join(" ")]
64+
eval(arr.join("\n")) # NOT OK
65+
end
5866
end

0 commit comments

Comments
 (0)