Skip to content

Commit 32b1400

Browse files
Jami CogswellJami Cogswell
authored andcommitted
move files out of experimental
1 parent 53b7584 commit 32b1400

File tree

8 files changed

+21
-5
lines changed

8 files changed

+21
-5
lines changed

java/ql/src/experimental/Security/CWE/CWE-730/RegexInjection.java renamed to java/ql/src/Security/CWE/CWE-730/RegexInjection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ public String string2(@RequestParam(value = "input", defaultValue = "test") Stri
3535
String escapeSpecialRegexChars(String str) {
3636
return SPECIAL_REGEX_CHARS.matcher(str).replaceAll("\\\\$0");
3737
}
38-
}
38+
}

java/ql/src/experimental/Security/CWE/CWE-730/RegexInjection.ql renamed to java/ql/src/Security/CWE/CWE-730/RegexInjection.ql

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,24 @@ class RegexSink extends DataFlow::ExprNode {
2727
m.getDeclaringType() instanceof TypeString and
2828
(
2929
ma.getArgument(0) = this.asExpr() and
30+
// TODO: confirm if more/less than the below need to be handled
3031
m.hasName(["matches", "split", "replaceFirst", "replaceAll"])
3132
)
3233
or
34+
// TODO: review Java Pattern API
3335
m.getDeclaringType().hasQualifiedName("java.util.regex", "Pattern") and
3436
(
3537
ma.getArgument(0) = this.asExpr() and
38+
// TODO: confirm if more/less than the below need to be handled
3639
m.hasName(["compile", "matches"])
3740
)
3841
or
42+
// TODO: read docs about regex APIs in Java
3943
m.getDeclaringType().hasQualifiedName("org.apache.commons.lang3", "RegExUtils") and
4044
(
4145
ma.getArgument(1) = this.asExpr() and
4246
m.getParameterType(1) instanceof TypeString and
47+
// TODO: confirm if more/less than the below need to be handled
4348
m.hasName([
4449
"removeAll", "removeFirst", "removePattern", "replaceAll", "replaceFirst",
4550
"replacePattern"
@@ -50,6 +55,7 @@ class RegexSink extends DataFlow::ExprNode {
5055
}
5156
}
5257

58+
// TODO: is this abstract class needed? Are there pre-existing sanitizer classes that can be used instead?
5359
abstract class Sanitizer extends DataFlow::ExprNode { }
5460

5561
/**
@@ -60,12 +66,12 @@ class RegExpSanitizationCall extends Sanitizer {
6066
RegExpSanitizationCall() {
6167
exists(string calleeName, string sanitize, string regexp |
6268
calleeName = this.asExpr().(Call).getCallee().getName() and
63-
sanitize = "(?:escape|saniti[sz]e)" and
64-
regexp = "regexp?"
69+
sanitize = "(?:escape|saniti[sz]e)" and // TODO: confirm this is sufficient
70+
regexp = "regexp?" // TODO: confirm this is sufficient
6571
|
6672
calleeName
6773
.regexpMatch("(?i)(" + sanitize + ".*" + regexp + ".*)" + "|(" + regexp + ".*" + sanitize +
68-
".*)")
74+
".*)") // TODO: confirm this is sufficient
6975
)
7076
}
7177
}
@@ -87,3 +93,13 @@ from DataFlow::PathNode source, DataFlow::PathNode sink, RegexInjectionConfigura
8793
where c.hasFlowPath(source, sink)
8894
select sink.getNode(), source, sink, "This regular expression is constructed from a $@.",
8995
source.getNode(), "user-provided value"
96+
// from MethodAccess ma
97+
// where
98+
// // ma.getMethod().hasName("startsWith") and // graphhopper
99+
// // ma.getFile().getBaseName() = "NavigateResource.java" // graphhopper
100+
// // ma.getMethod().hasName("substring") and // jfinal
101+
// // ma.getFile().getBaseName() = "FileManager.java" // jfinal
102+
// ma.getMethod().hasName("startsWith") and // roller
103+
// ma.getFile().getBaseName() = "PageServlet.java" // roller (or RegexUtil.java)
104+
// ProteinArraySignificanceTestJSON.java or MockRKeys.java for cbioportal
105+
// select ma, "method access"

java/ql/test/experimental/query-tests/security/CWE-730/RegexInjection.qlref

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
experimental/Security/CWE/CWE-730/RegexInjection.ql

0 commit comments

Comments
 (0)