@@ -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