11private import codeql.ruby.Regexp
2- private import codeql.ruby.ast.Literal as Ast
2+ private import codeql.ruby.AST as Ast
3+ private import codeql.ruby.CFG
34private import codeql.ruby.DataFlow
45private import codeql.ruby.controlflow.CfgNodes
5- private import codeql.ruby.dataflow.internal.tainttrackingforregexp.TaintTrackingImpl
6+ private import codeql.ruby.dataflow.internal.DataFlowImplForRegExp
67private import codeql.ruby.typetracking.TypeTracker
78private import codeql.ruby.ApiGraphs
89private import codeql.ruby.dataflow.internal.DataFlowPrivate as DataFlowPrivate
@@ -24,7 +25,7 @@ class RegExpConfiguration extends Configuration {
2425
2526 override predicate isSink ( DataFlow:: Node sink ) { sink instanceof RegExpInterpretation:: Range }
2627
27- override predicate isSanitizer ( DataFlow:: Node node ) {
28+ override predicate isBarrier ( DataFlow:: Node node ) {
2829 exists ( DataFlow:: CallNode mce | mce .getMethodName ( ) = [ "match" , "match?" ] |
2930 // receiver of https://ruby-doc.org/core-2.4.0/String.html#method-i-match
3031 node = mce .getReceiver ( ) and
@@ -34,11 +35,24 @@ class RegExpConfiguration extends Configuration {
3435 node = mce .getArgument ( 0 ) and
3536 mce .getReceiver ( ) = trackRegexpType ( )
3637 )
37- or
38- // only include taint flow through `String` summaries
39- FlowSummaryImpl:: Private:: Steps:: summaryLocalStep ( _, node , false ) and
40- not node .( DataFlowPrivate:: SummaryNode ) .getSummarizedCallable ( ) instanceof
38+ }
39+
40+ override predicate isAdditionalFlowStep ( DataFlow:: Node nodeFrom , DataFlow:: Node nodeTo ) {
41+ // include taint flow through `String` summaries,
42+ FlowSummaryImpl:: Private:: Steps:: summaryLocalStep ( nodeFrom , nodeTo , false ) and
43+ nodeFrom .( DataFlowPrivate:: SummaryNode ) .getSummarizedCallable ( ) instanceof
4144 String:: SummarizedCallable
45+ or
46+ // string concatenations, and
47+ exists ( CfgNodes:: ExprNodes:: OperationCfgNode op |
48+ op = nodeTo .asExpr ( ) and
49+ op .getAnOperand ( ) = nodeFrom .asExpr ( ) and
50+ op .getExpr ( ) .( Ast:: BinaryOperation ) .getOperator ( ) = "+"
51+ )
52+ or
53+ // string interpolations
54+ nodeFrom .asExpr ( ) =
55+ nodeTo .asExpr ( ) .( CfgNodes:: ExprNodes:: StringlikeLiteralCfgNode ) .getAComponent ( )
4256 }
4357}
4458
0 commit comments