@@ -136,24 +136,22 @@ private class GuavaRegexFlowStep extends RegexAdditionalFlowStep {
136
136
}
137
137
}
138
138
139
- private class RegexFlowConf extends DataFlow2 :: Configuration {
140
- RegexFlowConf ( ) { this = "RegexFlowConfig" }
139
+ private module RegexFlowConfig implements DataFlow :: ConfigSig {
140
+ predicate isSource ( DataFlow :: Node node ) { node . asExpr ( ) instanceof ExploitableStringLiteral }
141
141
142
- override predicate isSource ( DataFlow:: Node node ) {
143
- node .asExpr ( ) instanceof ExploitableStringLiteral
144
- }
145
-
146
- override predicate isSink ( DataFlow:: Node node ) { node instanceof RegexFlowSink }
142
+ predicate isSink ( DataFlow:: Node node ) { node instanceof RegexFlowSink }
147
143
148
- override predicate isAdditionalFlowStep ( DataFlow:: Node node1 , DataFlow:: Node node2 ) {
144
+ predicate isAdditionalFlowStep ( DataFlow:: Node node1 , DataFlow:: Node node2 ) {
149
145
any ( RegexAdditionalFlowStep s ) .step ( node1 , node2 )
150
146
}
151
147
152
- override predicate isBarrier ( DataFlow:: Node node ) {
148
+ predicate isBarrier ( DataFlow:: Node node ) {
153
149
node .getEnclosingCallable ( ) .getDeclaringType ( ) instanceof NonSecurityTestClass
154
150
}
155
151
}
156
152
153
+ private module RegexFlow = DataFlow:: Global< RegexFlowConfig > ;
154
+
157
155
/**
158
156
* Holds if `regex` is used as a regex, with the mode `mode` (if known).
159
157
* If regex mode is not known, `mode` will be `"None"`.
@@ -162,7 +160,7 @@ private class RegexFlowConf extends DataFlow2::Configuration {
162
160
* and therefore may be relevant for ReDoS queries are considered.
163
161
*/
164
162
predicate usedAsRegex ( StringLiteral regex , string mode , boolean match_full_string ) {
165
- any ( RegexFlowConf c ) . hasFlow ( DataFlow2 :: exprNode ( regex ) , _) and
163
+ RegexFlow :: flow ( DataFlow :: exprNode ( regex ) , _) and
166
164
mode = "None" and // TODO: proper mode detection
167
165
( if matchesFullString ( regex ) then match_full_string = true else match_full_string = false )
168
166
}
@@ -172,9 +170,9 @@ predicate usedAsRegex(StringLiteral regex, string mode, boolean match_full_strin
172
170
* as though it was implicitly surrounded by ^ and $.
173
171
*/
174
172
private predicate matchesFullString ( StringLiteral regex ) {
175
- exists ( RegexFlowConf c , RegexFlowSink sink |
173
+ exists ( RegexFlowSink sink |
176
174
sink .matchesFullString ( ) and
177
- c . hasFlow ( DataFlow2 :: exprNode ( regex ) , sink )
175
+ RegexFlow :: flow ( DataFlow :: exprNode ( regex ) , sink )
178
176
)
179
177
}
180
178
@@ -185,8 +183,8 @@ private predicate matchesFullString(StringLiteral regex) {
185
183
* and therefore may be relevant for ReDoS queries are considered.
186
184
*/
187
185
predicate regexMatchedAgainst ( StringLiteral regex , Expr str ) {
188
- exists ( RegexFlowConf c , RegexFlowSink sink |
186
+ exists ( RegexFlowSink sink |
189
187
str = sink .getStringArgument ( ) and
190
- c . hasFlow ( DataFlow2 :: exprNode ( regex ) , sink )
188
+ RegexFlow :: flow ( DataFlow :: exprNode ( regex ) , sink )
191
189
)
192
190
}
0 commit comments