Skip to content

Commit 42cd586

Browse files
committed
Ruby: configsig rb/url-redirection
1 parent f79796a commit 42cd586

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

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

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
/**
22
* Provides a taint-tracking configuration for detecting "URL redirection" vulnerabilities.
33
*
4-
* Note, for performance reasons: only import this file if `Configuration` is needed,
5-
* otherwise `UrlRedirectCustomizations` should be imported instead.
4+
* Note, for performance reasons: only import this file if
5+
* `UrlRedirectConfig` is needed, otherwise
6+
* `UrlRedirectCustomizations` should be imported instead.
67
*/
78

89
private import codeql.ruby.AST
@@ -13,8 +14,9 @@ import UrlRedirectCustomizations::UrlRedirect
1314

1415
/**
1516
* A taint-tracking configuration for detecting "URL redirection" vulnerabilities.
17+
* DEPRECATED: Use `UrlRedirectFlow`
1618
*/
17-
class Configuration extends TaintTracking::Configuration {
19+
deprecated class Configuration extends TaintTracking::Configuration {
1820
Configuration() { this = "UrlRedirect" }
1921

2022
override predicate isSource(DataFlow::Node source) { source instanceof Source }
@@ -31,3 +33,20 @@ class Configuration extends TaintTracking::Configuration {
3133
UrlRedirect::isAdditionalTaintStep(node1, node2)
3234
}
3335
}
36+
37+
private module UrlRedirectConfig implements DataFlow::ConfigSig {
38+
predicate isSource(DataFlow::Node source) { source instanceof Source }
39+
40+
predicate isSink(DataFlow::Node sink) { sink instanceof Sink }
41+
42+
predicate isBarrier(DataFlow::Node node) { node instanceof Sanitizer }
43+
44+
predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
45+
UrlRedirect::isAdditionalTaintStep(node1, node2)
46+
}
47+
}
48+
49+
/**
50+
* Taint-tracking for detecting "URL redirection" vulnerabilities.
51+
*/
52+
module UrlRedirectFlow = TaintTracking::Global<UrlRedirectConfig>;

ruby/ql/src/queries/security/cwe-601/UrlRedirect.ql

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@
1212
* @precision high
1313
*/
1414

15-
import codeql.ruby.AST
1615
import codeql.ruby.security.UrlRedirectQuery
17-
import codeql.ruby.DataFlow::DataFlow::PathGraph
16+
import UrlRedirectFlow::PathGraph
1817

19-
from Configuration config, DataFlow::PathNode source, DataFlow::PathNode sink
20-
where config.hasFlowPath(source, sink)
18+
from UrlRedirectFlow::PathNode source, UrlRedirectFlow::PathNode sink
19+
where UrlRedirectFlow::flowPath(source, sink)
2120
select sink.getNode(), source, sink, "Untrusted URL redirection depends on a $@.", source.getNode(),
2221
"user-provided value"

ruby/ql/test/query-tests/security/cwe-601/UrlRedirect.expected

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ edges
1010
| UrlRedirect.rb:63:38:63:43 | call to params | UrlRedirect.rb:63:38:63:49 | ...[...] |
1111
| UrlRedirect.rb:68:38:68:43 | call to params | UrlRedirect.rb:68:38:68:49 | ...[...] |
1212
| UrlRedirect.rb:73:25:73:30 | call to params | UrlRedirect.rb:73:25:73:36 | ...[...] |
13-
| UrlRedirect.rb:93:21:93:32 | input_params | UrlRedirect.rb:94:5:94:29 | call to permit |
13+
| UrlRedirect.rb:93:21:93:32 | input_params | UrlRedirect.rb:94:5:94:16 | input_params |
14+
| UrlRedirect.rb:94:5:94:16 | input_params | UrlRedirect.rb:94:5:94:29 | call to permit |
1415
nodes
1516
| UrlRedirect.rb:4:17:4:22 | call to params | semmle.label | call to params |
1617
| UrlRedirect.rb:9:17:9:22 | call to params | semmle.label | call to params |
@@ -33,6 +34,7 @@ nodes
3334
| UrlRedirect.rb:73:25:73:30 | call to params | semmle.label | call to params |
3435
| UrlRedirect.rb:73:25:73:36 | ...[...] | semmle.label | ...[...] |
3536
| UrlRedirect.rb:93:21:93:32 | input_params | semmle.label | input_params |
37+
| UrlRedirect.rb:94:5:94:16 | input_params | semmle.label | input_params |
3638
| UrlRedirect.rb:94:5:94:29 | call to permit | semmle.label | call to permit |
3739
subpaths
3840
| UrlRedirect.rb:24:31:24:36 | call to params | UrlRedirect.rb:93:21:93:32 | input_params | UrlRedirect.rb:94:5:94:29 | call to permit | UrlRedirect.rb:24:17:24:37 | call to filter_params |

0 commit comments

Comments
 (0)