Skip to content

Commit db056aa

Browse files
committed
add some more meta queries for Ruby evaluations
1 parent 0e6735b commit db056aa

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* @name Taint steps
3+
* @description The number of default taint steps.
4+
* @kind metric
5+
* @metricType project
6+
* @metricAggregate sum
7+
* @tags meta
8+
* @id rb/meta/taint-steps
9+
*/
10+
11+
import ruby
12+
import internal.TaintMetrics
13+
import codeql.ruby.dataflow.internal.TaintTrackingPublic
14+
15+
predicate relevantStep(DataFlow::Node pred, DataFlow::Node succ) { localTaintStep(pred, succ) }
16+
17+
select projectRoot(), count(DataFlow::Node pred, DataFlow::Node succ | relevantStep(pred, succ))
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* @name Tainted nodes
3+
* @description Nodes reachable from a remote flow source via default taint-tracking steps.
4+
* @kind problem
5+
* @problem.severity recommendation
6+
* @id rb/meta/tainted-nodes
7+
* @tags meta
8+
* @precision very-low
9+
*/
10+
11+
import internal.TaintMetrics
12+
import codeql.ruby.DataFlow
13+
import codeql.ruby.TaintTracking
14+
15+
class BasicTaintConfiguration extends TaintTracking::Configuration {
16+
BasicTaintConfiguration() { this = "BasicTaintConfiguration" }
17+
18+
override predicate isSource(DataFlow::Node node) { node = relevantTaintSource(_) }
19+
20+
override predicate isSink(DataFlow::Node node) {
21+
// To reduce noise from synthetic nodes, only count nodes that have an associated expression.
22+
exists(node.asExpr().getExpr())
23+
}
24+
}
25+
26+
from DataFlow::Node node
27+
where any(BasicTaintConfiguration cfg).hasFlow(_, node)
28+
select node, "Tainted node"

ruby/ql/src/queries/meta/internal/TaintMetrics.qll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,10 @@ DataFlow::Node relevantTaintSink(string kind) {
3636
kind = "UrlRedirect" and result instanceof UrlRedirect::Sink
3737
)
3838
}
39+
40+
/**
41+
* Gets the root folder of the snapshot.
42+
*
43+
* This is selected as the location for project-wide metrics.
44+
*/
45+
Folder projectRoot() { result.getRelativePath() = "" }

0 commit comments

Comments
 (0)