Open mbarton opened 3 months ago
I agree better that than what is happening. I am confused though as we used to have a custom 403 page. I am not clear why at least that is not rendering instead of the django one.
Thank you for looking into this :) - I will let the Clinicians know.
Reported via email by @SAbdin93. Customers see an opaque CSRF error message when trying to log in:
We can see from the production logs that it happens occasionally and is caused by a mismatch between the CSRF cookie and the hidden token in the login form:
I've verified using the logs that the user reporting the error saw this exact error message as they were then able to log in afterwards.
The error doesn't stop you logging in by opening another tab and trying again. I'm not exactly sure how it happens but I think it's to do with old tabs staying open in the browser. I've been able to reproduce with the following steps:
We can't fix this problem per se without custom logic to retry the request with a new CSRF token which defeats much of the point of having it in the first place. I don't think we should remove it as CSRF tokens on login pages are useful in avoiding attacks where users are tricked into logging in to an account that isn't actually their own (see this Stack Overflow thread).
It is quite straight forward though to punt them back to the login form to try again rather than showing a big angry technical error message. See https://forum.djangoproject.com/t/forbidden-csrf-token-from-post-incorrect-accounts-login/19146/1.