Skip to content

Commit 80d05c0

Browse files
committed
also recognize protected methods as library-input sources
1 parent a017b75 commit 80d05c0

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,13 @@ module Gem {
8585

8686
/** Gets a parameter from an exported method, which is an input to this gem. */
8787
DataFlow::ParameterNode getAnInputParameter() {
88-
exists(MethodBase method | method = getAPublicModule().getAMethod() |
89-
result.getParameter() = method.getAParameter() and
88+
exists(MethodBase method |
89+
method = getAPublicModule().getAMethod() and
90+
result.getParameter() = method.getAParameter()
91+
|
9092
method.isPublic()
93+
or
94+
method.isProtected()
9195
)
9296
}
9397
}

ruby/ql/test/query-tests/security/cwe-1333-polynomial-redos/PolynomialReDoS.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ edges
2424
| PolynomialReDoS.rb:31:9:31:14 | call to params : | PolynomialReDoS.rb:31:9:31:18 | ...[...] : |
2525
| PolynomialReDoS.rb:31:9:31:18 | ...[...] : | PolynomialReDoS.rb:32:5:32:5 | c |
2626
| lib/index.rb:2:11:2:11 | x : | lib/index.rb:4:13:4:13 | x |
27+
| lib/index.rb:8:13:8:13 | x : | lib/index.rb:9:15:9:15 | x |
2728
nodes
2829
| PolynomialReDoS.rb:4:12:4:17 | call to params : | semmle.label | call to params : |
2930
| PolynomialReDoS.rb:4:12:4:24 | ...[...] : | semmle.label | ...[...] : |
@@ -55,6 +56,8 @@ nodes
5556
| PolynomialReDoS.rb:47:10:47:13 | name | semmle.label | name |
5657
| lib/index.rb:2:11:2:11 | x : | semmle.label | x : |
5758
| lib/index.rb:4:13:4:13 | x | semmle.label | x |
59+
| lib/index.rb:8:13:8:13 | x : | semmle.label | x : |
60+
| lib/index.rb:9:15:9:15 | x | semmle.label | x |
5861
subpaths
5962
#select
6063
| PolynomialReDoS.rb:10:5:10:17 | ... =~ ... | PolynomialReDoS.rb:4:12:4:17 | call to params : | PolynomialReDoS.rb:10:5:10:8 | name | This $@ that depends on a $@ may run slow on strings with many repetitions of ' '. | PolynomialReDoS.rb:7:19:7:21 | \\s+ | regular expression | PolynomialReDoS.rb:4:12:4:17 | call to params | user-provided value |
@@ -78,3 +81,4 @@ subpaths
7881
| PolynomialReDoS.rb:42:5:45:7 | case ... | PolynomialReDoS.rb:4:12:4:17 | call to params : | PolynomialReDoS.rb:42:10:42:13 | name | This $@ that depends on a $@ may run slow on strings with many repetitions of ' '. | PolynomialReDoS.rb:7:19:7:21 | \\s+ | regular expression | PolynomialReDoS.rb:4:12:4:17 | call to params | user-provided value |
7982
| PolynomialReDoS.rb:47:5:50:7 | case ... | PolynomialReDoS.rb:4:12:4:17 | call to params : | PolynomialReDoS.rb:47:10:47:13 | name | This $@ that depends on a $@ may run slow on strings with many repetitions of ' '. | PolynomialReDoS.rb:48:14:48:16 | \\s+ | regular expression | PolynomialReDoS.rb:4:12:4:17 | call to params | user-provided value |
8083
| lib/index.rb:4:13:4:26 | call to match | lib/index.rb:2:11:2:11 | x : | lib/index.rb:4:13:4:13 | x | This $@ that depends on a $@ may run slow on strings with many repetitions of 'a'. | lib/index.rb:4:22:4:23 | a+ | regular expression | lib/index.rb:2:11:2:11 | x | library input |
84+
| lib/index.rb:9:15:9:28 | call to match | lib/index.rb:8:13:8:13 | x : | lib/index.rb:9:15:9:15 | x | This $@ that depends on a $@ may run slow on strings with many repetitions of 'a'. | lib/index.rb:9:24:9:25 | a+ | regular expression | lib/index.rb:8:13:8:13 | x | library input |

ruby/ql/test/query-tests/security/cwe-1333-polynomial-redos/lib/index.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,9 @@ def bar(x)
33
# Run the /a+$/ regex on the input x.
44
match = x.match(/a+$/)
55
end
6+
7+
protected
8+
def baz(x)
9+
match = x.match(/a+$/)
10+
end
611
end

0 commit comments

Comments
 (0)