Do not include signatures/hashes in make_{join,leave,knock} responses. (#10404)
These signatures would end up invalid since the joining/leaving/knocking server would modify the response before calling send_{join,leave,knock}.
This commit is contained in:
parent
bdfde6dca1
commit
d427f64724
|
@ -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}`.
|
|
@ -291,6 +291,20 @@ class EventBase(metaclass=abc.ABCMeta):
|
||||||
|
|
||||||
return pdu_json
|
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):
|
def __set__(self, instance, value):
|
||||||
raise AttributeError("Unrecognized attribute %s" % (instance,))
|
raise AttributeError("Unrecognized attribute %s" % (instance,))
|
||||||
|
|
||||||
|
|
|
@ -562,8 +562,7 @@ class FederationServer(FederationBase):
|
||||||
raise IncompatibleRoomVersionError(room_version=room_version)
|
raise IncompatibleRoomVersionError(room_version=room_version)
|
||||||
|
|
||||||
pdu = await self.handler.on_make_join_request(origin, room_id, user_id)
|
pdu = await self.handler.on_make_join_request(origin, room_id, user_id)
|
||||||
time_now = self._clock.time_msec()
|
return {"event": pdu.get_templated_pdu_json(), "room_version": room_version}
|
||||||
return {"event": pdu.get_pdu_json(time_now), "room_version": room_version}
|
|
||||||
|
|
||||||
async def on_invite_request(
|
async def on_invite_request(
|
||||||
self, origin: str, content: JsonDict, room_version_id: str
|
self, origin: str, content: JsonDict, room_version_id: str
|
||||||
|
@ -611,8 +610,7 @@ class FederationServer(FederationBase):
|
||||||
|
|
||||||
room_version = await self.store.get_room_version_id(room_id)
|
room_version = await self.store.get_room_version_id(room_id)
|
||||||
|
|
||||||
time_now = self._clock.time_msec()
|
return {"event": pdu.get_templated_pdu_json(), "room_version": room_version}
|
||||||
return {"event": pdu.get_pdu_json(time_now), "room_version": room_version}
|
|
||||||
|
|
||||||
async def on_send_leave_request(
|
async def on_send_leave_request(
|
||||||
self, origin: str, content: JsonDict, room_id: str
|
self, origin: str, content: JsonDict, room_id: str
|
||||||
|
@ -659,9 +657,8 @@ class FederationServer(FederationBase):
|
||||||
)
|
)
|
||||||
|
|
||||||
pdu = await self.handler.on_make_knock_request(origin, room_id, user_id)
|
pdu = await self.handler.on_make_knock_request(origin, room_id, user_id)
|
||||||
time_now = self._clock.time_msec()
|
|
||||||
return {
|
return {
|
||||||
"event": pdu.get_pdu_json(time_now),
|
"event": pdu.get_templated_pdu_json(),
|
||||||
"room_version": room_version.identifier,
|
"room_version": room_version.identifier,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue