mirror of
https://github.com/github/codeql.git
synced 2026-04-28 18:25:24 +02:00
Ruby: Restrict regexp taint flow to String summaries
This commit is contained in:
@@ -735,6 +735,9 @@ class SummaryNode extends NodeImpl, TSummaryNode {
|
||||
|
||||
SummaryNode() { this = TSummaryNode(c, state) }
|
||||
|
||||
/** Gets the summarized callable that this node belongs to. */
|
||||
FlowSummaryImpl::Public::SummarizedCallable getSummarizedCallable() { result = c }
|
||||
|
||||
override CfgScope getCfgScope() { none() }
|
||||
|
||||
override DataFlowCallable getEnclosingCallable() { result.asLibraryCallable() = c }
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
private import codeql.ruby.AST
|
||||
private import codeql.ruby.ApiGraphs
|
||||
private import codeql.ruby.DataFlow
|
||||
private import codeql.ruby.dataflow.FlowSummary
|
||||
private import codeql.ruby.dataflow.FlowSummary as FlowSummary
|
||||
private import codeql.ruby.dataflow.internal.DataFlowDispatch
|
||||
private import codeql.ruby.controlflow.CfgNodes
|
||||
private import codeql.ruby.Regexp as RE
|
||||
@@ -107,6 +107,18 @@ module String {
|
||||
preservesValue = false
|
||||
}
|
||||
|
||||
/** A `String` callable with a flow summary. */
|
||||
abstract class SummarizedCallable extends FlowSummary::SummarizedCallable {
|
||||
bindingset[this]
|
||||
SummarizedCallable() { any() }
|
||||
}
|
||||
|
||||
abstract private class SimpleSummarizedCallable extends SummarizedCallable,
|
||||
FlowSummary::SimpleSummarizedCallable {
|
||||
bindingset[this]
|
||||
SimpleSummarizedCallable() { any() }
|
||||
}
|
||||
|
||||
private class NewSummary extends SummarizedCallable {
|
||||
NewSummary() { this = "String.new" }
|
||||
|
||||
|
||||
@@ -5,6 +5,10 @@ private import codeql.ruby.controlflow.CfgNodes
|
||||
private import codeql.ruby.dataflow.internal.tainttrackingforregexp.TaintTrackingImpl
|
||||
private import codeql.ruby.typetracking.TypeTracker
|
||||
private import codeql.ruby.ApiGraphs
|
||||
private import codeql.ruby.dataflow.internal.DataFlowPrivate as DataFlowPrivate
|
||||
private import codeql.ruby.dataflow.internal.FlowSummaryImpl as FlowSummaryImpl
|
||||
private import codeql.ruby.dataflow.FlowSummary as FlowSummary
|
||||
private import codeql.ruby.frameworks.core.String
|
||||
|
||||
class RegExpConfiguration extends Configuration {
|
||||
RegExpConfiguration() { this = "RegExpConfiguration" }
|
||||
@@ -30,6 +34,11 @@ class RegExpConfiguration extends Configuration {
|
||||
node = mce.getArgument(0) and
|
||||
mce.getReceiver() = trackRegexpType()
|
||||
)
|
||||
or
|
||||
// only include taint flow through `String` summaries
|
||||
FlowSummaryImpl::Private::Steps::summaryLocalStep(_, node, false) and
|
||||
not node.(DataFlowPrivate::SummaryNode).getSummarizedCallable() instanceof
|
||||
String::SummarizedCallable
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user