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

Commit

Permalink
Log when we receive a /make_* request from a different origin
Browse files Browse the repository at this point in the history
  • Loading branch information
richvdh committed Jul 26, 2019
1 parent 2d573e2 commit d102065
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
1 change: 1 addition & 0 deletions changelog.d/5744.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Log when we receive a `/make_*` request from a different origin.
4 changes: 2 additions & 2 deletions synapse/federation/federation_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ def on_make_join_request(self, origin, room_id, user_id, supported_versions):
logger.warn("Room version %s not in %s", room_version, supported_versions)
raise IncompatibleRoomVersionError(room_version=room_version)

pdu = yield self.handler.on_make_join_request(room_id, user_id)
pdu = yield self.handler.on_make_join_request(origin, room_id, user_id)
time_now = self._clock.time_msec()
defer.returnValue(
{"event": pdu.get_pdu_json(time_now), "room_version": room_version}
Expand Down Expand Up @@ -423,7 +423,7 @@ def on_send_join_request(self, origin, content, room_id):
def on_make_leave_request(self, origin, room_id, user_id):
origin_host, _ = parse_server_name(origin)
yield self.check_server_matches_acl(origin_host, room_id)
pdu = yield self.handler.on_make_leave_request(room_id, user_id)
pdu = yield self.handler.on_make_leave_request(origin, room_id, user_id)

room_version = yield self.store.get_room_version(room_id)

Expand Down
37 changes: 35 additions & 2 deletions synapse/handlers/federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1204,11 +1204,28 @@ def _handle_queued_pdus(self, room_queue):

@defer.inlineCallbacks
@log_function
def on_make_join_request(self, room_id, user_id):
def on_make_join_request(self, origin, room_id, user_id):
""" We've received a /make_join/ request, so we create a partial
join event for the room and return that. We do *not* persist or
process it until the other server has signed it and sent it back.
Args:
origin (str): The (verified) server name of the requesting server.
room_id (str): Room to create join event in
user_id (str): The user to create the join for
Returns:
Deferred[FrozenEvent]
"""

if get_domain_from_id(user_id) != origin:
logger.info(
"Got /make_join request for user %r from different origin %s, ignoring",
user_id,
origin,
)
raise SynapseError(403, "User not from origin", Codes.FORBIDDEN)

event_content = {"membership": Membership.JOIN}

room_version = yield self.store.get_room_version(room_id)
Expand Down Expand Up @@ -1411,11 +1428,27 @@ def _make_and_verify_event(

@defer.inlineCallbacks
@log_function
def on_make_leave_request(self, room_id, user_id):
def on_make_leave_request(self, origin, room_id, user_id):
""" We've received a /make_leave/ request, so we create a partial
leave event for the room and return that. We do *not* persist or
process it until the other server has signed it and sent it back.
Args:
origin (str): The (verified) server name of the requesting server.
room_id (str): Room to create leave event in
user_id (str): The user to create the leave for
Returns:
Deferred[FrozenEvent]
"""
if get_domain_from_id(user_id) != origin:
logger.info(
"Got /make_leave request for user %r from different origin %s, ignoring",
user_id,
origin,
)
raise SynapseError(403, "User not from origin", Codes.FORBIDDEN)

room_version = yield self.store.get_room_version(room_id)
builder = self.event_builder_factory.new(
room_version,
Expand Down

0 comments on commit d102065

Please sign in to comment.