diff options
| author | Luke Plant <L.Plant.98@cantab.net> | 2010-10-14 20:54:30 +0000 |
|---|---|---|
| committer | Luke Plant <L.Plant.98@cantab.net> | 2010-10-14 20:54:30 +0000 |
| commit | 45c7f427ce830dd1b2f636fb9c244fda9201cadb (patch) | |
| tree | adf54547764f651e2bf20e6c259f8a42c7b87463 /tests | |
| parent | 36f2f7ee7c806824b28bdf669296cc0730fe6100 (diff) | |
Fixed #14445 - Use HMAC and constant-time comparison functions where needed.
All adhoc MAC applications have been updated to use HMAC, using SHA1 to
generate unique keys for each application based on the SECRET_KEY, which is
common practice for this situation. In all cases, backwards compatibility
with existing hashes has been maintained, aiming to phase this out as per
the normal deprecation process. In this way, under most normal
circumstances the old hashes will have expired (e.g. by session expiration
etc.) before they become invalid.
In the case of the messages framework and the cookie backend, which was
already using HMAC, there is the possibility of a backwards incompatibility
if the SECRET_KEY is shorter than the default 50 bytes, but the low
likelihood and low impact meant compatibility code was not worth it.
All known instances where tokens/hashes were compared using simple string
equality, which could potentially open timing based attacks, have also been
fixed using a constant-time comparison function.
There are no known practical attacks against the existing implementations,
so these security improvements will not be backported.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@14218 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/regressiontests/comment_tests/tests/comment_form_tests.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/regressiontests/comment_tests/tests/comment_form_tests.py b/tests/regressiontests/comment_tests/tests/comment_form_tests.py index 142931bfd6..b9261d1330 100644 --- a/tests/regressiontests/comment_tests/tests/comment_form_tests.py +++ b/tests/regressiontests/comment_tests/tests/comment_form_tests.py @@ -2,6 +2,7 @@ import time from django.conf import settings from django.contrib.comments.models import Comment from django.contrib.comments.forms import CommentForm +from django.utils.hashcompat import sha_constructor from regressiontests.comment_tests.models import Article from regressiontests.comment_tests.tests import CommentTestCase @@ -43,6 +44,23 @@ class CommentFormTests(CommentTestCase): def testObjectPKTampering(self): self.tamperWithForm(object_pk="3") + def testDjango12Hash(self): + # Ensure we can use the hashes generated by Django 1.2 + a = Article.objects.get(pk=1) + d = self.getValidData(a) + + content_type = d['content_type'] + object_pk = d['object_pk'] + timestamp = d['timestamp'] + + # The Django 1.2 method hard-coded here: + info = (content_type, object_pk, timestamp, settings.SECRET_KEY) + security_hash = sha_constructor("".join(info)).hexdigest() + + d['security_hash'] = security_hash + f = CommentForm(a, data=d) + self.assertTrue(f.is_valid(), f.errors) + def testSecurityErrors(self): f = self.tamperWithForm(honeypot="I am a robot") self.assert_("honeypot" in f.security_errors()) |
