From 8274732a2c9be5d9749df84dd38c5b45c6d35ad5 Mon Sep 17 00:00:00 2001 From: David Blackman Date: Mon, 6 Jan 2025 11:24:19 +0100 Subject: [PATCH 1/3] Fix overly restrictive typeguards in get_rooms_that_allow_join This was causing a bug that was only occuring when the server had modules loaded and there were unjoined space-visible rooms in a hierarchy. This fix is a result of the following investigation: Symptom: new 'space-visible' rooms are not showing up in /hierarchy Reason: because get_rooms_that_allow_join is checking that the allow key is a list, and it's coming back as a tuple https://github.com/element-hq/synapse/blob/develop/synapse/handlers/event_auth.py#L329 -> Reason: when the room is created, the join_rules event calls check_event_allowed - https://github.com/element-hq/synapse/blob/develop/synapse/handlers/message.py#L1289 - which calls event.freeze() which seems to be changing lists to tuples - https://github.com/element-hq/synapse/blob/develop/synapse/module_api/callbacks/third_party_event_rules_callbacks.py#L294 --> so that when the event is being pulled from cache, the allow list is a tuple. But when I restart the server, it gets pulled from the DB and deserialized as a list. --- synapse/handlers/event_auth.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/synapse/handlers/event_auth.py b/synapse/handlers/event_auth.py index c4dbf22408b..a91fe1323d7 100644 --- a/synapse/handlers/event_auth.py +++ b/synapse/handlers/event_auth.py @@ -21,6 +21,8 @@ import logging from typing import TYPE_CHECKING, List, Mapping, Optional, Union +from immutabledict import immutabledict + from synapse import event_auth from synapse.api.constants import ( EventTypes, @@ -326,13 +328,13 @@ async def get_rooms_that_allow_join( # If allowed is of the wrong form, then only allow invited users. allow_list = join_rules_event.content.get("allow", []) - if not isinstance(allow_list, list): + if not isinstance(allow_list, (list, tuple)): return () # Pull out the other room IDs, invalid data gets filtered. result = [] for allow in allow_list: - if not isinstance(allow, dict): + if not isinstance(allow, (immutabledict, dict)): continue # If the type is unexpected, skip it. From 94be0053ac24d7fd6aaad29d59515d23dfbceec5 Mon Sep 17 00:00:00 2001 From: David Blackman Date: Mon, 6 Jan 2025 11:45:44 +0100 Subject: [PATCH 2/3] add changelog --- changelog.d/18066.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/18066.bugfix diff --git a/changelog.d/18066.bugfix b/changelog.d/18066.bugfix new file mode 100644 index 00000000000..c979822bf0b --- /dev/null +++ b/changelog.d/18066.bugfix @@ -0,0 +1 @@ +Fixed a bug that caused new space-visible rooms to be hidden from the space hierarchy when any server modules are loaded. \ No newline at end of file From c3e650078678154092aa6034352f4da0fbd3ee57 Mon Sep 17 00:00:00 2001 From: David Blackman Date: Mon, 6 Jan 2025 12:26:26 +0100 Subject: [PATCH 3/3] add a fix for via as well, which has the same bug --- synapse/handlers/room_summary.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/synapse/handlers/room_summary.py b/synapse/handlers/room_summary.py index 64f5bea014f..b2338727035 100644 --- a/synapse/handlers/room_summary.py +++ b/synapse/handlers/room_summary.py @@ -955,7 +955,7 @@ def as_json(self, for_client: bool = False) -> JsonDict: def _has_valid_via(e: EventBase) -> bool: via = e.content.get("via") - if not via or not isinstance(via, list): + if not via or not isinstance(via, (list, tuple)): return False for v in via: if not isinstance(v, str):