Skip to content

Commit 975ce06

Browse files
committed
Python: implement for polynomial redos
1 parent 15c2ccb commit 975ce06

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ module PolynomialReDoS {
3535
/** Gets the regex that is being executed by this node. */
3636
abstract RegExpTerm getRegExp();
3737

38+
/** Gets a term within the regexp that may perform polynomial back-tracking. */
39+
final PolynomialBackTrackingTerm getABacktrackingTerm() {
40+
result.getRootTerm() = this.getRegExp()
41+
}
42+
3843
/**
3944
* Gets the node to highlight in the alert message.
4045
*/

python/ql/lib/semmle/python/security/dataflow/PolynomialReDoSQuery.qll

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ private module PolynomialReDoSConfig implements DataFlow::ConfigSig {
1818

1919
predicate isBarrier(DataFlow::Node node) { node instanceof Sanitizer }
2020

21-
predicate observeDiffInformedIncrementalMode() {
22-
// TODO(diff-informed): Manually verify if config can be diff-informed.
23-
// ql/src/Security/CWE-730/PolynomialReDoS.ql:31: Column 1 selects sink.getHighlight
24-
// ql/src/Security/CWE-730/PolynomialReDoS.ql:33: Column 5 does not select a source or sink originating from the flow call on line 24
25-
none()
21+
predicate observeDiffInformedIncrementalMode() { any() }
22+
23+
Location getASelectedSinkLocation(DataFlow::Node sink) {
24+
result = sink.(Sink).getHighlight().getLocation()
25+
or
26+
result = sink.(Sink).getABacktrackingTerm().getLocation()
2627
}
2728
}
2829

python/ql/src/Security/CWE-730/PolynomialReDoS.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ from
2323
where
2424
PolynomialReDoSFlow::flowPath(source, sink) and
2525
sinkNode = sink.getNode() and
26-
regexp.getRootTerm() = sinkNode.getRegExp()
26+
regexp = sinkNode.getABacktrackingTerm()
2727
// not (
2828
// source.getNode().(Source).getKind() = "url" and
2929
// regexp.isAtEndLine()

0 commit comments

Comments
 (0)