Skip to content

Commit 657642a

Browse files
committed
Java: Expose parts of the vquery message in the test.
1 parent 45a9d5b commit 657642a

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

java/ql/test/query-tests/security/CWE-730/ExpRedosTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,10 @@ class ExpRedosTest {
431431
"(a*)*b", // $ hasExpRedos
432432

433433
// BAD - but not detected due to the way possessive quantifiers are approximated
434-
"((aa|a*+)b)*c" // $ MISSING: hasExpRedos
434+
"((aa|a*+)b)*c", // $ MISSING: hasExpRedos
435+
436+
// BAD - testsing
437+
"(?is)(a|aa?)*b" // $ hasExpRedos hasPrefixMsg="starting with 'is' and " hasPump=a
435438
};
436439

437440
void test() {

java/ql/test/query-tests/security/CWE-730/ReDoS.ql

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@ private import semmle.code.java.regex.RegexTreeView::RegexTreeView as TreeView
44
import codeql.regex.nfa.ExponentialBackTracking::Make<TreeView> as ExponentialBackTracking
55
import semmle.code.java.regex.regex
66

7+
bindingset[s]
8+
string quote(string s) { if s.matches("% %") then result = "\"" + s + "\"" else result = s }
9+
710
module HasExpRedos implements TestSig {
8-
string getARelevantTag() { result = ["hasExpRedos", "hasParseFailure"] }
11+
string getARelevantTag() {
12+
result = ["hasExpRedos", "hasParseFailure", "hasPump", "hasPrefixMsg"]
13+
}
914

1015
predicate hasActualResult(Location location, string element, string tag, string value) {
1116
tag = "hasExpRedos" and
@@ -25,6 +30,22 @@ module HasExpRedos implements TestSig {
2530
element = r.toString()
2631
)
2732
}
33+
34+
predicate hasOptionalResult(Location location, string element, string tag, string value) {
35+
exists(TreeView::RegExpTerm t, Regex r, string pump, string prefixMsg |
36+
ExponentialBackTracking::hasReDoSResult(t, pump, _, prefixMsg) and
37+
t.occursInRegex(r, _, _) and
38+
(
39+
tag = "hasPrefixMsg" and
40+
value = quote(prefixMsg)
41+
or
42+
tag = "hasPump" and
43+
value = pump
44+
) and
45+
location = r.getLocation() and
46+
element = r.toString()
47+
)
48+
}
2849
}
2950

3051
import MakeTest<HasExpRedos>

0 commit comments

Comments
 (0)