Skip to content

Commit f222cc1

Browse files
committed
refactor the existing taint-step for string interpolation into StringFormatters.qll
1 parent 6de1abc commit f222cc1

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

ruby/ql/lib/codeql/ruby/dataflow/FlowSteps.qll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ private class Unit = DFPrivate::Unit;
1111
* A module importing the frameworks that implement additional flow steps,
1212
* ensuring that they are visible to the taint tracking library.
1313
*/
14-
private module Frameworks { }
14+
private module Frameworks {
15+
import codeql.ruby.frameworks.StringFormatters
16+
}
1517

1618
/**
1719
* A unit class for adding additional taint steps.

ruby/ql/lib/codeql/ruby/dataflow/internal/TaintTrackingPrivate.qll

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,6 @@ private module Cached {
9595
)
9696
)
9797
or
98-
// string interpolation of `nodeFrom` into `nodeTo`
99-
nodeFrom.asExpr() =
100-
nodeTo.asExpr().(CfgNodes::ExprNodes::StringlikeLiteralCfgNode).getAComponent()
101-
or
10298
FlowSummaryImpl::Private::Steps::summaryLocalStep(nodeFrom, nodeTo, false)
10399
or
104100
any(FlowSteps::AdditionalTaintStep s).step(nodeFrom, nodeTo)

ruby/ql/lib/codeql/ruby/frameworks/StringFormatters.qll

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,19 @@ class IOPrintfCall extends PrintfStyleCall {
7777

7878
override predicate returnsFormatted() { none() }
7979
}
80+
81+
private import codeql.ruby.dataflow.FlowSteps
82+
private import codeql.ruby.CFG
83+
84+
/**
85+
* A step for string interpolation of `pred` into `succ`.
86+
* E.g.
87+
* ```rb
88+
* succ = "foo #{pred} bar"
89+
* ```
90+
*/
91+
private class StringLiteralFormatStep extends AdditionalTaintStep {
92+
override predicate step(DataFlow::Node pred, DataFlow::Node succ) {
93+
pred.asExpr() = succ.asExpr().(CfgNodes::ExprNodes::StringlikeLiteralCfgNode).getAComponent()
94+
}
95+
}

0 commit comments

Comments
 (0)