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

Commit

Permalink
Limit displaynames and avatar URLs
Browse files Browse the repository at this point in the history
These end up in join events everywhere, so let's limit them.

Fixes #5079
  • Loading branch information
richvdh committed Jun 1, 2019
1 parent e26e6b3 commit d16c637
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog.d/5309.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Prevent users from setting huge displaynames and avatar URLs.
13 changes: 13 additions & 0 deletions synapse/handlers/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@

logger = logging.getLogger(__name__)

MAX_DISPLAYNAME_LEN = 100
MAX_AVATAR_URL_LEN = 1000


class BaseProfileHandler(BaseHandler):
"""Handles fetching and updating user profile information.
Expand Down Expand Up @@ -162,6 +165,11 @@ def set_displayname(self, target_user, requester, new_displayname, by_admin=Fals
if not by_admin and target_user != requester.user:
raise AuthError(400, "Cannot set another user's displayname")

if len(new_displayname) > MAX_DISPLAYNAME_LEN:
raise SynapseError(
400, "Displayname is too long (max %i)" % (MAX_DISPLAYNAME_LEN, ),
)

if new_displayname == '':
new_displayname = None

Expand Down Expand Up @@ -217,6 +225,11 @@ def set_avatar_url(self, target_user, requester, new_avatar_url, by_admin=False)
if not by_admin and target_user != requester.user:
raise AuthError(400, "Cannot set another user's avatar_url")

if len(new_avatar_url) > MAX_AVATAR_URL_LEN:
raise SynapseError(
400, "Avatar URL is too long (max %i)" % (MAX_AVATAR_URL_LEN, ),
)

yield self.store.set_profile_avatar_url(
target_user.localpart, new_avatar_url
)
Expand Down
2 changes: 2 additions & 0 deletions synapse/handlers/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,8 @@ def get_or_create_user(self, requester, localpart, displayname,
A tuple of (user_id, access_token).
Raises:
RegistrationError if there was a problem registering.
NB this is only used in tests. TODO: move it to the test package!
"""
if localpart is None:
raise SynapseError(400, "Request must include user id")
Expand Down

0 comments on commit d16c637

Please sign in to comment.