add some more meta queries for Ruby evaluations

This commit is contained in:
erik-krogh
2022-10-06 10:14:28 +02:00
parent 0e6735b804
commit db056aae1b
3 changed files with 52 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
/**
* @name Taint steps
* @description The number of default taint steps.
* @kind metric
* @metricType project
* @metricAggregate sum
* @tags meta
* @id rb/meta/taint-steps
*/
import ruby
import internal.TaintMetrics
import codeql.ruby.dataflow.internal.TaintTrackingPublic
predicate relevantStep(DataFlow::Node pred, DataFlow::Node succ) { localTaintStep(pred, succ) }
select projectRoot(), count(DataFlow::Node pred, DataFlow::Node succ | relevantStep(pred, succ))

View File

@@ -0,0 +1,28 @@
/**
* @name Tainted nodes
* @description Nodes reachable from a remote flow source via default taint-tracking steps.
* @kind problem
* @problem.severity recommendation
* @id rb/meta/tainted-nodes
* @tags meta
* @precision very-low
*/
import internal.TaintMetrics
import codeql.ruby.DataFlow
import codeql.ruby.TaintTracking
class BasicTaintConfiguration extends TaintTracking::Configuration {
BasicTaintConfiguration() { this = "BasicTaintConfiguration" }
override predicate isSource(DataFlow::Node node) { node = relevantTaintSource(_) }
override predicate isSink(DataFlow::Node node) {
// To reduce noise from synthetic nodes, only count nodes that have an associated expression.
exists(node.asExpr().getExpr())
}
}
from DataFlow::Node node
where any(BasicTaintConfiguration cfg).hasFlow(_, node)
select node, "Tainted node"

View File

@@ -36,3 +36,10 @@ DataFlow::Node relevantTaintSink(string kind) {
kind = "UrlRedirect" and result instanceof UrlRedirect::Sink
)
}
/**
* Gets the root folder of the snapshot.
*
* This is selected as the location for project-wide metrics.
*/
Folder projectRoot() { result.getRelativePath() = "" }