-
Notifications
You must be signed in to change notification settings - Fork 6k
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
samesite set by Tomcat CookieProcessor ignored when creating XSRF-TOKEN cookie in CsrfTokenRepository #14131
Comments
Hi, @burghduffkc. Thanks for the report. |
For the time being, you can work around that by customizing the cookie generated by the var repository = CookieCsrfTokenRepository.withHttpOnlyFalse();
repository.setCookieCustomizer((customizer) -> {
customizer.sameSite(sameSitePolicy);
}); |
@marcusdacoregio Thank you for the suggestion, unfortunately that would require us to update all applications, as our current Tomcat CookieProcessor is configured in the context.xml file and not in Spring. Example Configuration for context.xml |
Thanks, @burghduffkc. This is now merged into |
@marcusdacoregio I tested the snapshot and was able to verify the issue was fixed. Thanks for the quick turnaround!!! |
Hi, It seems this fix might have broken backwards compatibility with jakarta servlet 5, as it uses the new At least when using a
@marcusdacoregio I assume this was unintentional and servlet 5 should be supported, but wanted to make sure before raising a new issue about this? |
Hi @acutus, please go ahead and create a new ticket |
Will do |
Created #16173 |
Describe the bug
Prior to Spring Security 6, the CsrfTokenRepository used the response.addCookie in the saveToken method to add the XSRF-TOKEN cookie. In Spring-Security 6 it was changed to call response.addHeader which bypasses the Tomcat CookieProcessor.
To Reproduce
I forked the Spring-Security-Samples project and used hello-security-explicit
https://github.com/burghduffkc/spring-security-samples/commits/main/servlet/spring-boot/java/hello-security-explicit, below are the modifications and steps to reproduce.
http://locahost:8080
JSESSIONID
cookie has the sameSite set to Strict, but theXSRF-TOKEN
does not have sameSite set. This is because theCsrfTokenRepository#saveToken
does not use addCookie, bypassing the Tomcat CookieProcessor.Expected behavior
A clear and concise description of what you expected to happen.
The XSRF-TOKEN cookie should have sameSite set to Strict.
Sample
Change to hello-security-explicit sample
burghduffkc/spring-security-samples@fb8971a
Full code for Spring-Security Example
https://github.com/burghduffkc/spring-security-samples/commits/main/servlet/spring-boot/java/hello-security-explicit
A link to a GitHub repository with a minimal, reproducible sample.
Reports that include a sample will take priority over reports that do not.
At times, we may require a sample, so it is good to try and include a sample up front.
The text was updated successfully, but these errors were encountered: