Skip to content

Commit

Permalink
Compare tokens with a constant_time_compare
Browse files Browse the repository at this point in the history
  • Loading branch information
mattrobenolt committed Feb 13, 2015
1 parent 0022787 commit d863d48
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions sudo/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
:license: BSD, see LICENSE for more details.
"""
from django.core.signing import BadSignature
from django.utils.crypto import get_random_string
from django.utils.crypto import get_random_string, constant_time_compare

from sudo.settings import COOKIE_NAME, COOKIE_AGE, COOKIE_SALT

Expand Down Expand Up @@ -52,8 +52,10 @@ def has_sudo_privileges(request):
try:
request._sudo = (
request.user.is_authenticated() and
request.get_signed_cookie(COOKIE_NAME, salt=COOKIE_SALT, max_age=COOKIE_AGE) ==
request.session[COOKIE_NAME]
constant_time_compare(
request.get_signed_cookie(COOKIE_NAME, salt=COOKIE_SALT, max_age=COOKIE_AGE),
request.session[COOKIE_NAME]
)
)
except (KeyError, BadSignature):
request._sudo = False
Expand Down

0 comments on commit d863d48

Please sign in to comment.