Skip to content

Commit dd03d81

Browse files
authored
Merge pull request github#6300 from RasmusWL/redos-tests
Python: Fix `py/polynomial-redos`
2 parents 712b0d8 + a5834c4 commit dd03d81

File tree

9 files changed

+24
-2
lines changed

9 files changed

+24
-2
lines changed

python/ql/src/semmle/python/security/dataflow/PolynomialReDoSCustomizations.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ module PolynomialReDoS {
5656
/**
5757
* A regex execution, considered as a flow sink.
5858
*/
59-
class RegexExecutionAsSink extends DataFlow::Node {
59+
class RegexExecutionAsSink extends Sink {
6060
RegExpTerm t;
6161

6262
RegexExecutionAsSink() {
@@ -68,7 +68,7 @@ module PolynomialReDoS {
6868
}
6969

7070
/** Gets the regex that is being executed by this node. */
71-
RegExpTerm getRegExp() { result = t }
71+
override RegExpTerm getRegExp() { result = t }
7272
}
7373

7474
/**
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
edges
2+
| test.py:7:12:7:18 | ControlFlowNode for request | test.py:7:12:7:23 | ControlFlowNode for Attribute |
3+
| test.py:7:12:7:23 | ControlFlowNode for Attribute | test.py:8:30:8:33 | ControlFlowNode for text |
4+
| test.py:7:12:7:23 | ControlFlowNode for Attribute | test.py:9:32:9:35 | ControlFlowNode for text |
5+
nodes
6+
| test.py:7:12:7:18 | ControlFlowNode for request | semmle.label | ControlFlowNode for request |
7+
| test.py:7:12:7:23 | ControlFlowNode for Attribute | semmle.label | ControlFlowNode for Attribute |
8+
| test.py:8:30:8:33 | ControlFlowNode for text | semmle.label | ControlFlowNode for text |
9+
| test.py:9:32:9:35 | ControlFlowNode for text | semmle.label | ControlFlowNode for text |
10+
#select
11+
| test.py:8:30:8:33 | ControlFlowNode for text | test.py:7:12:7:18 | ControlFlowNode for request | test.py:8:30:8:33 | ControlFlowNode for text | This $@ that depends on $@ may run slow on strings with many repetitions of ' '. | test.py:8:21:8:23 | \\s+ | regular expression | test.py:7:12:7:18 | ControlFlowNode for request | a user-provided value |
12+
| test.py:9:32:9:35 | ControlFlowNode for text | test.py:7:12:7:18 | ControlFlowNode for request | test.py:9:32:9:35 | ControlFlowNode for text | This $@ that depends on $@ may run slow on strings with many repetitions of '99'. | test.py:9:27:9:29 | \\d+ | regular expression | test.py:7:12:7:18 | ControlFlowNode for request | a user-provided value |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Security/CWE-730/PolynomialReDoS.ql
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import re
2+
from flask import Flask, request
3+
app = Flask(__name__)
4+
5+
@app.route("/poly-redos")
6+
def code_execution():
7+
text = request.args.get("text")
8+
re.sub(r"^\s+|\s+$", "", text) # NOT OK
9+
re.match(r"^0\.\d+E?\d+$", text) # NOT OK

0 commit comments

Comments
 (0)