summaryrefslogtreecommitdiffstats
path: root/meta-python/recipes-devtools/python/python3-django
diff options
context:
space:
mode:
Diffstat (limited to 'meta-python/recipes-devtools/python/python3-django')
-rw-r--r--meta-python/recipes-devtools/python/python3-django/CVE-2024-39329.patch111
1 files changed, 111 insertions, 0 deletions
diff --git a/meta-python/recipes-devtools/python/python3-django/CVE-2024-39329.patch b/meta-python/recipes-devtools/python/python3-django/CVE-2024-39329.patch
new file mode 100644
index 0000000000..c302c0df18
--- /dev/null
+++ b/meta-python/recipes-devtools/python/python3-django/CVE-2024-39329.patch
@@ -0,0 +1,111 @@
1From 156d3186c96e3ec2ca73b8b25dc2ef366e38df14 Mon Sep 17 00:00:00 2001
2From: Michael Manfre <mike@manfre.net>
3Date: Fri, 14 Jun 2024 22:12:58 -0400
4Subject: [PATCH] Fixed CVE-2024-39329 -- Standarized timing of
5 verify_password() when checking unusuable passwords.
6
7Refs #20760.
8
9Thanks Michael Manfre for the fix and to Adam Johnson for the review.
10
11CVE: CVE-2024-39329
12
13Upstream-Status: Backport
14https://github.com/django/django/commit/156d3186c96e3ec2ca73b8b25dc2ef366e38df14
15
16Signed-off-by: Michael Manfre <mike@manfre.net>
17Signed-off-by: Saravanan <saravanan.kadambathursubramaniyam@windriver.com>
18---
19 django/contrib/auth/hashers.py | 10 ++++++++--
20 docs/releases/2.2.28.txt | 7 +++++++
21 tests/auth_tests/test_hashers.py | 32 ++++++++++++++++++++++++++++++++
22 3 files changed, 47 insertions(+), 2 deletions(-)
23
24diff --git a/django/contrib/auth/hashers.py b/django/contrib/auth/hashers.py
25index 1e8d754..4acb81d 100644
26--- a/django/contrib/auth/hashers.py
27+++ b/django/contrib/auth/hashers.py
28@@ -36,14 +36,20 @@ def check_password(password, encoded, setter=None, preferred='default'):
29 If setter is specified, it'll be called when you need to
30 regenerate the password.
31 """
32- if password is None or not is_password_usable(encoded):
33- return False
34+ fake_runtime = password is None or not is_password_usable(encoded)
35
36 preferred = get_hasher(preferred)
37 try:
38 hasher = identify_hasher(encoded)
39 except ValueError:
40 # encoded is gibberish or uses a hasher that's no longer installed.
41+ fake_runtime = True
42+
43+ if fake_runtime:
44+ # Run the default password hasher once to reduce the timing difference
45+ # between an existing user with an unusable password and a nonexistent
46+ # user or missing hasher (similar to #20760).
47+ make_password(get_random_string(UNUSABLE_PASSWORD_SUFFIX_LENGTH))
48 return False
49
50 hasher_changed = hasher.algorithm != preferred.algorithm
51diff --git a/docs/releases/2.2.28.txt b/docs/releases/2.2.28.txt
52index f3fb298..22fa80e 100644
53--- a/docs/releases/2.2.28.txt
54+++ b/docs/releases/2.2.28.txt
55@@ -124,3 +124,10 @@ CVE-2025-57833: Potential SQL injection in ``FilteredRelation`` column aliases
56 using a suitably crafted dictionary, with dictionary expansion, as the
57 ``**kwargs`` passed to :meth:`.QuerySet.annotate` or :meth:`.QuerySet.alias`.
58
59+CVE-2024-39329: Username enumeration through timing difference for users with unusable passwords
60+================================================================================================
61+
62+The :meth:`~django.contrib.auth.backends.ModelBackend.authenticate()` method
63+allowed remote attackers to enumerate users via a timing attack involving login
64+requests for users with unusable passwords.
65+
66diff --git a/tests/auth_tests/test_hashers.py b/tests/auth_tests/test_hashers.py
67index ee6441b..391b3cc 100644
68--- a/tests/auth_tests/test_hashers.py
69+++ b/tests/auth_tests/test_hashers.py
70@@ -433,6 +433,38 @@ class TestUtilsHashPass(SimpleTestCase):
71 check_password('wrong_password', encoded)
72 self.assertEqual(hasher.harden_runtime.call_count, 1)
73
74+ def test_check_password_calls_make_password_to_fake_runtime(self):
75+ hasher = get_hasher("default")
76+ cases = [
77+ (None, None, None), # no plain text password provided
78+ ("foo", make_password(password=None), None), # unusable encoded
79+ ("letmein", make_password(password="letmein"), ValueError), # valid encoded
80+ ]
81+ for password, encoded, hasher_side_effect in cases:
82+ with (
83+ self.subTest(encoded=encoded),
84+ mock.patch(
85+ "django.contrib.auth.hashers.identify_hasher",
86+ side_effect=hasher_side_effect,
87+ ) as mock_identify_hasher,
88+ mock.patch(
89+ "django.contrib.auth.hashers.make_password"
90+ ) as mock_make_password,
91+ mock.patch(
92+ "django.contrib.auth.hashers.get_random_string",
93+ side_effect=lambda size: "x" * size,
94+ ),
95+ mock.patch.object(hasher, "verify"),
96+ ):
97+ # Ensure make_password is called to standardize timing.
98+ check_password(password, encoded)
99+ self.assertEqual(hasher.verify.call_count, 0)
100+ self.assertEqual(mock_identify_hasher.mock_calls, [mock.call(encoded)])
101+ self.assertEqual(
102+ mock_make_password.mock_calls,
103+ [mock.call("x" * UNUSABLE_PASSWORD_SUFFIX_LENGTH)],
104+ )
105+
106
107 class BasePasswordHasherTests(SimpleTestCase):
108 not_implemented_msg = 'subclasses of BasePasswordHasher must provide %s() method'
109--
1102.40.0
111