From f26862fa691b470eaf19fe0b57bd561795d891f6 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Wed, 29 May 2024 11:52:48 +0100 Subject: [PATCH] Ignore attempts to send to-device messages to bad users (#17240) Currently sending a to-device message to a user ID with a dodgy destination is accepted, but then ends up spamming the logs when we try and send to the destination. An alternative would be to reject the request, but I'm slightly nervous that could break things. --- changelog.d/17240.bugfix | 1 + synapse/handlers/devicemessage.py | 7 +++++++ 2 files changed, 8 insertions(+) create mode 100644 changelog.d/17240.bugfix diff --git a/changelog.d/17240.bugfix b/changelog.d/17240.bugfix new file mode 100644 index 00000000000..c596d270cea --- /dev/null +++ b/changelog.d/17240.bugfix @@ -0,0 +1 @@ +Ignore attempts to send to-device messages to bad users, to avoid log spam when we try to connect to the bad server. diff --git a/synapse/handlers/devicemessage.py b/synapse/handlers/devicemessage.py index 79be7c97c8e..e56bdb40720 100644 --- a/synapse/handlers/devicemessage.py +++ b/synapse/handlers/devicemessage.py @@ -236,6 +236,13 @@ async def send_device_message( local_messages = {} remote_messages: Dict[str, Dict[str, Dict[str, JsonDict]]] = {} for user_id, by_device in messages.items(): + if not UserID.is_valid(user_id): + logger.warning( + "Ignoring attempt to send device message to invalid user: %r", + user_id, + ) + continue + # add an opentracing log entry for each message for device_id, message_content in by_device.items(): log_kv(