Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
Merge pull request #603 from mozilla-services/bug/571
Browse files Browse the repository at this point in the history
bug: Check tokens in constant time
  • Loading branch information
pjenvey authored Aug 17, 2016
2 parents 95d6d41 + ed7ce2b commit 7dc79e4
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions autopush/endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
ProvisionedThroughputExceededException,
)
from cryptography.fernet import InvalidToken
from cryptography.hazmat.primitives import constant_time
from twisted.internet.defer import Deferred
from twisted.internet.threads import deferToThread

Expand Down Expand Up @@ -868,11 +869,11 @@ def _validate_auth(self, uaid):
if token_type.lower() not in AUTH_SCHEMES:
return False
if self.ap_settings.bear_hash_key:
is_valid = False
for key in self.ap_settings.bear_hash_key:
token = generate_hash(key, uaid)
if rtoken == token:
return True
return False
is_valid |= constant_time.bytes_eq(rtoken, token)
return is_valid
else:
return True

Expand Down

0 comments on commit 7dc79e4

Please sign in to comment.