Skip to content

Commit 052dd24

Browse files
committed
Merge branch 'pr890'
* pr890: Revert the SECRET_KEY change per the discussion on PR#890 Fix issue that occurs when using bytes as secret key. The Django secret key can and should be random bytes which may or may not be decodable to UTF-8.
2 parents 72b009c + 08724cb commit 052dd24

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

debug_toolbar/panels/sql/forms.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from django.core.exceptions import ValidationError
1010
from django.db import connections
1111
from django.utils.crypto import constant_time_compare
12-
from django.utils.encoding import force_text
12+
from django.utils.encoding import force_bytes
1313
from django.utils.functional import cached_property
1414

1515
from debug_toolbar.panels.sql.utils import reformat_sql
@@ -79,12 +79,10 @@ def reformat_sql(self):
7979
return reformat_sql(self.cleaned_data['sql'])
8080

8181
def make_hash(self, data):
82-
items = [data['sql'], data['params']]
83-
# Replace lines endings with spaces to preserve the hash value
84-
# even when the browser normalizes \r\n to \n in inputs.
85-
items = [' '.join(force_text(item).splitlines()) for item in items]
86-
return hmac.new(settings.SECRET_KEY.encode('utf-8'),
87-
''.join(items).encode('utf-8'), hashlib.sha1).hexdigest()
82+
m = hmac.new(key=force_bytes(settings.SECRET_KEY), digestmod=hashlib.sha1)
83+
for item in [data['sql'], data['params']]:
84+
m.update(force_bytes(item))
85+
return m.hexdigest()
8886

8987
@property
9088
def connection(self):

0 commit comments

Comments
 (0)