Frameworks such as laravel and others require you place the csrf token in your HTML forms.
However at the same time laravel comes by default with the VerifyCsrfToken
middleware that automatically creates a X-XSRF-TOKEN
cookie with the csrf token on every response. This cookie is used for ajax requests and is automatically added to the header for axios for example.
I am wondering why is it required to add the csrf token to every HTML form. Why could you not just use the already existing X-XSRF-TOKEN
cookie to validate the csrf token. I understand there is the issue of same site cookies, and if your csrf cookie is set to lax
or none
the cookie would be sent from an external site if they would POST to my site. However this issue can be solved by setting the same site to strict
then there would be no need to set the csrf token on every form which is kind of annoying to do and remember.
Is there some security concern I am missing on why we just cant use a strict
cookie for validating the csrf token?