Skip to content

Commit e5f4730

Browse files
committed
Ruby: add Regexp.{compile,quote} to regex injection test
1 parent 13459c8 commit e5f4730

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

ruby/ql/test/query-tests/security/cwe-1333-regexp-injection/RegExpInjection.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ edges
33
| RegExpInjection.rb:10:12:10:17 | call to params : | RegExpInjection.rb:11:13:11:27 | /foo#{...}bar/ |
44
| RegExpInjection.rb:16:12:16:17 | call to params : | RegExpInjection.rb:17:24:17:27 | name |
55
| RegExpInjection.rb:22:12:22:17 | call to params : | RegExpInjection.rb:23:24:23:33 | ... + ... |
6+
| RegExpInjection.rb:54:12:54:17 | call to params : | RegExpInjection.rb:55:28:55:37 | ... + ... |
67
nodes
78
| RegExpInjection.rb:4:12:4:17 | call to params : | semmle.label | call to params : |
89
| RegExpInjection.rb:5:13:5:21 | /#{...}/ | semmle.label | /#{...}/ |
@@ -12,9 +13,12 @@ nodes
1213
| RegExpInjection.rb:17:24:17:27 | name | semmle.label | name |
1314
| RegExpInjection.rb:22:12:22:17 | call to params : | semmle.label | call to params : |
1415
| RegExpInjection.rb:23:24:23:33 | ... + ... | semmle.label | ... + ... |
16+
| RegExpInjection.rb:54:12:54:17 | call to params : | semmle.label | call to params : |
17+
| RegExpInjection.rb:55:28:55:37 | ... + ... | semmle.label | ... + ... |
1518
subpaths
1619
#select
1720
| RegExpInjection.rb:5:13:5:21 | /#{...}/ | RegExpInjection.rb:4:12:4:17 | call to params : | RegExpInjection.rb:5:13:5:21 | /#{...}/ | This regular expression is constructed from a $@. | RegExpInjection.rb:4:12:4:17 | call to params | user-provided value |
1821
| RegExpInjection.rb:11:13:11:27 | /foo#{...}bar/ | RegExpInjection.rb:10:12:10:17 | call to params : | RegExpInjection.rb:11:13:11:27 | /foo#{...}bar/ | This regular expression is constructed from a $@. | RegExpInjection.rb:10:12:10:17 | call to params | user-provided value |
1922
| RegExpInjection.rb:17:24:17:27 | name | RegExpInjection.rb:16:12:16:17 | call to params : | RegExpInjection.rb:17:24:17:27 | name | This regular expression is constructed from a $@. | RegExpInjection.rb:16:12:16:17 | call to params | user-provided value |
2023
| RegExpInjection.rb:23:24:23:33 | ... + ... | RegExpInjection.rb:22:12:22:17 | call to params : | RegExpInjection.rb:23:24:23:33 | ... + ... | This regular expression is constructed from a $@. | RegExpInjection.rb:22:12:22:17 | call to params | user-provided value |
24+
| RegExpInjection.rb:55:28:55:37 | ... + ... | RegExpInjection.rb:54:12:54:17 | call to params : | RegExpInjection.rb:55:28:55:37 | ... + ... | This regular expression is constructed from a $@. | RegExpInjection.rb:54:12:54:17 | call to params | user-provided value |

ruby/ql/test/query-tests/security/cwe-1333-regexp-injection/RegExpInjection.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,16 @@ def route6
4242
name = params[:name]
4343
regex = Regexp.new(Regexp.escape(name))
4444
end
45+
46+
# GOOD - string is explicitly escaped
47+
def route7
48+
name = params[:name]
49+
regex = Regexp.new(Regexp.quote(name))
50+
end
51+
52+
# BAD
53+
def route8
54+
name = params[:name]
55+
regex = Regexp.compile("@" + name)
56+
end
4557
end

0 commit comments

Comments
 (0)