Projet

Général

Profil

Bug #5617

CSRF token rotation since Django 1.5.2 has broken usability of login and registration page

Ajouté par Benjamin Dauvergne il y a plus de 9 ans. Mis à jour il y a environ 9 ans.

Statut:
Fermé
Priorité:
Haut
Assigné à:
Catégorie:
-
Version cible:
Début:
02 octobre 2014
Echéance:
% réalisé:

100%

Temps estimé:
Patch proposed:
Oui
Planning:

Description

Since the CSRF token is rotated on each login, lot of users see 403 errors when submitting login or registration because they multitask a lot. To fix that we will change three things:
  • 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 setting CSRF_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

Révision 40b90493 (diff)
Ajouté par Benjamin Dauvergne il y a plus de 9 ans

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)

Révision d570b728 (diff)
Ajouté par Benjamin Dauvergne il y a plus de 9 ans

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.

Révision 9290f3f4 (diff)
Ajouté par Benjamin Dauvergne il y a plus de 9 ans

Use new mixin on registration view to show a form error on CSRF token validation error instead of a redirect (refs #5617)

Révision 14a0e25e (diff)
Ajouté par Benjamin Dauvergne il y a plus de 9 ans

Update french translation (fixes #5617)

Révision 143528d0 (diff)
Ajouté par Benjamin Dauvergne il y a plus de 9 ans

Use new CSRF cookie validation on login view (refs #5617)

Révision 25ef99ff (diff)
Ajouté par Benjamin Dauvergne il y a environ 9 ans

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)

Révision 31c743d8 (diff)
Ajouté par Benjamin Dauvergne il y a environ 9 ans

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.

Révision 0baa91cf (diff)
Ajouté par Benjamin Dauvergne il y a environ 9 ans

Use new mixin on registration view to show a form error on CSRF token validation error instead of a redirect (refs #5617)

Révision 8fd5446d (diff)
Ajouté par Benjamin Dauvergne il y a environ 9 ans

Update french translation (fixes #5617)

Révision f2573707 (diff)
Ajouté par Benjamin Dauvergne il y a environ 9 ans

Use new CSRF cookie validation on login view (refs #5617)

Historique

#1

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
#2

Mis à jour par Benjamin Dauvergne il y a plus de 9 ans

  • Statut changé de Nouveau à En cours
  • Assigné à mis à Benjamin Dauvergne
#3

Mis à jour par Serghei Mihai il y a plus de 9 ans

It works for me

#4

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 reworked my patch, the recipe will serve to other projects:
  • 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.

#5

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.

#6

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
#7

Mis à jour par Benjamin Dauvergne il y a environ 9 ans

  • Version cible mis à 2.1.12
#8

Mis à jour par Benjamin Dauvergne il y a environ 9 ans

  • Fichier 0001-On-login-view-check-the-CSRF-cookie-only-after-check.patch supprimé
#9

Mis à jour par Benjamin Dauvergne il y a environ 9 ans

  • Fichier 0002-Use-setting-CSRF_FAILURE_VIEW-to-prevent-user-seeing.patch supprimé
#10

Mis à jour par Benjamin Dauvergne il y a environ 9 ans

  • Fichier 0003-If-the-user-is-already-logged-redirect-user-to-next-.patch supprimé
#11

Mis à jour par Benjamin Dauvergne il y a environ 9 ans

  • Fichier 0004-Remove-CSRF-protection-from-registration-view-as-the.patch supprimé
#12

Mis à jour par Benjamin Dauvergne il y a environ 9 ans

  • Fichier 0005-Update-french-translation-fixes-5617.patch supprimé
#13

Mis à jour par Benjamin Dauvergne il y a environ 9 ans

  • Fichier 0001-Use-setting-CSRF_FAILURE_VIEW-to-prevent-user-seeing.patch supprimé
#14

Mis à jour par Benjamin Dauvergne il y a environ 9 ans

  • Fichier 0002-Allow-validation-of-CSRF-cookie-to-be-done-in-view-u.patch supprimé
#15

Mis à jour par Benjamin Dauvergne il y a environ 9 ans

  • Fichier 0003-Use-new-mixin-on-registration-view-to-show-a-form-er.patch supprimé
#16

Mis à jour par Benjamin Dauvergne il y a environ 9 ans

  • Fichier 0004-Update-french-translation-fixes-5617.patch supprimé
#17

Mis à jour par Benjamin Dauvergne il y a environ 9 ans

  • Fichier 0005-Use-new-CSRF-cookie-validation-on-login-view-refs-56.patch supprimé
#20

Mis à jour par Benjamin Dauvergne il y a environ 9 ans

Thanks for updating patch to master.

#21

Mis à jour par Benjamin Dauvergne il y a environ 9 ans

  • Statut changé de Nouveau à Résolu (à déployer)
#22

Mis à jour par Benjamin Dauvergne il y a environ 9 ans

  • Statut changé de Résolu (à déployer) à Fermé

Formats disponibles : Atom PDF