-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
CSRF Support for SameSite #7537
Comments
It is different. We want to persist the expected CSRF token in a cookie marked with SameSite strict. If the cookie is present in supported browser, then we know that the request originated from the same site. |
Hey folks. This is marked for 5.3.0 milestone, but I don't see it in the release notes. |
An easy way around this problem is to use org.springframework.http.ResponseCookie class. The class has a nice builder with samesite property. |
@phalt It's probably not obvious, but the the .x milestones are buckets of items that we would like to get into a release, but haven't planned capacity for it. That means this has not been concretely planned for a release. I have also updated the milestone description to be more informative. |
thanks @rwinch. i can understand but google chrome is pushing hard to enforce this. |
Would someone be interested in submitting a pull request using |
I would like to take this one. I think this should be fixed for all cookies, also value should be configurable. |
Thank you @codecracker2014 This issue is yours. I'd suggest creating separate tickets/PRs for any other places that need updated. |
@codecracker2014 any updates on this? |
I'm sorry for late update on this. It's very good idea to use same-site attribute to implement CSRF protection, but the problem is setter for sameSite is not available in Servlet API(javax.servlet.http.Cookie). refer https://wiki.shibboleth.net/confluence/display/DEV/Tomcat+and+Jetty+SameSite+Workarounds |
Any suggestions on Servlet API dependency? Servlet API 5.0.* yet to be released with support of SameSite, we should wait for that release to implement this feature. |
Keep in mind that for intranet applications, relying on SameSite=Strict for CSRF protection is not sufficient. Imagine a company hosting its intranet sites under company.com: If application A uses a session cookie with Read this for an explanation: https://web.dev/same-site-same-origin/ |
Yes, @codecracker2014, I think you would use the suggestion outlined here.
I wonder if want to wait that long as Spring Security will not move its baseline from Servlet 3.1 until a major release. It would be nice to have this feature in the Spring Security 5.x line. |
I've created pull request #9843 for this issue. |
Thanks @codecracker2014! As you noticed this issue is pretty old and so I wanted to refresh my understanding around CSRF best practices. At the moment, I'm wondering if it is a good idea to replace Synchronizer Token Pattern as we are doing here because the OWASP CSRF Cheat Sheet says that I've reached out to OWASP on the current guidance around if From here we will see what the response on the ticket I created is and take it from there. |
@rwinch SameSite does not protect against CSRF within larger intranet spaces that share the same ETLD+1. |
OWASP is recommending to implement SameSite cookie along with Synchronizer token (OWASP cheat sheet) to provide additional layer of defense. SameSite cookie can enable us to control top level navigation. Like some sites might disallow user to continue if page opened from third party site. @rwinch Instead of replacing Synchronizer token we can implement provision to add SameSite attribute to session cookie this will provide additional defense. |
After quite a bit of deliberation and feedback on the owasp ticket, I've decided to close this as won't fix (at least for now). The problem is that using SameSite is still really a defense in depth mechanism and does not solve for every cases. For example, it does not protect subdomains or older browsers (yes old browsers are very prevalent in many companies still). Frameworks should make it difficult (if not impossible) to make insecure choices. Until SameSite is established as a complete solution to CSRF attacks, we should not allow users to replace tokenizer pattern with SameSite. |
Hi, im confused about reason why setting SameSite and CSRF coockie was rejected. Now most browsers use lax as default if SameSite is not set. This should be an additional configuration and not used as a replacment of the sync token pattern. Currently i used custom token repo which delegates to the original spring coockie repro and adds the SameSite attribute to the cockie. Better would be to have already support in the existing repro which use Lax as default. |
I also think in this ticket two topics are mixed.
As requested in #7990 and many in this topic discussed the first topic...so being able to set the SameSite attribute for the currently existing cookie (nothing else). Yes, modern browsers fall back to SameSite=Lax, but in security I always prefer explicit setting over implicit assumptions. |
The reasons for rejecting are outlined in link I provided in #7537 (comment) If OWASP is not recommending an approach, it is very unlikely that we will implement it in Spring Security. |
@rwinch thanks for answering. But I believe we still not talking about the same thing. I (and I believe most of the people here) do NOT want to replace CSRF protection mechanism by soley using the SameSite attribute. We just want to be able to set the SameSite attribute (which ALL cookies have) for the CSRF cookie. So enhancing the CookieCsrfTokenRepository to allow to set the SameSite attribute. This will not change any security related stuff for the worse -> right now the XSRF-TOKEN cookie will just fall back to SameSite=Lax as this is currently the standard by modern browser. |
@rwinch I would echo the point that @BenICE raises. I understand that setting SameSite=Strict will not replace CSRF cookie protection. We are just looking to close the gap some penetration test reports raise where they expect all cookies produced from a site to be SameSite=Strict. Since CookieCsrfTokenRepository is final the only way to accomplish this today is to re-implement the entire class. I know there are other options for ensuring all cookies are set to strict via Tomcat/Http Server configurations, but would rather take a deployment independent approach and have it configured on CookieCsrfTokenRepository directly. |
For those who are just looking for a way to set the SameSite Attribute for the CSRF-Cookie: I just worked around that issue by putting the following Bean into my App-Context... this adds SameSite Lax (check:
That should work for Undertow, Tomcat and Jetty as far as I can see. |
This only works when using Spring Boot, and only when using an embedded webserver, not when building a WAR and deploying it to an existing webserver.
Edit: sorry, got XSRF and SESSION cookies confused. |
Unfortunally not because thats only evaluated for the Spring Session Cookie, check |
You're right, I keep getting those two confused (like everyone). |
Seems like
works for me. |
Summary
An alternative to using the synchronizer token pattern is to use the approach described in https://tools.ietf.org/html/draft-west-first-party-cookies-07#section-5.2
The text was updated successfully, but these errors were encountered: