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.
This commit is contained in:
Erik Johnston 2024-05-29 11:52:48 +01:00 committed by GitHub
parent 94ef2f4f5d
commit d7198dfb95
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 0 deletions

1
changelog.d/17240.bugfix Normal file
View File

@ -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.

View File

@ -236,6 +236,13 @@ class DeviceMessageHandler:
local_messages = {} local_messages = {}
remote_messages: Dict[str, Dict[str, Dict[str, JsonDict]]] = {} remote_messages: Dict[str, Dict[str, Dict[str, JsonDict]]] = {}
for user_id, by_device in messages.items(): 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 # add an opentracing log entry for each message
for device_id, message_content in by_device.items(): for device_id, message_content in by_device.items():
log_kv( log_kv(