Skip to content

Commit 5402001

Browse files
Jami CogswellJami Cogswell
authored andcommitted
remove original sanitizer
1 parent be548c1 commit 5402001

File tree

2 files changed

+0
-86
lines changed

2 files changed

+0
-86
lines changed

java/ql/lib/semmle/code/java/security/RegexInjection.qll

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import java
44
private import semmle.code.java.dataflow.DataFlow
55
private import semmle.code.java.frameworks.Regex
6-
//private import semmle.code.java.frameworks.apache.Lang
76
private import semmle.code.java.regex.RegexFlowModels
87

98
/** A data flow sink for untrusted user input used to construct regular expressions. */
@@ -24,30 +23,6 @@ private class DefaultRegexInjectionSink extends RegexInjectionSink {
2423
}
2524
}
2625

27-
/** A call to a function whose name suggests that it escapes regular expression meta-characters. */
28-
private class RegexSanitizationCall extends RegexInjectionSanitizer {
29-
RegexSanitizationCall() {
30-
// original
31-
// exists(string calleeName, string sanitize, string regexp |
32-
// calleeName = this.asExpr().(Call).getCallee().getName() and
33-
// sanitize = "(?:escape|saniti[sz]e)" and
34-
// regexp = "regexp?"
35-
// |
36-
// calleeName
37-
// .regexpMatch("(?i)(" + sanitize + ".*" + regexp + ".*)" + "|(" + regexp + ".*" + sanitize +
38-
// ".*)")
39-
// )
40-
// without regexp
41-
exists(string calleeName, string sanitize |
42-
calleeName = this.asExpr().(Call).getCallee().getName() and
43-
sanitize = "(?:escape|saniti[sz]e)"
44-
|
45-
calleeName.regexpMatch("(?i)(.*" + sanitize + ".*)")
46-
//calleeName.matches("handleEscapes")
47-
)
48-
}
49-
}
50-
5126
/**
5227
* A call to the `Pattern.quote` method, which gives metacharacters or escape sequences
5328
* no special meaning.

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

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -72,67 +72,6 @@ String foo(String str) {
7272
return str;
7373
}
7474

75-
public boolean pattern5(javax.servlet.http.HttpServletRequest request) {
76-
String pattern = request.getParameter("pattern");
77-
String input = request.getParameter("input");
78-
79-
// Safe: User input is sanitized before constructing the regex
80-
return input.matches("^" + escapeSpecialRegexChars(pattern) + "=.*$");
81-
}
82-
83-
public boolean pattern6(javax.servlet.http.HttpServletRequest request) {
84-
String pattern = request.getParameter("pattern");
85-
String input = request.getParameter("input");
86-
87-
escapeSpecialRegexChars(pattern);
88-
89-
// BAD: the pattern is not really sanitized
90-
return input.matches("^" + pattern + "=.*$"); // $ hasRegexInjection
91-
}
92-
93-
public boolean pattern7(javax.servlet.http.HttpServletRequest request) {
94-
String pattern = request.getParameter("pattern");
95-
String input = request.getParameter("input");
96-
97-
String escapedPattern = escapeSpecialRegexChars(pattern);
98-
99-
// Safe: User input is sanitized before constructing the regex
100-
return input.matches("^" + escapedPattern + "=.*$");
101-
}
102-
103-
public boolean pattern8(javax.servlet.http.HttpServletRequest request) {
104-
String pattern = request.getParameter("pattern");
105-
String input = request.getParameter("input");
106-
107-
// Safe: User input is sanitized before constructing the regex
108-
return input.matches("^" + sanitizeSpecialRegexChars(pattern) + "=.*$");
109-
}
110-
111-
public boolean pattern9(javax.servlet.http.HttpServletRequest request) {
112-
String pattern = request.getParameter("pattern");
113-
String input = request.getParameter("input");
114-
115-
// Safe: User input is sanitized before constructing the regex
116-
return input.matches("^" + sanitiseSpecialRegexChars(pattern) + "=.*$");
117-
}
118-
119-
Pattern SPECIAL_REGEX_CHARS = Pattern.compile("[{}()\\[\\]><-=!.+*?^$\\\\|]");
120-
121-
// test `escape...regex`
122-
String escapeSpecialRegexChars(String str) {
123-
return SPECIAL_REGEX_CHARS.matcher(str).replaceAll("\\\\$0");
124-
}
125-
126-
// test `sanitize...regex`
127-
String sanitizeSpecialRegexChars(String str) {
128-
return SPECIAL_REGEX_CHARS.matcher(str).replaceAll("\\\\$0");
129-
}
130-
131-
// test `sanitise...regex`
132-
String sanitiseSpecialRegexChars(String str) {
133-
return SPECIAL_REGEX_CHARS.matcher(str).replaceAll("\\\\$0");
134-
}
135-
13675
public boolean apache1(javax.servlet.http.HttpServletRequest request) {
13776
String pattern = request.getParameter("pattern");
13877
String input = request.getParameter("input");

0 commit comments

Comments
 (0)