Skip to content

Commit 306309a

Browse files
committed
Prevent caching of non-document requests in HttpSessionRequestCache
Signed-off-by: Andrey Litvitski <[email protected]>
1 parent 1d2d268 commit 306309a

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

web/src/main/java/org/springframework/security/web/savedrequest/HttpSessionRequestCache.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public class HttpSessionRequestCache implements RequestCache {
5050

5151
private boolean createSessionAllowed = true;
5252

53-
private RequestMatcher requestMatcher = AnyRequestMatcher.INSTANCE;
53+
private RequestMatcher requestMatcher = new SecFetchDestRequestMatcher();
5454

5555
private String sessionAttrName = SAVED_REQUEST;
5656

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.security.web.savedrequest;
18+
19+
import jakarta.servlet.http.HttpServletRequest;
20+
import org.springframework.security.web.util.matcher.RequestMatcher;
21+
22+
public class SecFetchDestRequestMatcher implements RequestMatcher {
23+
@Override
24+
public boolean matches(HttpServletRequest request) {
25+
String secFetchDest = request.getHeader("Sec-Fetch-Dest");
26+
return "document".equals(secFetchDest);
27+
}
28+
}

0 commit comments

Comments
 (0)