@@ -11,21 +11,46 @@ private import ParseRegex
1111private import codeql.swift.regex.Regex
1212
1313/**
14- * A data flow configuration for tracking string literals that are used as
15- * regular expressions.
14+ * A data flow configuration for tracking string literals that are used to
15+ * create regular expression objects, or are evaluated directly as regular
16+ * expressions.
1617 */
1718private module StringLiteralUseConfig implements DataFlow:: ConfigSig {
1819 predicate isSource ( DataFlow:: Node node ) { node .asExpr ( ) instanceof StringLiteralExpr }
1920
20- predicate isSink ( DataFlow:: Node node ) { node .asExpr ( ) = any ( RegexEval eval ) .getRegexInput ( ) }
21+ predicate isSink ( DataFlow:: Node node ) {
22+ // evaluated directly as a regular expression
23+ node .asExpr ( ) = any ( RegexEval eval ) .getRegexInput ( )
24+ or
25+ // used to create a regular expression object
26+ node = any ( RegexCreation regexCreation ) .getStringInput ( )
27+ }
28+ }
2129
22- predicate isAdditionalFlowStep ( DataFlow:: Node nodeFrom , DataFlow:: Node nodeTo ) {
23- // flow through `Regex` initializer, i.e. from a string to a `Regex` object.
30+ module StringLiteralUseFlow = DataFlow:: Global< StringLiteralUseConfig > ;
31+
32+ /**
33+ * A data flow configuration for tracking regular expression objects from
34+ * creation to the point of use.
35+ */
36+ private module RegexUseConfig implements DataFlow:: ConfigSig {
37+ predicate isSource ( DataFlow:: Node node ) {
38+ // creation of the regex
2439 exists ( RegexCreation regexCreation |
25- nodeFrom = regexCreation .getStringInput ( ) and
26- nodeTo = regexCreation
40+ node = regexCreation
2741 )
42+ // TODO: track parse mode flags.
43+ }
44+
45+ predicate isSink ( DataFlow:: Node node ) {
46+ // evaluation of the regex
47+ node .asExpr ( ) = any ( RegexEval eval ) .getRegexInput ( )
48+ }
49+
50+ predicate isAdditionalFlowStep ( DataFlow:: Node nodeFrom , DataFlow:: Node nodeTo ) {
51+ // TODO: flow through regex methods that return a modified regex.
52+ none ( )
2853 }
2954}
3055
31- module StringLiteralUseFlow = DataFlow:: Global< StringLiteralUseConfig > ;
56+ module RegexUseFlow = DataFlow:: Global< RegexUseConfig > ;
0 commit comments