Skip to content

Commit 6c06def

Browse files
committed
Ruby: configsig rb/manually-checking-http-verb
1 parent 39af2d2 commit 6c06def

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

ruby/ql/src/experimental/manually-check-http-verb/ManuallyCheckHttpVerb.ql

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import codeql.ruby.DataFlow
1515
import codeql.ruby.controlflow.CfgNodes
1616
import codeql.ruby.frameworks.ActionController
1717
import codeql.ruby.TaintTracking
18-
import DataFlow::PathGraph
1918

2019
// any `request` calls in an action method
2120
class Request extends DataFlow::CallNode {
@@ -73,10 +72,8 @@ class RequestGet extends DataFlow::CallNode {
7372
}
7473
}
7574

76-
class HttpVerbConfig extends TaintTracking::Configuration {
77-
HttpVerbConfig() { this = "HttpVerbConfig" }
78-
79-
override predicate isSource(DataFlow::Node source) {
75+
private module HttpVerbConfig implements DataFlow::ConfigSig {
76+
predicate isSource(DataFlow::Node source) {
8077
source instanceof RequestMethod or
8178
source instanceof RequestRequestMethod or
8279
source instanceof RequestEnvMethod or
@@ -85,13 +82,17 @@ class HttpVerbConfig extends TaintTracking::Configuration {
8582
source instanceof RequestGet
8683
}
8784

88-
override predicate isSink(DataFlow::Node sink) {
85+
predicate isSink(DataFlow::Node sink) {
8986
exists(ExprNodes::ConditionalExprCfgNode c | c.getCondition() = sink.asExpr()) or
9087
exists(ExprNodes::CaseExprCfgNode c | c.getValue() = sink.asExpr())
9188
}
9289
}
9390

94-
from HttpVerbConfig config, DataFlow::PathNode source, DataFlow::PathNode sink
95-
where config.hasFlowPath(source, sink)
91+
private module HttpVerbFlow = TaintTracking::Global<HttpVerbConfig>;
92+
93+
private import HttpVerbFlow::PathGraph
94+
95+
from HttpVerbFlow::PathNode source, HttpVerbFlow::PathNode sink
96+
where HttpVerbFlow::flowPath(source, sink)
9697
select sink.getNode(), source, sink,
9798
"Manually checking HTTP verbs is an indication that multiple requests are routed to the same controller action. This could lead to bypassing necessary authorization methods and other protections, like CSRF protection. Prefer using different controller actions for each HTTP method and relying Rails routing to handle mapping resources and verbs to specific methods."

0 commit comments

Comments
 (0)