-
Notifications
You must be signed in to change notification settings - Fork 6k
Ineffective CSRF Protection for SPAs as suggested by the Official Docs? #15092
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
@ptrckkk thanks for reaching out!
Please be aware that using In the future, if you feel you have found a security issue, please report it responsibly. Please also spend some time reading the Cross Site Request Forgery chapter in the reference and other resources covering CSRF and web application security. I'm going to close this issue with the above explanation, as others have noted concern over this issue while it remains unresolved. |
First of all, I did not intend to report a possible security issue irresponsibly and am now aware of how to do it more responsibly in the future! I still do not understand why everything works as expected which is why I ask further questions.
If I do not get it wrong, the documentation example uses
I do not want to argue with that statement.
Thus, I would assume that it works with header parameters - and without any cookies. These are my open questions. Maybe the documentation could be extended how to do CSRF protection for SPAs that use an API backend not relying on cookies? |
I am sorry you are not understanding. However, it feels like these are questions that would be better suited to Stack Overflow. We prefer to use GitHub issues only for bugs and enhancements. Feel free to update this issue with a link to the re-posted question (so that other people can find it).
I believe this request does not account for how CSRF protection works, which relies on both a storage mechanism for the expected CSRF token (session or cookie) as well as an actual (resolved) token value (HTTP header or parameter). As I mentioned above, please spend some time understanding how CSRF protection works by reviewing the documentation (linked in my earlier comment). |
Describe the bug
The offical documentation for CSRF protection for Single Page Applications (SPA) might be ineffective. It seems possible to send arbitrary CSRF tokens which are accepted as valid CSRF tokens.
To Reproduce
I created a repository with a simple REST controller, having one POST endpoint at "/hello" which returns the plain text "Hello there".
The endpoint is protected by Spring Security in version 6.2.4 and configured exactly as the above-mentioned official docs recommend for SPAs.
If you start the application and send the following POST request via curl
the backend will respond with "Hello, there" meaning the endpoint was reached and executed. However, "123" is not a valid CSRF token! Actually, when one changes "123" to any arbitrary value for both, the "XSRF-TOKEN" cookie and the "X-XSRF-TOKEN" header, the endpoint is executed.
Expected behavior
The expected behavior is that the curl request with arbitrary CSRF tokens runs into "invalid CSRF token" and does not execute the endpoint; thus, no "Hello, there" should be returned.
Sample
See "To reproduce".
The text was updated successfully, but these errors were encountered: