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

Commit

Permalink
Reject instead of erroring on invalid membership events. (#15564)
Browse files Browse the repository at this point in the history
Instead of resulting in an internal server error for invalid events,
return that the event is invalid.
  • Loading branch information
clokep authored May 15, 2023
1 parent ba6b21c commit eb3c182
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
1 change: 1 addition & 0 deletions changelog.d/15564.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a long-standing bug where an invalid membership event could cause an internal server error.
17 changes: 11 additions & 6 deletions synapse/event_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -1054,10 +1054,15 @@ def _verify_third_party_invite(
"""
if "third_party_invite" not in event.content:
return False
if "signed" not in event.content["third_party_invite"]:
third_party_invite = event.content["third_party_invite"]
if not isinstance(third_party_invite, collections.abc.Mapping):
return False
signed = event.content["third_party_invite"]["signed"]
for key in {"mxid", "token"}:
if "signed" not in third_party_invite:
return False
signed = third_party_invite["signed"]
if not isinstance(signed, collections.abc.Mapping):
return False
for key in {"mxid", "token", "signatures"}:
if key not in signed:
return False

Expand All @@ -1075,8 +1080,6 @@ def _verify_third_party_invite(

if signed["mxid"] != event.state_key:
return False
if signed["token"] != token:
return False

for public_key_object in get_public_keys(invite_event):
public_key = public_key_object["public_key"]
Expand All @@ -1088,7 +1091,9 @@ def _verify_third_party_invite(
verify_key = decode_verify_key_bytes(
key_name, decode_base64(public_key)
)
verify_signed_json(signed, server, verify_key)
# verify_signed_json incorrectly states it wants a dict, it
# just needs a mapping.
verify_signed_json(signed, server, verify_key) # type: ignore[arg-type]

# We got the public key from the invite, so we know that the
# correct server signed the signed bundle.
Expand Down

0 comments on commit eb3c182

Please sign in to comment.