Skip to content

Commit 6f8cc92

Browse files
committed
Merge branch '6.1.x' into 6.2.x
Closes gh-14805
2 parents 614123e + 80845d0 commit 6f8cc92

File tree

1 file changed

+37
-1
lines changed
  • docs/modules/ROOT/pages/servlet/exploits

1 file changed

+37
-1
lines changed

docs/modules/ROOT/pages/servlet/exploits/csrf.adoc

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,7 @@ class SpaCsrfTokenRequestHandler : CsrfTokenRequestAttributeHandler() {
876876
delegate.handle(request, response, csrfToken)
877877
}
878878
879-
override fun resolveCsrfTokenValue(request: HttpServletRequest, csrfToken: CsrfToken): String {
879+
override fun resolveCsrfTokenValue(request: HttpServletRequest, csrfToken: CsrfToken): String? {
880880
/*
881881
* If the request contains a request header, use CsrfTokenRequestAttributeHandler
882882
* to resolve the CsrfToken. This applies when a single-page application includes
@@ -1221,6 +1221,24 @@ public class CsrfTests {
12211221
.andExpect(header().string(HttpHeaders.LOCATION, "/"));
12221222
}
12231223
1224+
@Test
1225+
public void loginWhenInvalidCsrfTokenThenForbidden() throws Exception {
1226+
this.mockMvc.perform(post("/login").with(csrf().useInvalidToken())
1227+
.accept(MediaType.TEXT_HTML)
1228+
.param("username", "user")
1229+
.param("password", "password"))
1230+
.andExpect(status().isForbidden());
1231+
}
1232+
1233+
@Test
1234+
public void loginWhenMissingCsrfTokenThenForbidden() throws Exception {
1235+
this.mockMvc.perform(post("/login")
1236+
.accept(MediaType.TEXT_HTML)
1237+
.param("username", "user")
1238+
.param("password", "password"))
1239+
.andExpect(status().isForbidden());
1240+
}
1241+
12241242
@Test
12251243
@WithMockUser
12261244
public void logoutWhenValidCsrfTokenThenSuccess() throws Exception {
@@ -1264,6 +1282,24 @@ class CsrfTests {
12641282
.andExpect(header().string(HttpHeaders.LOCATION, "/"))
12651283
}
12661284
1285+
@Test
1286+
fun loginWhenInvalidCsrfTokenThenForbidden() {
1287+
mockMvc.perform(post("/login").with(csrf().useInvalidToken())
1288+
.accept(MediaType.TEXT_HTML)
1289+
.param("username", "user")
1290+
.param("password", "password"))
1291+
.andExpect(status().isForbidden)
1292+
}
1293+
1294+
@Test
1295+
fun loginWhenMissingCsrfTokenThenForbidden() {
1296+
mockMvc.perform(post("/login")
1297+
.accept(MediaType.TEXT_HTML)
1298+
.param("username", "user")
1299+
.param("password", "password"))
1300+
.andExpect(status().isForbidden)
1301+
}
1302+
12671303
@Test
12681304
@WithMockUser
12691305
@Throws(Exception::class)

0 commit comments

Comments
 (0)