-
Notifications
You must be signed in to change notification settings - Fork 6k
CookieCsrfTokenRepository Optionally allows to set the SameSite attribute. #11913
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
Hi @void-spark. Since Spring Boot 2.6, you can achieve this by providing a @Configuration(proxyBeanMethods = false)
public class MySameSiteConfiguration {
@Bean
public CookieSameSiteSupplier applicationCookieSameSiteSupplier() {
return CookieSameSiteSupplier.ofLax().whenHasNameMatching("myapp.*");
}
} Is this what you are looking for? |
Hmm, that uses some kind of cookie post-processing functionality at server level? |
As far as I know, yes. Here is the documentation about that feature: https://docs.spring.io/spring-boot/docs/current/reference/html/web.html#web.servlet.embedded-container.customizing.samesite I'll close this for now but feel free to continue the discussion if you think there is value in adding this feature. |
Hi @marcusdacoregio, Thanks |
Hello @martashorak, I'm afraid that this question is more suited to StackOverflow, but I'm quite sure that it is possible to configure the cookies or override them if needed. |
I think there still is value. Not everybody uses Spring Boot, and not everybody runs it in embedded mode. It feels like the Spring Boot method is a fairy elaborate hack which is webserver dependent, whereas this would be 1 setting in |
Expected Behavior
CookieCsrfTokenRepository can be configured with a setSameSite method taking an enum as arg to allow to set the SameSite attribute for the XSRF cookie.
Current Behavior
CookieCsrfTokenRepository Provides no way to specify using SameSite.
Context
This is inspired from: #7537 (comment)
Which collected several thumbs up by now :)
For us this is triggerd by security requesting we add SameSite on our CSRF token, which right now we can only do by copy-pasting the CookieCsrfTokenRepository class and modifying it to use a ResponseCookie and adding the SameSite with that.
See also: https://stackoverflow.com/questions/60039647/is-it-possible-to-add-same-site-attribute-to-spring-security-csrfs-csrftokenre
The text was updated successfully, but these errors were encountered: