3 ms·
The [OWASP] recommended approach to solve CSRF is with a Synchronizer Token [1]. Basically render a token with a hidden input with your form associated with th
by jfroma 13y ago
The [OWASP] recommended approach to solve CSRF is with a Synchronizer Token [1].
Basically render a token with a hidden input with your form associated with the user session and as you mention use a middleware to validate the token on every request.
So, let's talk about Syncronizer Token and "Single Page Applications" which was the topic on our first blog post. The recommended way for this is to get a token the first time and use the token in a header in every AJAX request. [2]
So, you now have cookies that are vulnerables to CSRF and a token in your javascript scope, in the same way you have the JWT.
If you think XSS is that common, the http only cookie+synchronizer token is more work and equally vulnerable to CSRF.
While with JWT you can stole my token if the site is XSS-vulnerable, but you can't trick me with the browser to do things I didn't meant.
I still consider XSS is easy to prevent than CSRF, you just need to escape user inputs always which is what every major template engine does by default. Usually you get the common syntax which does ESCAPE the user input.
Why OWASP states the contrary? I have one word: php. I blame php, wordpress and wordpress plugins. Consider that half of the internet runs on wordpress.
[1]: https://www.owasp.org/index.php/Cross-Site_Request_Forgery_(CSRF)_Prevention_Cheat_Sheet#General_Recommendation:_Synchronizer_Token_Pattern https://www.owasp.org/index.php/Cross-Site_Request_Forgery_(...
[2]: https://www.owasp.org/index.php/Cross-Site_Request_Forgery_(CSRF)_Prevention_Cheat_Sheet#Encrypted_Token_Pattern https://www.owasp.org/index.php/Cross-Site_Request_Forgery_(...