diff options
author | Andrew Morgan <1342360+anoadragon453@users.noreply.github.com> | 2019-12-11 13:07:25 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-12-11 13:07:25 +0000 |
commit | ea0f0ad4144e3ce0cf10f3ec461ecd8f654955a2 (patch) | |
tree | 42887f20e171923facb8ddf3098f1a7f310ec52a /synapse/storage | |
parent | Merge pull request #6349 from matrix-org/babolivier/msc1802 (diff) | |
download | synapse-ea0f0ad4144e3ce0cf10f3ec461ecd8f654955a2.tar.xz |
Prevent message search in upgraded rooms we're not in (#6385)
Diffstat (limited to 'synapse/storage')
-rw-r--r-- | synapse/storage/data_stores/main/state.py | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/synapse/storage/data_stores/main/state.py b/synapse/storage/data_stores/main/state.py index 9ef7b48c74..dcc6b43cdf 100644 --- a/synapse/storage/data_stores/main/state.py +++ b/synapse/storage/data_stores/main/state.py @@ -278,7 +278,7 @@ class StateGroupWorkerStore( @defer.inlineCallbacks def get_room_predecessor(self, room_id): - """Get the predecessor room of an upgraded room if one exists. + """Get the predecessor of an upgraded room if it exists. Otherwise return None. Args: @@ -291,14 +291,22 @@ class StateGroupWorkerStore( * room_id (str): The room ID of the predecessor room * event_id (str): The ID of the tombstone event in the predecessor room + None if a predecessor key is not found, or is not a dictionary. + Raises: - NotFoundError if the room is unknown + NotFoundError if the given room is unknown """ # Retrieve the room's create event create_event = yield self.get_create_event_for_room(room_id) - # Return predecessor if present - return create_event.content.get("predecessor", None) + # Retrieve the predecessor key of the create event + predecessor = create_event.content.get("predecessor", None) + + # Ensure the key is a dictionary + if not isinstance(predecessor, dict): + return None + + return predecessor @defer.inlineCallbacks def get_create_event_for_room(self, room_id): @@ -318,7 +326,7 @@ class StateGroupWorkerStore( # If we can't find the create event, assume we've hit a dead end if not create_id: - raise NotFoundError("Unknown room %s" % (room_id)) + raise NotFoundError("Unknown room %s" % (room_id,)) # Retrieve the room's create event and return create_event = yield self.get_event(create_id) |