Bug #5617
CSRF token rotation since Django 1.5.2 has broken usability of login and registration page
100%
Description
- on login page, we wait after having validated that the user is not already logged to let the the CSRF token check happen, so that we can just redirect to the next_url if it is
- we add a new
authentic2.views.csrf_failure_view()
which will be used through the settingCSRF_FAILURE_VIEW
, this view will just reload the current page using a redirection and display a warning thourgh the messages framework that alerts the user that as he logged in since he loaded this page, the page became out of date. - we removed CSRF protection on the registration view since it's a public page anyway and nothing can be gained from CSRF on the registration page.
Fichiers
Révisions associées
Allow validation of CSRF cookie to be done in view using a CBV mixin or an helper function (refs #5617)
Use the CBV for a do-nothing use or on a function based view you must
apply the decorators @csrf_exempt and @ensure_csrf_cookie on your view
(in this order) and use utils.csrf_token_check(request, form) to check
for the cookie before validating your form.
Use new mixin on registration view to show a form error on CSRF token validation error instead of a redirect (refs #5617)
Update french translation (fixes #5617)
Use new CSRF cookie validation on login view (refs #5617)
Use setting CSRF_FAILURE_VIEW to prevent user seeing 403 on CSRF failure, instead redirect them to the same page and display a warning (refs #5617)
Allow validation of CSRF cookie to be done in view using a CBV mixin or an helper function (refs #5617)
Use the CBV for a do-nothing use or on a function based view you must
apply the decorators @csrf_exempt and @ensure_csrf_cookie on your view
(in this order) and use utils.csrf_token_check(request, form) to check
for the cookie before validating your form.
Use new mixin on registration view to show a form error on CSRF token validation error instead of a redirect (refs #5617)
Update french translation (fixes #5617)
Use new CSRF cookie validation on login view (refs #5617)
Historique
Mis à jour par Benjamin Dauvergne il y a plus de 9 ans
- Fichier 0001-On-login-view-check-the-CSRF-cookie-only-after-check.patch ajouté
- Fichier 0002-Use-setting-CSRF_FAILURE_VIEW-to-prevent-user-seeing.patch ajouté
- Fichier 0003-If-the-user-is-already-logged-redirect-user-to-next-.patch ajouté
- Fichier 0004-Remove-CSRF-protection-from-registration-view-as-the.patch ajouté
- Fichier 0005-Update-french-translation-fixes-5617.patch ajouté
- Patch proposed changé de Non à Oui
Mis à jour par Benjamin Dauvergne il y a plus de 9 ans
- Statut changé de Nouveau à En cours
- Assigné à mis à Benjamin Dauvergne
Mis à jour par Benjamin Dauvergne il y a plus de 9 ans
- Fichier 0001-Use-setting-CSRF_FAILURE_VIEW-to-prevent-user-seeing.patch ajouté
- Fichier 0002-Allow-validation-of-CSRF-cookie-to-be-done-in-view-u.patch ajouté
- Fichier 0003-Use-new-mixin-on-registration-view-to-show-a-form-er.patch ajouté
- Fichier 0004-Update-french-translation-fixes-5617.patch ajouté
- Fichier 0005-Use-new-CSRF-cookie-validation-on-login-view-refs-56.patch ajouté
- I still change the default CSRF cookie validation view
- I added a CBV mixin and an utility function in order to merge CSRF validation inside form validation, CSRF errors are now reported as form errors
- I used the CBV on the registration view and the manual implementation in the default login/password frontend view
Here commes new patches, review is welcome.
Mis à jour par Benjamin Dauvergne il y a plus de 9 ans
To test them, open a form (registration or login) in a tab, then open a new tab, login then logout in this tab, them come back to the first tab and try to use the form. The form must validate on first try. If it does not validate then it does not report CSRF validation errors, as the CSRF cookie will be updated after re-display of the form, and so you will not really test this patch.
Mis à jour par Benjamin Dauvergne il y a plus de 9 ans
- Statut changé de En cours à Résolu (à déployer)
- % réalisé changé de 0 à 100
Appliqué par commit 14a0e25eed69f80c3c2a5bc9ce5a1d271e2ab38e.
Mis à jour par Benjamin Dauvergne il y a environ 9 ans
- Fichier
0001-On-login-view-check-the-CSRF-cookie-only-after-check.patchsupprimé
Mis à jour par Benjamin Dauvergne il y a environ 9 ans
- Fichier
0002-Use-setting-CSRF_FAILURE_VIEW-to-prevent-user-seeing.patchsupprimé
Mis à jour par Benjamin Dauvergne il y a environ 9 ans
- Fichier
0003-If-the-user-is-already-logged-redirect-user-to-next-.patchsupprimé
Mis à jour par Benjamin Dauvergne il y a environ 9 ans
- Fichier
0004-Remove-CSRF-protection-from-registration-view-as-the.patchsupprimé
Mis à jour par Benjamin Dauvergne il y a environ 9 ans
- Fichier
0005-Update-french-translation-fixes-5617.patchsupprimé
Mis à jour par Benjamin Dauvergne il y a environ 9 ans
- Fichier
0001-Use-setting-CSRF_FAILURE_VIEW-to-prevent-user-seeing.patchsupprimé
Mis à jour par Benjamin Dauvergne il y a environ 9 ans
- Fichier
0002-Allow-validation-of-CSRF-cookie-to-be-done-in-view-u.patchsupprimé
Mis à jour par Benjamin Dauvergne il y a environ 9 ans
- Fichier
0003-Use-new-mixin-on-registration-view-to-show-a-form-er.patchsupprimé
Mis à jour par Benjamin Dauvergne il y a environ 9 ans
- Fichier
0004-Update-french-translation-fixes-5617.patchsupprimé
Mis à jour par Benjamin Dauvergne il y a environ 9 ans
- Fichier
0005-Use-new-CSRF-cookie-validation-on-login-view-refs-56.patchsupprimé
Mis à jour par Benjamin Dauvergne il y a environ 9 ans
- Fichier 0001-Use-setting-CSRF_FAILURE_VIEW-to-prevent-user-seeing.patch 0001-Use-setting-CSRF_FAILURE_VIEW-to-prevent-user-seeing.patch ajouté
- Fichier 0002-Allow-validation-of-CSRF-cookie-to-be-done-in-view-u.patch 0002-Allow-validation-of-CSRF-cookie-to-be-done-in-view-u.patch ajouté
- Fichier 0003-Use-new-mixin-on-registration-view-to-show-a-form-er.patch 0003-Use-new-mixin-on-registration-view-to-show-a-form-er.patch ajouté
- Fichier 0004-Update-french-translation-fixes-5617.patch 0004-Update-french-translation-fixes-5617.patch ajouté
- Fichier 0005-Use-new-CSRF-cookie-validation-on-login-view-refs-56.patch 0005-Use-new-CSRF-cookie-validation-on-login-view-refs-56.patch ajouté
- Statut changé de Résolu (à déployer) à Nouveau
- Priorité changé de Normal à Haut
Update to last master state.
Mis à jour par Serghei Mihai il y a environ 9 ans
- Fichier 0002-Allow-validation-of-CSRF-cookie-to-be-done-in-view-u.patch 0002-Allow-validation-of-CSRF-cookie-to-be-done-in-view-u.patch ajouté
- Fichier 0004-Update-french-translation-fixes-5617.patch 0004-Update-french-translation-fixes-5617.patch ajouté
- Fichier 0003-Use-new-mixin-on-registration-view-to-show-a-form-er.patch 0003-Use-new-mixin-on-registration-view-to-show-a-form-er.patch ajouté
Here are modified the patches 2, 3, 4 fixing some errors and adaptations to last master
state
Mis à jour par Benjamin Dauvergne il y a environ 9 ans
- Statut changé de Nouveau à Résolu (à déployer)
Appliqué par commit 8fd5446dc0da2eccf48c02617527d8848be55501.
Mis à jour par Benjamin Dauvergne il y a environ 9 ans
- Statut changé de Résolu (à déployer) à Fermé
Use setting CSRF_FAILURE_VIEW to prevent user seeing 403 on CSRF failure, instead redirect them to the same page and display a warning (refs #5617)