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

Commit df49635

Browse files
authored
Give a meaningful error message when a client tries to create a room with an invalid alias localpart. (#12779)
1 parent a167304 commit df49635

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

changelog.d/12779.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Give a meaningful error message when a client tries to create a room with an invalid alias localpart.

synapse/handlers/directory.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ async def _create_association(
7171
if wchar in room_alias.localpart:
7272
raise SynapseError(400, "Invalid characters in room alias")
7373

74+
if ":" in room_alias.localpart:
75+
raise SynapseError(400, "Invalid character in room alias localpart: ':'.")
76+
7477
if not self.hs.is_mine(room_alias):
7578
raise SynapseError(400, "Room alias must be local")
7679
# TODO(erikj): Change this.

synapse/handlers/room.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,21 @@ async def create_room(
751751
if wchar in config["room_alias_name"]:
752752
raise SynapseError(400, "Invalid characters in room alias")
753753

754+
if ":" in config["room_alias_name"]:
755+
# Prevent someone from trying to pass in a full alias here.
756+
# Note that it's permissible for a room alias to have multiple
757+
# hash symbols at the start (notably bridged over from IRC, too),
758+
# but the first colon in the alias is defined to separate the local
759+
# part from the server name.
760+
# (remember server names can contain port numbers, also separated
761+
# by a colon. But under no circumstances should the local part be
762+
# allowed to contain a colon!)
763+
raise SynapseError(
764+
400,
765+
"':' is not permitted in the room alias name. "
766+
"Please note this expects a local part — 'wombat', not '#wombat:example.com'.",
767+
)
768+
754769
room_alias = RoomAlias(config["room_alias_name"], self.hs.hostname)
755770
mapping = await self.store.get_association_from_room_alias(room_alias)
756771

0 commit comments

Comments
 (0)