Say we implement CSRF tokens that expire when the session expires. A user opens a website and logs in. The session expires. Then in another tab, they log in again, go to the expired tab, and try to perform an action that requires a valid token. How could we avoid hindering the user from making the request while maintaining security?
I was thinking perhaps we could preserve the user's intent, and some how trigger a chain of events that securely leads to another fresh token being automatically obtained and then submitted with the original attempt.
Is that feasible? How would that back-and-forth work? And how would would the CSRF token have to be communicated, in all directions? Cookie? Body? POST? Does it matter? Would it rely on CORS headers for security, or is it inherently secure?
Couldn't that request be mimicked by a CSRF attack? Because that request would surely mimic a CSRF with an old, leaked token, defeating the purpose of expiring tokens?