diff --git a/synapse/handlers/federation.py b/synapse/handlers/federation.py index c14ddac69..79b6ccf66 100644 --- a/synapse/handlers/federation.py +++ b/synapse/handlers/federation.py @@ -683,7 +683,7 @@ class FederationHandler(BaseHandler, FederationBase): async def _validate_forwarded_event(self, event: EventBase) -> Tuple[bool, Optional[str]]: try: 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["content"] = {**event.content} del source_evt_dict["unsigned"] @@ -691,11 +691,18 @@ class FederationHandler(BaseHandler, FederationBase): except (KeyError, TypeError): logger.exception("Failed to read forward data") 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: source_evt = event_from_pdu_json(source_evt_dict, room_version) except SynapseError: logger.exception("Failed to parse forward data") return False, None + try: 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 diff --git a/synapse/rest/client/v2_alpha/forward_event.py b/synapse/rest/client/v2_alpha/forward_event.py index d77c412f1..8fbae6597 100644 --- a/synapse/rest/client/v2_alpha/forward_event.py +++ b/synapse/rest/client/v2_alpha/forward_event.py @@ -85,8 +85,9 @@ class RoomEventForwardServlet(RestServlet): errcode=self._err_not_forwardable) elif not has_forward_meta: content[self._data_key] = event_dict + room_version = await self.store.get_room_version(event.room_id) 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 }