@@ -9,91 +9,3 @@ private import semmle.python.dataflow.new.TaintTracking
99private import semmle.python.dataflow.new.RemoteFlowSources
1010private import experimental.semmle.python.Concepts
1111private import semmle.python.ApiGraphs
12-
13- /**
14- * Provides models for Python's `re` library.
15- *
16- * See https://docs.python.org/3/library/re.html
17- */
18- private module Re {
19- /**
20- * List of `re` methods immediately executing an expression.
21- *
22- * See https://docs.python.org/3/library/re.html#module-contents
23- */
24- private class RegexExecutionMethods extends string {
25- RegexExecutionMethods ( ) {
26- this in [ "match" , "fullmatch" , "search" , "split" , "findall" , "finditer" , "sub" , "subn" ]
27- }
28- }
29-
30- /**
31- * A class to find `re` methods immediately executing an expression.
32- *
33- * See `RegexExecutionMethods`
34- */
35- private class DirectRegex extends DataFlow:: CallCfgNode , RegexExecution:: Range {
36- DataFlow:: Node regexNode ;
37-
38- DirectRegex ( ) {
39- this = API:: moduleImport ( "re" ) .getMember ( any ( RegexExecutionMethods m ) ) .getACall ( ) and
40- regexNode = this .getArg ( 0 )
41- }
42-
43- override DataFlow:: Node getRegexNode ( ) { result = regexNode }
44-
45- override string getRegexModule ( ) { result = "re" }
46- }
47-
48- /**
49- * A class to find `re` methods immediately executing a compiled expression by `re.compile`.
50- *
51- * Given the following example:
52- *
53- * ```py
54- * pattern = re.compile(input)
55- * pattern.match(s)
56- * ```
57- *
58- * This class will identify that `re.compile` compiles `input` and afterwards
59- * executes `re`'s `match`. As a result, `this` will refer to `pattern.match(s)`
60- * and `this.getRegexNode()` will return the node for `input` (`re.compile`'s first argument)
61- *
62- *
63- * See `RegexExecutionMethods`
64- *
65- * See https://docs.python.org/3/library/re.html#regular-expression-objects
66- */
67- private class CompiledRegex extends DataFlow:: MethodCallNode , RegexExecution:: Range {
68- DataFlow:: Node regexNode ;
69-
70- CompiledRegex ( ) {
71- exists ( DataFlow:: MethodCallNode patternCall |
72- patternCall = API:: moduleImport ( "re" ) .getMember ( "compile" ) .getACall ( ) and
73- patternCall .flowsTo ( this .getObject ( ) ) and
74- this .getMethodName ( ) instanceof RegexExecutionMethods and
75- regexNode = patternCall .getArg ( 0 )
76- )
77- }
78-
79- override DataFlow:: Node getRegexNode ( ) { result = regexNode }
80-
81- override string getRegexModule ( ) { result = "re" }
82- }
83-
84- /**
85- * A class to find `re` methods escaping an expression.
86- *
87- * See https://docs.python.org/3/library/re.html#re.escape
88- */
89- class ReEscape extends DataFlow:: CallCfgNode , RegexEscape:: Range {
90- DataFlow:: Node regexNode ;
91-
92- ReEscape ( ) {
93- this = API:: moduleImport ( "re" ) .getMember ( "escape" ) .getACall ( ) and
94- regexNode = this .getArg ( 0 )
95- }
96-
97- override DataFlow:: Node getRegexNode ( ) { result = regexNode }
98- }
99- }
0 commit comments