Skip to content

Commit 703829c

Browse files
committed
Ruby: use taint tracking for rb/sensitive-get-query
1 parent 7720d85 commit 703829c

File tree

2 files changed

+27
-22
lines changed

2 files changed

+27
-22
lines changed

ruby/ql/src/queries/security/cwe-598/SensitiveGetQuery.ql

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @name Sensitive data read from GET request
33
* @description Placing sensitive data in a GET request increases the risk of
44
* the data being exposed to an attacker.
5-
* @kind problem
5+
* @kind path-problem
66
* @problem.severity warning
77
* @security-severity 6.5
88
* @precision high
@@ -13,32 +13,36 @@
1313

1414
import ruby
1515
private import codeql.ruby.DataFlow
16+
private import codeql.ruby.TaintTracking
1617
private import codeql.ruby.security.SensitiveActions
1718
private import codeql.ruby.Concepts
1819
private import codeql.ruby.frameworks.ActionDispatch
1920
private import codeql.ruby.frameworks.ActionController
2021
private import codeql.ruby.frameworks.core.Array
2122

22-
// Local flow augmented with flow through element references
23-
private predicate localFlowWithElementReference(DataFlow::LocalSourceNode src, DataFlow::Node to) {
24-
src.flowsTo(to)
25-
or
26-
exists(DataFlow::Node midRecv, DataFlow::LocalSourceNode mid, ElementReference ref |
27-
src.flowsTo(midRecv) and
28-
midRecv.asExpr().getExpr() = ref.getReceiver() and
29-
mid.asExpr().getExpr() = ref
30-
|
31-
localFlowWithElementReference(mid, to)
32-
)
23+
class Source extends Http::Server::RequestInputAccess {
24+
private Http::Server::RequestHandler handler;
25+
26+
Source() {
27+
handler = this.asExpr().getExpr().getEnclosingMethod() and
28+
handler.getAnHttpMethod() = "get"
29+
}
30+
31+
Http::Server::RequestHandler getHandler() { result = handler }
32+
}
33+
34+
class Configuration extends TaintTracking::Configuration {
35+
Configuration() { this = "SensitiveGetQuery" }
36+
37+
override predicate isSource(DataFlow::Node source) { source instanceof Source }
38+
39+
override predicate isSink(DataFlow::Node sink) { sink instanceof SensitiveNode }
3340
}
3441

35-
from
36-
Http::Server::RequestHandler handler, Http::Server::RequestInputAccess input,
37-
SensitiveNode sensitive
42+
from DataFlow::PathNode source, DataFlow::PathNode sink, Configuration config
3843
where
39-
handler.getAnHttpMethod() = "get" and
40-
input.asExpr().getExpr().getEnclosingMethod() = handler and
41-
localFlowWithElementReference(input, sensitive) and
42-
not sensitive.getClassification() = SensitiveDataClassification::id()
43-
select input, "$@ for GET requests uses query parameter as sensitive data.", handler,
44-
"Route handler"
44+
config.hasFlowPath(source, sink) and
45+
not sink.getNode().(SensitiveNode).getClassification() = SensitiveDataClassification::id()
46+
select source.getNode(), source, sink,
47+
"$@ for GET requests uses query parameter as sensitive data.",
48+
source.getNode().(Source).getHandler(), "Route handler"
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
| app/controllers/users_controller.rb:4:16:4:21 | call to params | $@ for GET requests uses query parameter as sensitive data. | app/controllers/users_controller.rb:3:3:6:5 | login_get | Route handler |
1+
| app/controllers/users_controller.rb:4:16:4:21 | call to params | app/controllers/users_controller.rb:4:16:4:21 | call to params : | app/controllers/users_controller.rb:4:16:4:32 | ...[...] | $@ for GET requests uses query parameter as sensitive data. | app/controllers/users_controller.rb:3:3:6:5 | login_get | Route handler |
2+
| app/controllers/users_controller.rb:4:16:4:21 | call to params | app/controllers/users_controller.rb:4:16:4:21 | call to params : | app/controllers/users_controller.rb:5:42:5:49 | password | $@ for GET requests uses query parameter as sensitive data. | app/controllers/users_controller.rb:3:3:6:5 | login_get | Route handler |

0 commit comments

Comments
 (0)