0
0
Fork 1
mirror of https://mau.dev/maunium/synapse.git synced 2024-11-16 06:51:46 +01:00

Fix handling room versions

This commit is contained in:
Tulir Asokan 2020-08-13 13:31:45 +03:00
parent 1357a75592
commit ce02e755c1
2 changed files with 10 additions and 2 deletions

View file

@ -683,7 +683,7 @@ class FederationHandler(BaseHandler, FederationBase):
async def _validate_forwarded_event(self, event: EventBase) -> Tuple[bool, Optional[str]]: async def _validate_forwarded_event(self, event: EventBase) -> Tuple[bool, Optional[str]]:
try: try:
source_evt_dict = {**event.content[self._forwarded_key]} source_evt_dict = {**event.content[self._forwarded_key]}
room_version = source_evt_dict["unsigned"]["room_version"] room_version_identifier = source_evt_dict["unsigned"]["room_version"]
source_evt_dict["type"] = event.type source_evt_dict["type"] = event.type
source_evt_dict["content"] = {**event.content} source_evt_dict["content"] = {**event.content}
del source_evt_dict["unsigned"] del source_evt_dict["unsigned"]
@ -691,11 +691,18 @@ class FederationHandler(BaseHandler, FederationBase):
except (KeyError, TypeError): except (KeyError, TypeError):
logger.exception("Failed to read forward data") logger.exception("Failed to read forward data")
return False, None return False, None
room_version = KNOWN_ROOM_VERSIONS.get(room_version_identifier)
if not room_version:
# We don't support the source room version, so we can't verify the event :(
return False, None
try: try:
source_evt = event_from_pdu_json(source_evt_dict, room_version) source_evt = event_from_pdu_json(source_evt_dict, room_version)
except SynapseError: except SynapseError:
logger.exception("Failed to parse forward data") logger.exception("Failed to parse forward data")
return False, None return False, None
try: try:
checked_evt = await self._check_sigs_and_hash(room_version, source_evt) checked_evt = await self._check_sigs_and_hash(room_version, source_evt)
# _check_sigs_and_hash returns a redacted event if hash validation failed and # _check_sigs_and_hash returns a redacted event if hash validation failed and

View file

@ -85,8 +85,9 @@ class RoomEventForwardServlet(RestServlet):
errcode=self._err_not_forwardable) errcode=self._err_not_forwardable)
elif not has_forward_meta: elif not has_forward_meta:
content[self._data_key] = event_dict content[self._data_key] = event_dict
room_version = await self.store.get_room_version(event.room_id)
content[self._data_key]["unsigned"] = { content[self._data_key]["unsigned"] = {
"room_version": await self.store.get_room_version(event.room_id), "room_version": room_version.identifier,
# TODO add sender profile info here # TODO add sender profile info here
} }