@@ -11,21 +11,46 @@ private import ParseRegex
11
11
private import codeql.swift.regex.Regex
12
12
13
13
/**
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.
16
17
*/
17
18
private module StringLiteralUseConfig implements DataFlow:: ConfigSig {
18
19
predicate isSource ( DataFlow:: Node node ) { node .asExpr ( ) instanceof StringLiteralExpr }
19
20
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
+ }
21
29
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
24
39
exists ( RegexCreation regexCreation |
25
- nodeFrom = regexCreation .getStringInput ( ) and
26
- nodeTo = regexCreation
40
+ node = regexCreation
27
41
)
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 ( )
28
53
}
29
54
}
30
55
31
- module StringLiteralUseFlow = DataFlow:: Global< StringLiteralUseConfig > ;
56
+ module RegexUseFlow = DataFlow:: Global< RegexUseConfig > ;
0 commit comments