Skip to content

Commit 19de13b

Browse files
Luke Buttersjzheaux
authored andcommitted
Issue 6731 improve performance of checking headers
Improves the performance of checking headers for new lines. Fixes: gh-6731
1 parent 21a0e45 commit 19de13b

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

web/src/main/java/org/springframework/security/web/firewall/FirewalledResponse.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package org.springframework.security.web.firewall;
1717

1818
import java.io.IOException;
19-
import java.util.regex.Pattern;
2019

2120
import javax.servlet.http.Cookie;
2221
import javax.servlet.http.HttpServletResponse;
@@ -26,9 +25,9 @@
2625
* @author Luke Taylor
2726
* @author Eddú Meléndez
2827
* @author Gabriel Lavoie
28+
* @author Luke Butters
2929
*/
3030
class FirewalledResponse extends HttpServletResponseWrapper {
31-
private static final Pattern CR_OR_LF = Pattern.compile("\\r|\\n");
3231
private static final String LOCATION_HEADER = "Location";
3332
private static final String SET_COOKIE_HEADER = "Set-Cookie";
3433

@@ -76,6 +75,6 @@ void validateCrlf(String name, String value) {
7675
}
7776

7877
private boolean hasCrlf(String value) {
79-
return value != null && CR_OR_LF.matcher(value).find();
78+
return value != null && (value.indexOf('\n') != -1 || value.indexOf('\r') != -1);
8079
}
8180
}

0 commit comments

Comments
 (0)