Skip to content

Commit 472c25b

Browse files
committed
AntRegexRequestMatcher Optimization
Closes gh-11234
1 parent 0df5ece commit 472c25b

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

web/src/main/java/org/springframework/security/web/util/matcher/RegexRequestMatcher.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@
4242
*/
4343
public final class RegexRequestMatcher implements RequestMatcher {
4444

45-
private static final int DEFAULT = 0;
45+
private static final int DEFAULT = Pattern.DOTALL;
46+
47+
private static final int CASE_INSENSITIVE = DEFAULT | Pattern.CASE_INSENSITIVE;
4648

4749
private static final Log logger = LogFactory.getLog(RegexRequestMatcher.class);
4850

@@ -67,7 +69,7 @@ public RegexRequestMatcher(String pattern, String httpMethod) {
6769
* {@link Pattern#CASE_INSENSITIVE} flag set.
6870
*/
6971
public RegexRequestMatcher(String pattern, String httpMethod, boolean caseInsensitive) {
70-
this.pattern = Pattern.compile(pattern, caseInsensitive ? Pattern.CASE_INSENSITIVE : DEFAULT);
72+
this.pattern = Pattern.compile(pattern, caseInsensitive ? CASE_INSENSITIVE : DEFAULT);
7173
this.httpMethod = StringUtils.hasText(httpMethod) ? HttpMethod.valueOf(httpMethod) : null;
7274
}
7375

web/src/test/java/org/springframework/security/web/util/matcher/RegexRequestMatcherTests.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,22 @@ public void matchesWithInvalidMethod() {
100100
assertThat(matcher.matches(request)).isFalse();
101101
}
102102

103+
@Test
104+
public void matchesWithCarriageReturn() {
105+
RegexRequestMatcher matcher = new RegexRequestMatcher(".*", null);
106+
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/blah%0a");
107+
request.setServletPath("/blah\n");
108+
assertThat(matcher.matches(request)).isTrue();
109+
}
110+
111+
@Test
112+
public void matchesWithLineFeed() {
113+
RegexRequestMatcher matcher = new RegexRequestMatcher(".*", null);
114+
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/blah%0d");
115+
request.setServletPath("/blah\r");
116+
assertThat(matcher.matches(request)).isTrue();
117+
}
118+
103119
@Test
104120
public void toStringThenFormatted() {
105121
RegexRequestMatcher matcher = new RegexRequestMatcher("/blah", "GET");

0 commit comments

Comments
 (0)