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

Improve the error handling for bad invites received over federation #2323

Merged
merged 1 commit into from
Jul 4, 2017
Merged
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
19 changes: 17 additions & 2 deletions synapse/handlers/federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def __init__(self, hs):
self.server_name = hs.hostname
self.keyring = hs.get_keyring()
self.action_generator = hs.get_action_generator()
self.is_mine_id = hs.is_mine_id

self.replication_layer.set_handler(self)

Expand Down Expand Up @@ -1072,6 +1073,20 @@ def on_invite_request(self, origin, pdu):
if is_blocked:
raise SynapseError(403, "This room has been blocked on this server")

membership = event.content.get("membership")
if event.type != EventTypes.Member or membership != Membership.INVITE:
raise SynapseError(400, "The event was not an m.room.member invite event")

sender_domain = get_domain_from_id(event.sender)
if sender_domain != origin:
raise SynapseError(400, "The invite event was not from the server sending it")

if event.state_key is None:
raise SynapseError(400, "The invite event did not have a state key")

if not self.is_mine_id(event.state_key):
raise SynapseError(400, "The invite event must be for this server")

event.internal_metadata.outlier = True
event.internal_metadata.invite_from_remote = True

Expand Down Expand Up @@ -1280,7 +1295,7 @@ def get_state_for_pdu(self, room_id, event_id):
for event in res:
# We sign these again because there was a bug where we
# incorrectly signed things the first time round
if self.hs.is_mine_id(event.event_id):
if self.is_mine_id(event.event_id):
event.signatures.update(
compute_event_signature(
event,
Expand Down Expand Up @@ -1353,7 +1368,7 @@ def get_persisted_pdu(self, origin, event_id, do_auth=True):
)

if event:
if self.hs.is_mine_id(event.event_id):
if self.is_mine_id(event.event_id):
# FIXME: This is a temporary work around where we occasionally
# return events slightly differently than when they were
# originally signed
Expand Down