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

Commit

Permalink
Prevent kicking users who aren't in the room (#4999)
Browse files Browse the repository at this point in the history
Prevent kick events from succeeding if the user is not currently in the room.
  • Loading branch information
anoadragon453 authored Apr 4, 2019
1 parent 9f5d206 commit db265f0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog.d/4999.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Prevent the ability to kick users from a room they aren't in.
9 changes: 9 additions & 0 deletions synapse/handlers/room_member.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,9 @@ def _update_membership(
room_id, latest_event_ids=latest_event_ids,
)

# TODO: Refactor into dictionary of explicitly allowed transitions
# between old and new state, with specific error messages for some
# transitions and generic otherwise
old_state_id = current_state_ids.get((EventTypes.Member, target.to_string()))
if old_state_id:
old_state = yield self.store.get_event(old_state_id, allow_none=True)
Expand All @@ -446,6 +449,9 @@ def _update_membership(
if same_sender and same_membership and same_content:
defer.returnValue(old_state)

if old_membership in ["ban", "leave"] and action == "kick":
raise AuthError(403, "The target user is not in the room")

# we don't allow people to reject invites to the server notice
# room, but they can leave it once they are joined.
if (
Expand All @@ -459,6 +465,9 @@ def _update_membership(
"You cannot reject this invite",
errcode=Codes.CANNOT_LEAVE_SERVER_NOTICE_ROOM,
)
else:
if action == "kick":
raise AuthError(403, "The target user is not in the room")

is_host_in_room = yield self._is_host_in_room(current_state_ids)

Expand Down

0 comments on commit db265f0

Please sign in to comment.