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

Give a meaningful error message when a client tries to create a room with an invalid alias localpart. #12779

Merged
merged 3 commits into from
May 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/12779.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Give a meaningful error message when a client tries to create a room with an invalid alias localpart.
3 changes: 3 additions & 0 deletions synapse/handlers/directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ async def _create_association(
if wchar in room_alias.localpart:
raise SynapseError(400, "Invalid characters in room alias")

if ":" in room_alias.localpart:
raise SynapseError(400, "Invalid character in room alias localpart: ':'.")

if not self.hs.is_mine(room_alias):
raise SynapseError(400, "Room alias must be local")
# TODO(erikj): Change this.
Expand Down
15 changes: 15 additions & 0 deletions synapse/handlers/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,21 @@ async def create_room(
if wchar in config["room_alias_name"]:
raise SynapseError(400, "Invalid characters in room alias")

if ":" in config["room_alias_name"]:
# Prevent someone from trying to pass in a full alias here.
# Note that it's permissible for a room alias to have multiple
# hash symbols at the start (notably bridged over from IRC, too),
# but the first colon in the alias is defined to separate the local
# part from the server name.
# (remember server names can contain port numbers, also separated
# by a colon. But under no circumstances should the local part be
# allowed to contain a colon!)
raise SynapseError(
400,
"':' is not permitted in the room alias name. "
"Please note this expects a local part — 'wombat', not '#wombat:example.com'.",
)

room_alias = RoomAlias(config["room_alias_name"], self.hs.hostname)
mapping = await self.store.get_association_from_room_alias(room_alias)

Expand Down