Skip to content

Commit 43fec9d

Browse files
committed
Revert "Ruby: switch rb/sensitive-get-query back to using local flow"
This reverts commit fa58c51.
1 parent 139d386 commit 43fec9d

File tree

4 files changed

+106
-27
lines changed

4 files changed

+106
-27
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* Provides default sources and sinks for reasoning about sensitive data sourced
3+
* from the query string of a GET request, as well as extension points for
4+
* adding your own.
5+
*/
6+
7+
private import codeql.ruby.security.SensitiveActions
8+
private import codeql.ruby.Concepts
9+
private import codeql.ruby.DataFlow
10+
11+
/**
12+
* Provides default sources and sinks for reasoning about sensitive data sourced
13+
* from the query string of a GET request, as well as extension points for
14+
* adding your own.
15+
*/
16+
module SensitiveGetQuery {
17+
/**
18+
* A data flow source representing data sourced from the query string in a
19+
* GET request handler.
20+
*/
21+
abstract class Source extends DataFlow::Node {
22+
/** Gets the request handler corresponding to this data source. */
23+
abstract Http::Server::RequestHandler getHandler();
24+
}
25+
26+
/**
27+
* An access to data from the query string of a GET request as a data flow
28+
* source.
29+
*/
30+
private class RequestInputAccessSource extends Source instanceof Http::Server::RequestInputAccess {
31+
private Http::Server::RequestHandler handler;
32+
33+
RequestInputAccessSource() {
34+
handler = this.asExpr().getExpr().getEnclosingMethod() and
35+
handler.getAnHttpMethod() = "get" and
36+
this.getKind() = "parameter"
37+
}
38+
39+
override Http::Server::RequestHandler getHandler() { result = handler }
40+
}
41+
42+
/**
43+
* A data flow sink suggesting a use of sensitive data.
44+
*/
45+
abstract class Sink extends DataFlow::Node { }
46+
47+
/** A sensitive data node as a data flow sink. */
48+
private class SensitiveNodeSink extends Sink instanceof SensitiveNode {
49+
SensitiveNodeSink() {
50+
// User names and other similar information is not sensitive in this context.
51+
not this.getClassification() = SensitiveDataClassification::id()
52+
}
53+
}
54+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* Provides a taint-tracking configuration for detecting flow of query string
3+
* data to sensitive actions in GET query request handlers.
4+
*
5+
* Note, for performance reasons: only import this file if `Configuration` is
6+
* needed, otherwise `SensitiveGetQueryCustomizations` should be imported
7+
* instead.
8+
*/
9+
10+
private import ruby
11+
private import codeql.ruby.TaintTracking
12+
13+
/**
14+
* Provides a taint-tracking configuration for detecting flow of query string
15+
* data to sensitive actions in GET query request handlers.
16+
*/
17+
module SensitiveGetQuery {
18+
import SensitiveGetQueryCustomizations::SensitiveGetQuery
19+
20+
/**
21+
* A taint-tracking configuration for reasoning about use of sensitive data
22+
* from a GET request query string.
23+
*/
24+
class Configuration extends TaintTracking::Configuration {
25+
Configuration() { this = "SensitiveGetQuery" }
26+
27+
override predicate isSource(DataFlow::Node source) { source instanceof Source }
28+
29+
override predicate isSink(DataFlow::Node sink) { sink instanceof Sink }
30+
}
31+
}

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

Lines changed: 8 additions & 26 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
@@ -12,30 +12,12 @@
1212
*/
1313

1414
import ruby
15-
import codeql.ruby.Concepts
15+
import DataFlow::PathGraph
16+
import codeql.ruby.security.SensitiveGetQueryQuery
1617
import codeql.ruby.security.SensitiveActions
1718

18-
// Local flow augmented with flow through element references
19-
private predicate localFlowWithElementReference(DataFlow::LocalSourceNode src, DataFlow::Node to) {
20-
src.flowsTo(to)
21-
or
22-
exists(DataFlow::Node midRecv, DataFlow::LocalSourceNode mid, Ast::ElementReference ref |
23-
src.flowsTo(midRecv) and
24-
midRecv.asExpr().getExpr() = ref.getReceiver() and
25-
mid.asExpr().getExpr() = ref
26-
|
27-
localFlowWithElementReference(mid, to)
28-
)
29-
}
30-
31-
from
32-
Http::Server::RequestHandler handler, Http::Server::RequestInputAccess input,
33-
SensitiveNode sensitive
34-
where
35-
handler.getAnHttpMethod() = "get" and
36-
input.asExpr().getExpr().getEnclosingMethod() = handler and
37-
input.getKind() = "parameter" and
38-
localFlowWithElementReference(input, sensitive) and
39-
not sensitive.getClassification() = SensitiveDataClassification::id()
40-
select input, "$@ for GET requests uses query parameter as sensitive data.", handler,
41-
"Route handler"
19+
from DataFlow::PathNode source, DataFlow::PathNode sink, SensitiveGetQuery::Configuration config
20+
where config.hasFlowPath(source, sink)
21+
select source.getNode(), source, sink,
22+
"$@ for GET requests uses query parameter as sensitive data.",
23+
source.getNode().(SensitiveGetQuery::Source).getHandler(), "Route handler"
Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,13 @@
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+
edges
2+
| app/controllers/users_controller.rb:4:16:4:21 | call to params : | app/controllers/users_controller.rb:4:16:4:32 | ...[...] |
3+
| app/controllers/users_controller.rb:4:16:4:21 | call to params : | app/controllers/users_controller.rb:4:16:4:32 | ...[...] : |
4+
| app/controllers/users_controller.rb:4:16:4:32 | ...[...] : | app/controllers/users_controller.rb:5:42:5:49 | password |
5+
nodes
6+
| app/controllers/users_controller.rb:4:16:4:21 | call to params : | semmle.label | call to params : |
7+
| app/controllers/users_controller.rb:4:16:4:32 | ...[...] | semmle.label | ...[...] |
8+
| app/controllers/users_controller.rb:4:16:4:32 | ...[...] : | semmle.label | ...[...] : |
9+
| app/controllers/users_controller.rb:5:42:5:49 | password | semmle.label | password |
10+
subpaths
11+
#select
12+
| 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 |
13+
| 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)