diff options
author | Mathieu Velten <mathieuv@matrix.org> | 2023-08-04 15:30:18 +0200 |
---|---|---|
committer | Mathieu Velten <mathieuv@matrix.org> | 2023-08-04 15:30:18 +0200 |
commit | 7ad75e6d2010868370c25672fe757e2a16c3e751 (patch) | |
tree | d67108d80b9d5b1818532d903145c9e8acc80d6a | |
parent | fix comments (diff) | |
download | synapse-7ad75e6d2010868370c25672fe757e2a16c3e751.tar.xz |
Add check to EDUs and move PDUs check in the event storage controller
-rw-r--r-- | synapse/handlers/device.py | 4 | ||||
-rw-r--r-- | synapse/handlers/devicemessage.py | 4 | ||||
-rw-r--r-- | synapse/handlers/e2e_keys.py | 4 | ||||
-rw-r--r-- | synapse/handlers/receipts.py | 4 | ||||
-rw-r--r-- | synapse/handlers/typing.py | 4 | ||||
-rw-r--r-- | synapse/storage/controllers/persist_events.py | 5 | ||||
-rw-r--r-- | synapse/storage/databases/main/events.py | 4 |
7 files changed, 25 insertions, 4 deletions
diff --git a/synapse/handlers/device.py b/synapse/handlers/device.py index f3a713f5fa..4989bdb65a 100644 --- a/synapse/handlers/device.py +++ b/synapse/handlers/device.py @@ -1033,6 +1033,10 @@ class DeviceListUpdater(DeviceListWorkerUpdater): ) prev_ids = [str(p) for p in prev_ids] # They may come as ints + # The result of `validate` is not used yet because for now we only want to + # log invalid mxids in the wild. + UserID.from_string(user_id).validate(allow_historical_mxids=True) + if get_domain_from_id(user_id) != origin: # TODO: Raise? logger.warning( diff --git a/synapse/handlers/devicemessage.py b/synapse/handlers/devicemessage.py index 15e94a03cb..5cbcc73102 100644 --- a/synapse/handlers/devicemessage.py +++ b/synapse/handlers/devicemessage.py @@ -110,6 +110,10 @@ class DeviceMessageHandler: origin, sender_user_id, ) + # The result of `validate` is not used yet because for now we only want to + # log invalid mxids in the wild. + UserID.from_string(sender_user_id).validate(allow_historical_mxids=True) + message_type = content["type"] message_id = content["message_id"] for user_id, by_device in content["messages"].items(): diff --git a/synapse/handlers/e2e_keys.py b/synapse/handlers/e2e_keys.py index ad075497c8..4924404526 100644 --- a/synapse/handlers/e2e_keys.py +++ b/synapse/handlers/e2e_keys.py @@ -1593,6 +1593,10 @@ class SigningKeyEduUpdater: logger.warning("Got signing key update edu for %r from %r", user_id, origin) return + # The result of `validate` is not used yet because for now we only want to + # log invalid mxids in the wild. + UserID.from_string(user_id).validate(allow_historical_mxids=True) + room_ids = await self.store.get_rooms_for_user(user_id) if not room_ids: # We don't share any rooms with this user. Ignore update, as we diff --git a/synapse/handlers/receipts.py b/synapse/handlers/receipts.py index 2bacdebfb5..09a0ed276d 100644 --- a/synapse/handlers/receipts.py +++ b/synapse/handlers/receipts.py @@ -117,6 +117,10 @@ class ReceiptsHandler: max_batch_id: Optional[int] = None for receipt in receipts: + # The result of `validate` is not used yet because for now we only want to + # log invalid mxids in the wild. + UserID.from_string(receipt.user_id).validate(allow_historical_mxids=True) + res = await self.store.insert_receipt( receipt.room_id, receipt.receipt_type, diff --git a/synapse/handlers/typing.py b/synapse/handlers/typing.py index 7aeae5319c..d0f01bb89f 100644 --- a/synapse/handlers/typing.py +++ b/synapse/handlers/typing.py @@ -362,6 +362,10 @@ class TypingWriterHandler(FollowerTypingHandler): room_id = content["room_id"] user_id = content["user_id"] + # The result of `validate` is not used yet because for now we only want to + # log invalid mxids in the wild. + UserID.from_string(user_id).validate(allow_historical_mxids=True) + # If we're not in the room just ditch the event entirely. This is # probably an old server that has come back and thinks we're still in # the room (or we've been rejoined to the room by a state reset). diff --git a/synapse/storage/controllers/persist_events.py b/synapse/storage/controllers/persist_events.py index 35cd1089d6..61ab493e38 100644 --- a/synapse/storage/controllers/persist_events.py +++ b/synapse/storage/controllers/persist_events.py @@ -63,6 +63,7 @@ from synapse.types import ( PersistedEventPosition, RoomStreamToken, StateMap, + UserID, get_domain_from_id, ) from synapse.types.state import StateFilter @@ -397,6 +398,10 @@ class EventsPersistenceStorageController: event_ids: List[str] = [] partitioned: Dict[str, List[Tuple[EventBase, EventContext]]] = {} for event, ctx in events_and_contexts: + # The result of `validate` is not used yet because for now we only want to + # log invalid mxids in the wild. + UserID.from_string(event.user_id).validate(allow_historical_mxids=True) + partitioned.setdefault(event.room_id, []).append((event, ctx)) event_ids.append(event.event_id) diff --git a/synapse/storage/databases/main/events.py b/synapse/storage/databases/main/events.py index da8cbc9642..b291a924cd 100644 --- a/synapse/storage/databases/main/events.py +++ b/synapse/storage/databases/main/events.py @@ -393,10 +393,6 @@ class PersistEventsStore: # Once the txn completes, invalidate all of the relevant caches. Note that we do this # up here because it captures all the events_and_contexts before any are removed. for event, _ in events_and_contexts: - sender = UserID.from_string(event.sender) - # The result of `validate` is not used yet because for now we only want to - # log invalid mxids in the wild. - sender.validate(allow_historical_mxids=True) self.store.invalidate_get_event_cache_after_txn(txn, event.event_id) if event.redacts: self.store.invalidate_get_event_cache_after_txn(txn, event.redacts) |