You wrote: Given that a Rails session cookie expires only after the browsing session ends (i.e. when the web browser is closed), what are the ways in which this cookie (and the CSRF token it includes) can be changed without closing the browser?
First, your hypothesis is correct. However, how you could do this is worth considering.
Presumptive presumption requires focusing on two levels.
One: a saved cookie is not deleted when a web browsing session ends, unless something has been encoded in this way; The cookie is probably saved until the cookie timeout expires, so itโs likely that the next access to the page will use the old token, but since developers usually allow the page to be refreshed with a โnew loginโ, they can also refresh the token at that time. See @ Shikhar-Mann's Answer for a better understanding of sign_out_user.
Two: the cookie does not need to be changed for this problem, it is a CSRF token mismatch problem.
So, the main question: how can we have an inconsistent CSRF token that would be easier to answer: old data on the client due to a long wait, which leads to a timeout on the server, which invalidates the CSRF token during the delay. If the web page is not configured / created, as well as timeout and redirection, the client / user will never know.
Also, can I assume that CSRF is NOT persistent? It really isn't that important if you can access form data; I usually create a hidden field with CSRF data and use it instead. CSRF does not live very long, and session data is saved.
Antonio Ciolino
source share