Skip to content

Commit 378cc1a

Browse files
committed
add support for string-like-literals
1 parent 80c92dc commit 378cc1a

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

ruby/ql/lib/codeql/ruby/security/UnsafeCodeConstructionCustomizations.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ module UnsafeCodeConstruction {
8484
Concepts::CodeExecution s;
8585

8686
StringFormatAsSink() {
87-
exists(Ast::StringLiteral lit |
87+
exists(Ast::StringlikeLiteral lit |
8888
any(DataFlow::Node n | n.asExpr().getExpr() = lit) = getANodeExecutedAsCode(s) and
8989
this.asExpr().getExpr() = lit.getComponent(_)
9090
)

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ edges
66
| impl/unsafeCode.rb:32:21:32:21 | x : | impl/unsafeCode.rb:34:10:34:12 | arr |
77
| impl/unsafeCode.rb:37:15:37:15 | x : | impl/unsafeCode.rb:40:10:40:12 | arr |
88
| impl/unsafeCode.rb:37:15:37:15 | x : | impl/unsafeCode.rb:44:10:44:12 | arr |
9+
| impl/unsafeCode.rb:47:15:47:15 | x : | impl/unsafeCode.rb:49:9:49:12 | #{...} |
910
nodes
1011
| impl/unsafeCode.rb:2:12:2:17 | target : | semmle.label | target : |
1112
| impl/unsafeCode.rb:3:17:3:25 | #{...} | semmle.label | #{...} |
@@ -20,6 +21,8 @@ nodes
2021
| impl/unsafeCode.rb:37:15:37:15 | x : | semmle.label | x : |
2122
| impl/unsafeCode.rb:40:10:40:12 | arr | semmle.label | arr |
2223
| impl/unsafeCode.rb:44:10:44:12 | arr | semmle.label | arr |
24+
| impl/unsafeCode.rb:47:15:47:15 | x : | semmle.label | x : |
25+
| impl/unsafeCode.rb:49:9:49:12 | #{...} | semmle.label | #{...} |
2326
subpaths
2427
#select
2528
| 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 |
@@ -29,3 +32,4 @@ subpaths
2932
| impl/unsafeCode.rb:34:10:34:12 | arr | impl/unsafeCode.rb:32:21:32:21 | x : | impl/unsafeCode.rb:34:10:34:12 | arr | This array which depends on $@ is later $@. | impl/unsafeCode.rb:32:21:32:21 | x | library input | impl/unsafeCode.rb:34:5:34:24 | call to eval | interpreted as code |
3033
| impl/unsafeCode.rb:40:10:40:12 | arr | impl/unsafeCode.rb:37:15:37:15 | x : | impl/unsafeCode.rb:40:10:40:12 | arr | This array which depends on $@ is later $@. | impl/unsafeCode.rb:37:15:37:15 | x | library input | impl/unsafeCode.rb:40:5:40:24 | call to eval | interpreted as code |
3134
| 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 |
35+
| 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 |

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,11 @@ def pushArr(x, y)
4343
arr2 << y
4444
eval(arr.join("\n")) # NOT OK
4545
end
46+
47+
def hereDoc(x)
48+
foo = <<~HERE
49+
#{x}
50+
HERE
51+
eval(foo) # NOT OK
52+
end
4653
end

0 commit comments

Comments
 (0)