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

Commit

Permalink
Do not return allowed_room_ids from /hierarchy response.
Browse files Browse the repository at this point in the history
  • Loading branch information
clokep committed Mar 7, 2022
1 parent 26211fe commit c2aca33
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog.d/12175.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a bug where non-standard information was returned from the `/hierarchy` API. Introduced in Synapse v1.41.0.
15 changes: 13 additions & 2 deletions synapse/handlers/room_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ async def _get_room_hierarchy(
# inaccessible to the requesting user.
if room_entry:
# Add the room (including the stripped m.space.child events).
rooms_result.append(room_entry.as_json())
rooms_result.append(room_entry.as_json(for_client=True))

# If this room is not at the max-depth, check if there are any
# children to process.
Expand Down Expand Up @@ -843,14 +843,25 @@ class _RoomEntry:
# This may not include all children.
children_state_events: Sequence[JsonDict] = ()

def as_json(self) -> JsonDict:
def as_json(self, for_client: bool = False) -> JsonDict:
"""
Returns a JSON dictionary suitable for the room hierarchy endpoint.
It returns the room summary including the stripped m.space.child events
as a sub-key.
Args:
for_client: If true, any server-server only fields are stripped from
the result.
"""
result = dict(self.room)

# Before returning to the client, remove the allowed_room_ids key, if it
# exists.
if for_client:
result.pop("allowed_room_ids", False)

result["children_state"] = self.children_state_events
return result

Expand Down
3 changes: 3 additions & 0 deletions tests/handlers/test_room_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ def _assert_hierarchy(
result_room_ids = []
result_children_ids = []
for result_room in result["rooms"]:
# Ensure federation results are not leaking over the client-server API.
self.assertNotIn("allowed_room_ids", result_room)

result_room_ids.append(result_room["room_id"])
result_children_ids.append(
[
Expand Down

0 comments on commit c2aca33

Please sign in to comment.