diff options
author | Andrew Morgan <andrew@amorgan.xyz> | 2020-03-23 17:12:09 +0000 |
---|---|---|
committer | Andrew Morgan <andrew@amorgan.xyz> | 2020-03-23 17:12:09 +0000 |
commit | 1dbb4305e30024618e4d2ac374dda09885c3d95e (patch) | |
tree | 9fbb60ee5f1892d5e153dd7206f7707bba9e04e9 /synapse/handlers | |
parent | filter out m.room.aliases from /sync state blocks (#6884) (diff) | |
parent | Reject device display names that are too long (#6882) (diff) | |
download | synapse-1dbb4305e30024618e4d2ac374dda09885c3d95e.tar.xz |
Reject device display names that are too long (#6882)
* commit 'a92e703ab': Reject device display names that are too long (#6882)
Diffstat (limited to 'synapse/handlers')
-rw-r--r-- | synapse/handlers/device.py | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/synapse/handlers/device.py b/synapse/handlers/device.py index 6d8e48ed39..50cea3f378 100644 --- a/synapse/handlers/device.py +++ b/synapse/handlers/device.py @@ -26,6 +26,7 @@ from synapse.api.errors import ( FederationDeniedError, HttpResponseException, RequestSendFailed, + SynapseError, ) from synapse.logging.opentracing import log_kv, set_tag, trace from synapse.types import RoomStreamToken, get_domain_from_id @@ -39,6 +40,8 @@ from ._base import BaseHandler logger = logging.getLogger(__name__) +MAX_DEVICE_DISPLAY_NAME_LEN = 100 + class DeviceWorkerHandler(BaseHandler): def __init__(self, hs): @@ -404,9 +407,18 @@ class DeviceHandler(DeviceWorkerHandler): defer.Deferred: """ + # Reject a new displayname which is too long. + new_display_name = content.get("display_name") + if new_display_name and len(new_display_name) > MAX_DEVICE_DISPLAY_NAME_LEN: + raise SynapseError( + 400, + "Device display name is too long (max %i)" + % (MAX_DEVICE_DISPLAY_NAME_LEN,), + ) + try: yield self.store.update_device( - user_id, device_id, new_display_name=content.get("display_name") + user_id, device_id, new_display_name=new_display_name ) yield self.notify_device_update(user_id, [device_id]) except errors.StoreError as e: |