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

Do not include signatures/hashes in make_{join,leave,knock} responses. #10404

Merged
merged 1 commit into from
Jul 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/10404.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Responses from `/make_{join,leave,knock}` no longer include signatures, which will turn out to be invalid after events are returned to `/send_{join,leave,knock}`.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unsure if there's a clearer changelog to give people here?

14 changes: 14 additions & 0 deletions synapse/events/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,20 @@ def get_pdu_json(self, time_now=None) -> JsonDict:

return pdu_json

def get_templated_pdu_json(self) -> JsonDict:
"""
Return a JSON object suitable for a templated event, as used in the
make_{join,leave,knock} workflow.
"""
# By using _dict directly we don't pull in signatures/unsigned.
template_json = dict(self._dict)
# The hashes (similar to the signature) need to be recalculated by the
# joining/leaving/knocking server after (potentially) modifying the
# event.
template_json.pop("hashes")

return template_json

def __set__(self, instance, value):
raise AttributeError("Unrecognized attribute %s" % (instance,))

Expand Down
9 changes: 3 additions & 6 deletions synapse/federation/federation_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,8 +562,7 @@ async def on_make_join_request(
raise IncompatibleRoomVersionError(room_version=room_version)

pdu = await self.handler.on_make_join_request(origin, room_id, user_id)
time_now = self._clock.time_msec()
return {"event": pdu.get_pdu_json(time_now), "room_version": room_version}
return {"event": pdu.get_templated_pdu_json(), "room_version": room_version}

async def on_invite_request(
self, origin: str, content: JsonDict, room_version_id: str
Expand Down Expand Up @@ -611,8 +610,7 @@ async def on_make_leave_request(

room_version = await self.store.get_room_version_id(room_id)

time_now = self._clock.time_msec()
return {"event": pdu.get_pdu_json(time_now), "room_version": room_version}
return {"event": pdu.get_templated_pdu_json(), "room_version": room_version}

async def on_send_leave_request(
self, origin: str, content: JsonDict, room_id: str
Expand Down Expand Up @@ -659,9 +657,8 @@ async def on_make_knock_request(
)

pdu = await self.handler.on_make_knock_request(origin, room_id, user_id)
time_now = self._clock.time_msec()
return {
"event": pdu.get_pdu_json(time_now),
"event": pdu.get_templated_pdu_json(),
"room_version": room_version.identifier,
}

Expand Down