Skip to content

Commit 33e72b3

Browse files
author
Steve Riesenberg
committed
Add section for migrating WebSocket support
Issue gh-12378
1 parent c306df9 commit 33e72b3

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

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

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,3 +243,65 @@ open fun springSecurity(http: HttpSecurity): SecurityFilterChain {
243243
==== I need to opt out of CSRF BREACH protection for another reason
244244

245245
If CSRF BREACH protection does not work for you for another reason, you can opt out using the configuration from the <<servlet-opt-in-defer-loading-csrf-token>> section.
246+
247+
== CSRF BREACH with WebSocket support
248+
249+
If the steps for <<Protect against CSRF BREACH>> work for normal HTTP requests and you are using xref:servlet/integrations/websocket.adoc[WebSocket Security] support, then you can also opt into Spring Security 6's default support for BREACH protection of the `CsrfToken` with xref:servlet/integrations/websocket.adoc#websocket-sameorigin-csrf[Stomp headers].
250+
251+
.WebSocket Security BREACH Protection
252+
====
253+
.Java
254+
[source,java,role="primary"]
255+
----
256+
@Bean
257+
ChannelInterceptor csrfChannelInterceptor() {
258+
return new XorCsrfChannelInterceptor();
259+
}
260+
----
261+
262+
.Kotlin
263+
[source,kotlin,role="secondary"]
264+
----
265+
@Bean
266+
open fun csrfChannelInterceptor(): ChannelInterceptor {
267+
return XorCsrfChannelInterceptor()
268+
}
269+
----
270+
271+
.XML
272+
[source,xml,role="secondary"]
273+
----
274+
<b:bean id="csrfChannelInterceptor"
275+
class="org.springframework.security.messaging.web.csrf.XorCsrfChannelInterceptor"/>
276+
----
277+
====
278+
279+
If configuring CSRF BREACH protection for WebSocket Security gives you trouble, you can configure the 5.8 default using the following configuration:
280+
281+
.Configure WebSocket Security with 5.8 default
282+
====
283+
.Java
284+
[source,java,role="primary"]
285+
----
286+
@Bean
287+
ChannelInterceptor csrfChannelInterceptor() {
288+
return new CsrfChannelInterceptor();
289+
}
290+
----
291+
292+
.Kotlin
293+
[source,kotlin,role="secondary"]
294+
----
295+
@Bean
296+
open fun csrfChannelInterceptor(): ChannelInterceptor {
297+
return CsrfChannelInterceptor()
298+
}
299+
----
300+
301+
.XML
302+
[source,xml,role="secondary"]
303+
----
304+
<b:bean id="csrfChannelInterceptor"
305+
class="org.springframework.security.messaging.web.csrf.CsrfChannelInterceptor"/>
306+
----
307+
====

0 commit comments

Comments
 (0)