Skip to content

Commit bdc60a9

Browse files
joshistefhanik
authored andcommitted
Don't cache requests with Accept: text/event-stream by default.
The eventstream requests is typically not directly invoked by the browser. And even more unfortunately the Browser-Api doesn't allow the set additional headers as `XMLHttpRequest`..
1 parent 1ae3ec3 commit bdc60a9

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

config/src/main/java/org/springframework/security/config/annotation/web/configurers/RequestCacheConfigurer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ private RequestMatcher createDefaultSavedRequestMatcher(H http) {
162162
matchers.add(notMatchingMediaType(http, MediaType.APPLICATION_JSON));
163163
matchers.add(notXRequestedWith);
164164
matchers.add(notMatchingMediaType(http, MediaType.MULTIPART_FORM_DATA));
165+
matchers.add(notMatchingMediaType(http, MediaType.TEXT_EVENT_STREAM));
165166

166167
return new AndRequestMatcher(matchers);
167168
}

config/src/test/java/org/springframework/security/config/annotation/web/configurers/RequestCacheConfigurerTests.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,21 @@ public void getWhenBookmarkedRequestIsXRequestedWithThenPostAuthenticationRedire
183183

184184
// This is desirable since XHR requests are typically not invoked directly from the browser and we don't want the browser to replay them
185185
}
186+
@Test
187+
public void getWhenBookmarkedRequestIsTextEventStreamThenPostAuthenticationRedirectsToRoot() throws Exception {
188+
this.spring.register(RequestCacheDefaultsConfig.class, DefaultSecurityConfig.class).autowire();
189+
190+
MockHttpSession session = (MockHttpSession)
191+
this.mvc.perform(get("/messages")
192+
.header(HttpHeaders.ACCEPT, MediaType.TEXT_EVENT_STREAM))
193+
.andExpect(redirectedUrl("http://localhost/login"))
194+
.andReturn().getRequest().getSession();
195+
196+
this.mvc.perform(formLogin(session))
197+
.andExpect(redirectedUrl("/")); // ignores text/event-stream
198+
199+
// This is desirable since event-stream requests are typically not invoked directly from the browser and we don't want the browser to replay them
200+
}
186201

187202
@Test
188203
public void getWhenBookmarkedRequestIsAllMediaTypeThenPostAuthenticationRemembers() throws Exception {

0 commit comments

Comments
 (0)