From e65da2d18c4e05a81cc079fa4f389c6abebc863f Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Thu, 9 Mar 2023 15:40:59 +0000 Subject: [PATCH] Fix error when sending message into deleted room. When a room is deleted in Synapse we remove the event forward extremities in the room, so if (say a bot) tries to send a message into the room we error out due to not being able to calculate prev events for the new event *before* we check if the sender is in the room. Fixes #8094 --- synapse/handlers/message.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/synapse/handlers/message.py b/synapse/handlers/message.py index da129ec16a4a..435e08ebeedc 100644 --- a/synapse/handlers/message.py +++ b/synapse/handlers/message.py @@ -1169,6 +1169,17 @@ async def create_new_client_event( len(prev_event_ids), ) else: + # If we don't have any prev event IDs specified then we need to + # check that the host is in the room (as otherwise populating the + # prev events will fail), at which point we may as well check the + # local user is in the room. + user_id = requester.user.to_string() + is_user_in_room = await self.store.check_local_user_in_room( + requester.user.to_string(), builder.room_id + ) + if not is_user_in_room: + raise AuthError(403, f"User {user_id} not in room {builder.room_id}") + prev_event_ids = await self.store.get_prev_events_for_room(builder.room_id) # Do a quick sanity check here, rather than waiting until we've created the