We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 36cc7b5 commit 53d61c4Copy full SHA for 53d61c4
4 files changed
python/ql/src/experimental/Security/CWE-730/RegexInjection.ql
@@ -16,7 +16,13 @@ import python
16
import experimental.semmle.python.security.injection.RegexInjection
17
import DataFlow::PathGraph
18
19
-from RegexInjectionFlowConfig config, DataFlow::PathNode source, DataFlow::PathNode sink
20
-where config.hasFlowPath(source, sink)
21
-select sink.getNode(), source, sink, "$@ regular expression is constructed from a $@.",
22
- sink.getNode(), "This", source.getNode(), "user-provided value"
+from
+ RegexInjectionFlowConfig config, DataFlow::PathNode source, DataFlow::PathNode sink,
+ Attribute sinkAttribute
+where
23
+ config.hasFlowPath(source, sink) and
24
+ sinkAttribute = sink.getNode().(RegexInjectionSink).getRegexMethod()
25
+select sink.getNode(), source, sink,
26
+ "$@ regular expression is constructed from a $@ and executed by $@.", sink.getNode(), "This",
27
+ source.getNode(), "user-provided value", sinkAttribute,
28
+ sinkAttribute.getObject().toString() + "." + sinkAttribute.getName()
python/ql/src/experimental/semmle/python/Concepts.qll
@@ -76,3 +76,16 @@ class RegexEscape extends DataFlow::Node {
76
77
DataFlow::CallCfgNode getEscapeMethod() { result = range.getEscapeMethod() }
78
}
79
+
80
+class RegexInjectionSink extends DataFlow::Node {
81
+ Attribute regexMethod;
82
83
+ RegexInjectionSink() {
84
+ exists(RegexExecution reExec |
85
+ this = reExec.getRegexNode() and
86
+ regexMethod = reExec.getRegexMethod().getFunction().asExpr().(Attribute)
87
+ )
88
+ }
89
90
+ Attribute getRegexMethod() { result = regexMethod }
91
+}
python/ql/src/experimental/semmle/python/frameworks/Stdlib.qll
@@ -24,6 +24,7 @@ private module Re {
DataFlow::CallCfgNode regexMethod;
DirectRegex() {
+ // this.getLocation().getFile().getBaseName().regexpMatch("^re_(good|bad)\\.py$") and // debug
this = API::moduleImport("re").getMember(any(ReMethods m)).getACall() and
29
regexNode = this.getArg(0) and
30
regexMethod = this
@@ -41,6 +42,7 @@ private module Re {
41
42
43
CompiledRegex() {
44
exists(DataFlow::CallCfgNode patternCall, DataFlow::AttrRead reMethod |
45
46
this.getFunction() = reMethod and
47
patternCall = API::moduleImport("re").getMember("compile").getACall() and
48
patternCall = reMethod.getObject().getALocalSource() and
python/ql/src/experimental/semmle/python/security/injection/RegexInjection.qll
@@ -8,7 +8,6 @@ import experimental.semmle.python.Concepts
8
import semmle.python.dataflow.new.DataFlow
9
import semmle.python.dataflow.new.TaintTracking
10
import semmle.python.dataflow.new.RemoteFlowSources
11
-import semmle.python.ApiGraphs
12
13
/**
14
* A taint-tracking configuration for detecting regular expression injections.
@@ -18,7 +17,7 @@ class RegexInjectionFlowConfig extends TaintTracking::Configuration {
override predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
- override predicate isSink(DataFlow::Node sink) { sink = any(RegexExecution re).getRegexNode() }
+ override predicate isSink(DataFlow::Node sink) { sink instanceof RegexInjectionSink }
override predicate isSanitizer(DataFlow::Node sanitizer) {
sanitizer = any(RegexEscape reEscape).getRegexNode()
0 commit comments