|
2 | 2 | * @name Sensitive data read from GET request |
3 | 3 | * @description Placing sensitive data in a GET request increases the risk of |
4 | 4 | * the data being exposed to an attacker. |
5 | | - * @kind problem |
| 5 | + * @kind path-problem |
6 | 6 | * @problem.severity warning |
7 | 7 | * @security-severity 6.5 |
8 | 8 | * @precision high |
|
13 | 13 |
|
14 | 14 | import ruby |
15 | 15 | private import codeql.ruby.DataFlow |
| 16 | +private import codeql.ruby.TaintTracking |
16 | 17 | private import codeql.ruby.security.SensitiveActions |
17 | 18 | private import codeql.ruby.Concepts |
18 | 19 | private import codeql.ruby.frameworks.ActionDispatch |
19 | 20 | private import codeql.ruby.frameworks.ActionController |
20 | 21 | private import codeql.ruby.frameworks.core.Array |
21 | 22 |
|
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 } |
33 | 40 | } |
34 | 41 |
|
35 | | -from |
36 | | - Http::Server::RequestHandler handler, Http::Server::RequestInputAccess input, |
37 | | - SensitiveNode sensitive |
| 42 | +from DataFlow::PathNode source, DataFlow::PathNode sink, Configuration config |
38 | 43 | 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" |
0 commit comments