I started using zend-expressive-csrf to protect my login page against CSRF following the documentation (CSRF Guards and CSRF Guard Middleware).
It works (of course) really great except when the session expires between the load of the page and the submit of the form. For example, if a user opens the login page in a tab but don’t login and comes back some time later (when the session expired), the login “process” will fail.
What would be the best way to take care of that situation ?
(increasing the time before session times out is, of course, not really a solution)
I don’t know if there is a best practice. What I would do is represent the form again and display a message that the token expired and ask the user to submit the form again.