Skip to content

Commit d7198df

Browse files
authored
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.
1 parent 94ef2f4 commit d7198df

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

changelog.d/17240.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Ignore attempts to send to-device messages to bad users, to avoid log spam when we try to connect to the bad server.

synapse/handlers/devicemessage.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,13 @@ async def send_device_message(
236236
local_messages = {}
237237
remote_messages: Dict[str, Dict[str, Dict[str, JsonDict]]] = {}
238238
for user_id, by_device in messages.items():
239+
if not UserID.is_valid(user_id):
240+
logger.warning(
241+
"Ignoring attempt to send device message to invalid user: %r",
242+
user_id,
243+
)
244+
continue
245+
239246
# add an opentracing log entry for each message
240247
for device_id, message_content in by_device.items():
241248
log_kv(

0 commit comments

Comments
 (0)