You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
open fun securityWebFilterChain(http: HttpSecurity): SecurityWebFilterChain {
109
+
open fun securityWebFilterChain(http: ServerHttpSecurity): SecurityWebFilterChain {
110
110
val requestHandler = XorServerCsrfTokenRequestAttributeHandler()
111
111
// ...
112
112
return http {
@@ -119,6 +119,116 @@ open fun securityWebFilterChain(http: HttpSecurity): SecurityWebFilterChain {
119
119
----
120
120
====
121
121
122
+
[[reactive-csrf-breach-opt-out]]
123
+
=== Opt-out Steps
124
+
125
+
If configuring CSRF BREACH protection gives you trouble, take a look at these scenarios for optimal opt out behavior:
126
+
127
+
==== I am using AngularJS or another Javascript framework
128
+
129
+
If you are using AngularJS and the https://angular.io/api/common/http/HttpClientXsrfModule[HttpClientXsrfModule] (or a similar module in another framework) along with `CookieCsrfTokenRepository.withHttpOnlyFalse()`, you may find that automatic support no longer works.
130
+
131
+
In this case, you can configure Spring Security to validate the raw `CsrfToken` from the cookie while keeping CSRF BREACH protection of the response using a custom `ServerCsrfTokenRequestHandler` with delegation, like so:
132
+
133
+
.Configure `CsrfToken` BREACH Protection to validate raw tokens
ServerCsrfTokenRequestAttributeHandler requestHandler = new ServerCsrfTokenRequestAttributeHandler();
207
+
http
208
+
// ...
209
+
.csrf((csrf) -> csrf
210
+
.csrfTokenRequestHandler(requestHandler)
211
+
);
212
+
return http.build();
213
+
}
214
+
----
215
+
216
+
.Kotlin
217
+
[source,kotlin,role="secondary"]
218
+
----
219
+
@Bean
220
+
open fun securityWebFilterChain(http: ServerHttpSecurity): SecurityWebFilterChain {
221
+
val requestHandler = ServerCsrfTokenRequestAttributeHandler()
222
+
return http {
223
+
// ...
224
+
csrf {
225
+
csrfTokenRequestHandler = requestHandler
226
+
}
227
+
}
228
+
}
229
+
----
230
+
====
231
+
122
232
== Use `AuthorizationManager` for Method Security
123
233
124
234
xref:reactive/authorization/method.adoc[Method Security] has been xref:reactive/authorization/method.adoc#jc-enable-reactive-method-security-authorization-manager[improved] through {security-api-url}org/springframework/security/authorization/AuthorizationManager.html[the `AuthorizationManager` API] and direct use of Spring AOP.
0 commit comments