Skip to content

Commit c4f68d8

Browse files
author
Steve Riesenberg
committed
Document default CsrfTokenRequestHandler in 6.0
Closes gh-12651
1 parent 5ccf414 commit c4f68d8

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

Diff for: docs/modules/ROOT/pages/reactive/exploits/csrf.adoc

+7-7
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,14 @@ fun springSecurityFilterChain(http: ServerHttpSecurity): SecurityWebFilterChain
109109
[[webflux-csrf-configure-request-handler]]
110110
==== Configure ServerCsrfTokenRequestHandler
111111

112-
Spring Security's https://docs.spring.io/spring-security/site/docs/current/api/org/springframework/security/web/server/csrf/CsrfWebFilter.html[`CsrfWebFilter`] exposes a https://docs.spring.io/spring-security/site/docs/current/api/org/springframework/security/web/csrf/CsrfToken.html[`Mono<CsrfToken>`] as a `ServerWebExchange` attribute named `org.springframework.security.web.server.csrf.CsrfToken` with the help of a https://docs.spring.io/spring-security/site/docs/current/api/org/springframework/security/web/server/csrf/ServerCsrfTokenRequestHandler.html[`ServerCsrfTokenRequestHandler`].
113-
The default implementation is `ServerCsrfTokenRequestAttributeHandler`.
112+
Spring Security's https://docs.spring.io/spring-security/site/docs/current/api/org/springframework/security/web/server/csrf/CsrfWebFilter.html[`CsrfWebFilter`] exposes a https://docs.spring.io/spring-security/site/docs/current/api/org/springframework/security/web/server/csrf/CsrfToken.html[`Mono<CsrfToken>`] as a `ServerWebExchange` attribute named `org.springframework.security.web.server.csrf.CsrfToken` with the help of a https://docs.spring.io/spring-security/site/docs/current/api/org/springframework/security/web/server/csrf/ServerCsrfTokenRequestHandler.html[`ServerCsrfTokenRequestHandler`].
113+
In 5.8, the default implementation was `ServerCsrfTokenRequestAttributeHandler`, which simply makes the `Mono<CsrfToken>` available as an exchange attribute.
114114

115-
An alternate implementation `XorServerCsrfTokenRequestAttributeHandler` is available to provide protection for BREACH (see https://github.com/spring-projects/spring-security/issues/4001[gh-4001]).
115+
As of 6.0, the default implementation is `XorServerCsrfTokenRequestAttributeHandler`, which provides protection for BREACH (see https://github.com/spring-projects/spring-security/issues/4001[gh-4001]).
116116

117-
You can configure `XorServerCsrfTokenRequestAttributeHandler` using the following Java configuration:
117+
If you wish to disable BREACH protection of the `CsrfToken` and revert to the 5.8 default, you can configure `ServerCsrfTokenRequestAttributeHandler` using the following Java configuration:
118118

119-
.Configure BREACH protection
119+
.Disable BREACH protection
120120
====
121121
.Java
122122
[source,java,role="primary"]
@@ -126,7 +126,7 @@ public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http)
126126
http
127127
// ...
128128
.csrf(csrf -> csrf
129-
.csrfTokenRequestHandler(new XorServerCsrfTokenRequestAttributeHandler())
129+
.csrfTokenRequestHandler(new ServerCsrfTokenRequestAttributeHandler())
130130
)
131131
return http.build();
132132
}
@@ -140,7 +140,7 @@ fun springSecurityFilterChain(http: ServerHttpSecurity): SecurityWebFilterChain
140140
return http {
141141
// ...
142142
csrf {
143-
csrfTokenRequestHandler = XorServerCsrfTokenRequestAttributeHandler()
143+
csrfTokenRequestHandler = ServerCsrfTokenRequestAttributeHandler()
144144
}
145145
}
146146
}

Diff for: docs/modules/ROOT/pages/servlet/exploits/csrf.adoc

+9-9
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,13 @@ class SecurityConfig {
168168
==== Configure CsrfTokenRequestHandler
169169

170170
Spring Security's https://docs.spring.io/spring-security/site/docs/current/api/org/springframework/security/web/csrf/CsrfFilter.html[`CsrfFilter`] exposes a https://docs.spring.io/spring-security/site/docs/current/api/org/springframework/security/web/csrf/CsrfToken.html[`CsrfToken`] as an `HttpServletRequest` attribute named `_csrf` with the help of a https://docs.spring.io/spring-security/site/docs/current/api/org/springframework/security/web/csrf/CsrfTokenRequestHandler.html[CsrfTokenRequestHandler].
171-
The default implementation is `CsrfTokenRequestAttributeHandler`.
171+
In 5.8, the default implementation was `CsrfTokenRequestAttributeHandler` which simply makes the `_csrf` attribute available as a request attribute.
172172

173-
An alternate implementation `XorCsrfTokenRequestAttributeHandler` is available to provide protection for BREACH (see https://github.com/spring-projects/spring-security/issues/4001[gh-4001]).
173+
As of 6.0, the default implementation is `XorCsrfTokenRequestAttributeHandler`, which provides protection for BREACH (see https://github.com/spring-projects/spring-security/issues/4001[gh-4001]).
174174

175-
You can configure `XorCsrfTokenRequestAttributeHandler` in XML using the following:
175+
If you wish to disable BREACH protection of the `CsrfToken` and revert to the 5.8 default, you can configure `CsrfTokenRequestAttributeHandler` in XML using the following:
176176

177-
.Configure BREACH protection XML Configuration
177+
.Disable BREACH protection XML Configuration
178178
====
179179
[source,xml]
180180
----
@@ -183,13 +183,13 @@ You can configure `XorCsrfTokenRequestAttributeHandler` in XML using the followi
183183
<csrf request-handler-ref="requestHandler"/>
184184
</http>
185185
<b:bean id="requestHandler"
186-
class="org.springframework.security.web.csrf.XorCsrfTokenRequestAttributeHandler"/>
186+
class="org.springframework.security.web.csrf.CsrfTokenRequestAttributeHandler"/>
187187
----
188188
====
189189

190-
You can configure `XorCsrfTokenRequestAttributeHandler` in Java Configuration using the following:
190+
You can configure `CsrfTokenRequestAttributeHandler` in Java Configuration using the following:
191191

192-
.Configure BREACH protection
192+
.Disable BREACH protection
193193
====
194194
.Java
195195
[source,java,role="primary"]
@@ -201,7 +201,7 @@ public class WebSecurityConfig {
201201
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
202202
http
203203
.csrf(csrf -> csrf
204-
.csrfTokenRequestHandler(new XorCsrfTokenRequestAttributeHandler())
204+
.csrfTokenRequestHandler(new CsrfTokenRequestAttributeHandler())
205205
);
206206
return http.build();
207207
}
@@ -218,7 +218,7 @@ class SecurityConfig {
218218
open fun filterChain(http: HttpSecurity): SecurityFilterChain {
219219
http {
220220
csrf {
221-
csrfTokenRequestHandler = XorCsrfTokenRequestAttributeHandler()
221+
csrfTokenRequestHandler = CsrfTokenRequestAttributeHandler()
222222
}
223223
}
224224
return http.build()

0 commit comments

Comments
 (0)