-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Allow configuration of added SessionAuthenticationStrategy for CsrfConfigurer #5300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
If someone could confirm that extending the |
Any thoughts on this @rwinch? |
@mvitz & @samiconductor, having the same problem here with a Spring MVC stateless application with JWT tokens. After authentication, CsrfAuthenticationStrategy is generating CSRF tokens for each resource, but saves the initial html csrf token as thymeleaf hidden field. Therefore, any POST requests are failing. |
First, why do you want to change the authentication strategy? Second, can you clarify why you want to do that vs http
.sessionManagement()
.sessionAuthenticationStrategy(someStrategy); |
@rwinch the problem is when you configure CSRF the configurer automatically adds With a STATELESS app, we want to store the CSRF token on the client on login and pass it back each time similar to a JWT token. So we would add the CSRF token to the client as a cookie that is hidden from JS and pass the CSRF token to the JS as a HTTP header and store it in session storage for example. Each request would ensure the cookie and passed token match. However, when the CSRF token is recreated on each request, the cookie and passed token can get out of sync when making concurrent requests. Anyway, that was my idea of how CSRF would work in a STATELESS app. Maybe there's another approach? I've just disabled CSRF in the mean time. But the above cookie/header approach could work if we can override the default strategy like @mvitz setup in this PR. |
@samiconductor Thanks for the clarification. This makes more sense to me now. I'd love for you to submit a PR that allows configuring the strategy as you suggested. Once you have confirmed you are still able to work on it, I will mark this issue as such. If you need any help, don't hesitate to reach out |
If you have specific questions, feel free to ask here. |
@samiconductor Thanks for the PR!
Strange as they worked fine for me. If you continue to see errors, can you please create a ticket with what happens and details on how to reproduce? |
Summary
CsrfConfigurer
automatically adds an instance ofCsrfAuthenticationStrategy
asSessionAuthenticationStrategy
. It would be helpful to allow another strategy to be added.Actual Behavior
An instance of
CsrfAuthenticationStrategy
is configured automatically.Expected Behavior
The
CsrfConfigurer
contains a method to configure the usedSessionAuthenticationStrategy
.Version
5.0.4.RELEASE
The text was updated successfully, but these errors were encountered: