Skip to content

Commit d5d8942

Browse files
committed
Fix a security issue in the auth system. Disclosure and new release forthcoming.
git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@15034 bcc190cf-cafb-0310-a4f2-bffc1f526a37
1 parent 85207a2 commit d5d8942

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

django/contrib/auth/tests/tokens.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,14 @@ def _today(self):
5050

5151
p2 = Mocked(date.today() + timedelta(settings.PASSWORD_RESET_TIMEOUT_DAYS + 1))
5252
self.assertFalse(p2.check_token(user, tk1))
53+
54+
def test_date_length(self):
55+
"""
56+
Make sure we don't allow overly long dates, causing a potential DoS.
57+
"""
58+
user = User.objects.create_user('ima1337h4x0r', '[email protected]', 'p4ssw0rd')
59+
p0 = PasswordResetTokenGenerator()
60+
61+
# This will put a 14-digit base36 timestamp into the token, which is too large.
62+
tk1 = p0._make_token_with_timestamp(user, 175455491841851871349)
63+
self.assertFalse(p0.check_token(user, tk1))

django/contrib/auth/urls.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# These URLs are normally mapped to /admin/urls.py. This URLs file is
1+
# These URLs are normally mapped to /admin/urls.py. This URLs file is
22
# provided as a convenience to those who want to deploy these URLs elsewhere.
33
# This file is also used to provide a reliable view deployment for test purposes.
44

@@ -11,7 +11,7 @@
1111
(r'^password_change/done/$', 'django.contrib.auth.views.password_change_done'),
1212
(r'^password_reset/$', 'django.contrib.auth.views.password_reset'),
1313
(r'^password_reset/done/$', 'django.contrib.auth.views.password_reset_done'),
14-
(r'^reset/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$', 'django.contrib.auth.views.password_reset_confirm'),
14+
(r'^reset/(?P<uidb36>[0-9A-Za-z]{1,13})-(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$', 'django.contrib.auth.views.password_reset_confirm'),
1515
(r'^reset/done/$', 'django.contrib.auth.views.password_reset_complete'),
1616
)
1717

django/utils/http.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,13 @@ def http_date(epoch_seconds=None):
7373

7474
def base36_to_int(s):
7575
"""
76-
Convertd a base 36 string to an integer
76+
Converts a base 36 string to an ``int``. To prevent
77+
overconsumption of server resources, raises ``ValueError` if the
78+
input is longer than 13 base36 digits (13 digits is sufficient to
79+
base36-encode any 64-bit integer).
7780
"""
81+
if len(s) > 13:
82+
raise ValueError("Base36 input too large")
7883
return int(s, 36)
7984

8085
def int_to_base36(i):

0 commit comments

Comments
 (0)