Skip to content
Snippets Groups Projects
Unverified Commit db265f06 authored by Andrew Morgan's avatar Andrew Morgan Committed by GitHub
Browse files

Prevent kicking users who aren't in the room (#4999)

Prevent kick events from succeeding if the user is not currently in the room.
parent 9f5d206c
No related branches found
No related tags found
No related merge requests found
Prevent the ability to kick users from a room they aren't in.
...@@ -421,6 +421,9 @@ class RoomMemberHandler(object): ...@@ -421,6 +421,9 @@ class RoomMemberHandler(object):
room_id, latest_event_ids=latest_event_ids, 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())) old_state_id = current_state_ids.get((EventTypes.Member, target.to_string()))
if old_state_id: if old_state_id:
old_state = yield self.store.get_event(old_state_id, allow_none=True) old_state = yield self.store.get_event(old_state_id, allow_none=True)
...@@ -446,6 +449,9 @@ class RoomMemberHandler(object): ...@@ -446,6 +449,9 @@ class RoomMemberHandler(object):
if same_sender and same_membership and same_content: if same_sender and same_membership and same_content:
defer.returnValue(old_state) 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 # we don't allow people to reject invites to the server notice
# room, but they can leave it once they are joined. # room, but they can leave it once they are joined.
if ( if (
...@@ -459,6 +465,9 @@ class RoomMemberHandler(object): ...@@ -459,6 +465,9 @@ class RoomMemberHandler(object):
"You cannot reject this invite", "You cannot reject this invite",
errcode=Codes.CANNOT_LEAVE_SERVER_NOTICE_ROOM, 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) is_host_in_room = yield self._is_host_in_room(current_state_ids)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment