Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Fix 500 error from /consent form #3732

Merged
merged 3 commits into from
Aug 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/3732.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix bug introduced in v0.33.3rc1 which made the ToS give a 500 error
15 changes: 12 additions & 3 deletions synapse/rest/consent/consent_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def _async_render_GET(self, request):
version = parse_string(request, "v",
default=self._default_consent_version)
username = parse_string(request, "u", required=True)
userhmac = parse_string(request, "h", required=True)
userhmac = parse_string(request, "h", required=True, encoding=None)

self._check_hash(username, userhmac)

Expand Down Expand Up @@ -175,7 +175,7 @@ def _async_render_POST(self, request):
"""
version = parse_string(request, "v", required=True)
username = parse_string(request, "u", required=True)
userhmac = parse_string(request, "h", required=True)
userhmac = parse_string(request, "h", required=True, encoding=None)

self._check_hash(username, userhmac)

Expand Down Expand Up @@ -210,9 +210,18 @@ def _render_template(self, request, template_name, **template_args):
finish_request(request)

def _check_hash(self, userid, userhmac):
"""
Args:
userid (unicode):
userhmac (bytes):

Raises:
SynapseError if the hash doesn't match

"""
want_mac = hmac.new(
key=self._hmac_secret,
msg=userid,
msg=userid.encode('utf-8'),
digestmod=sha256,
).hexdigest()

Expand Down