Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Apply limit to per-room display names when setting them #10654

Merged
merged 9 commits into from
Aug 23, 2021
1 change: 1 addition & 0 deletions changelog.d/10654.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Apply display name length limit to per-room display names.
Azrenbeth marked this conversation as resolved.
Show resolved Hide resolved
11 changes: 8 additions & 3 deletions synapse/handlers/room_member.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
from synapse.util.distributor import user_left_room

from ._base import BaseHandler
from .profile import MAX_DISPLAYNAME_LEN
Azrenbeth marked this conversation as resolved.
Show resolved Hide resolved

if TYPE_CHECKING:
from synapse.server import HomeServer
Expand Down Expand Up @@ -79,7 +80,7 @@ def __init__(self, hs: "HomeServer"):
self.account_data_handler = hs.get_account_data_handler()
self.event_auth_handler = hs.get_event_auth_handler()

self.member_linearizer = Linearizer(name="member")
self.member_linearizer: Linearizer = Linearizer(name="member")
Azrenbeth marked this conversation as resolved.
Show resolved Hide resolved

self.clock = hs.get_clock()
self.spam_checker = hs.get_spam_checker()
Expand Down Expand Up @@ -548,13 +549,17 @@ async def update_membership_locked(
)

if (
not self.allow_per_room_profiles and not is_requester_server_notices_user
) or requester.shadow_banned:
(not self.allow_per_room_profiles and not is_requester_server_notices_user)
or requester.shadow_banned
or len(content.get("displayname", "")) > MAX_DISPLAYNAME_LEN
Azrenbeth marked this conversation as resolved.
Show resolved Hide resolved
):
# Strip profile data, knowing that new profile data will be added to the
# event's content in event_creation_handler.create_event() using the target's
# global profile.
content.pop("displayname", None)
content.pop("avatar_url", None)
# content may now be emtpy
content_specified = len(content) == 0
clokep marked this conversation as resolved.
Show resolved Hide resolved

effective_membership_state = action
if action in ["kick", "unban"]:
Expand Down