diff options
| author | David Wobrock <david.wobrock@gmail.com> | 2023-03-06 16:18:03 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-03-08 10:48:04 +0100 |
| commit | 2396933ca99c6bfb53bda9e53968760316646e01 (patch) | |
| tree | 4e28cc9bf22bed440c3d42b0c1f6cb615aec849e /django/contrib/auth/base_user.py | |
| parent | 9b224579875e30203d079cc2fee83b116d98eb78 (diff) | |
Fixed #34384 -- Fixed session validation when rotation secret keys.
Bug in 0dcd549bbe36c060f536ec270d34d9e7d4b8e6c7.
Thanks Eric Zarowny for the report.
Diffstat (limited to 'django/contrib/auth/base_user.py')
| -rw-r--r-- | django/contrib/auth/base_user.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/django/contrib/auth/base_user.py b/django/contrib/auth/base_user.py index 5ee30bf59c..e205ccccf2 100644 --- a/django/contrib/auth/base_user.py +++ b/django/contrib/auth/base_user.py @@ -5,6 +5,7 @@ not in INSTALLED_APPS. import unicodedata import warnings +from django.conf import settings from django.contrib.auth import password_validation from django.contrib.auth.hashers import ( check_password, @@ -135,10 +136,18 @@ class AbstractBaseUser(models.Model): """ Return an HMAC of the password field. """ + return self._get_session_auth_hash() + + def get_session_auth_fallback_hash(self): + for fallback_secret in settings.SECRET_KEY_FALLBACKS: + yield self._get_session_auth_hash(secret=fallback_secret) + + def _get_session_auth_hash(self, secret=None): key_salt = "django.contrib.auth.models.AbstractBaseUser.get_session_auth_hash" return salted_hmac( key_salt, self.password, + secret=secret, algorithm="sha256", ).hexdigest() |
