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

Commit

Permalink
Enforce the max length for per-room display names / avatar URLs. (#10654
Browse files Browse the repository at this point in the history
)

To match the maximum lengths allowed for profile data.
  • Loading branch information
Azrenbeth authored Aug 23, 2021
1 parent 3e83f97 commit 0c1d6f6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog.d/10654.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Enforce the maximum length for per-room display names and avatar URLs.
17 changes: 16 additions & 1 deletion synapse/handlers/room_member.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from synapse.event_auth import get_named_level, get_power_level_event
from synapse.events import EventBase
from synapse.events.snapshot import EventContext
from synapse.handlers.profile import MAX_AVATAR_URL_LEN, MAX_DISPLAYNAME_LEN
from synapse.types import (
JsonDict,
Requester,
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")

self.clock = hs.get_clock()
self.spam_checker = hs.get_spam_checker()
Expand Down Expand Up @@ -556,6 +557,20 @@ async def update_membership_locked(
content.pop("displayname", None)
content.pop("avatar_url", None)

if len(content.get("displayname") or "") > MAX_DISPLAYNAME_LEN:
raise SynapseError(
400,
f"Displayname is too long (max {MAX_DISPLAYNAME_LEN})",
errcode=Codes.BAD_JSON,
)

if len(content.get("avatar_url") or "") > MAX_AVATAR_URL_LEN:
raise SynapseError(
400,
f"Avatar URL is too long (max {MAX_AVATAR_URL_LEN})",
errcode=Codes.BAD_JSON,
)

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

0 comments on commit 0c1d6f6

Please sign in to comment.