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

Don't set new room alias before potential 403 #10930

Merged
merged 12 commits into from
Oct 25, 2021
1 change: 1 addition & 0 deletions changelog.d/10929.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Newly-created public rooms are now only assigned an alias if the room's creation has not been blocked by permission settings. Contributed by @AndrewFerr.
18 changes: 9 additions & 9 deletions synapse/handlers/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,15 @@ async def create_room(
if not allowed_by_third_party_rules:
raise SynapseError(403, "Room visibility value not allowed.")

if is_public:
if not self.config.roomdirectory.is_publishing_room_allowed(
user_id, room_id, room_alias
):
# Lets just return a generic message, as there may be all sorts of
AndrewFerr marked this conversation as resolved.
Show resolved Hide resolved
# reasons why we said no. TODO: Allow configurable error messages
# per alias creation rule?
raise SynapseError(403, "Not allowed to publish room")

directory_handler = self.hs.get_directory_handler()
if room_alias:
await directory_handler.create_association(
Expand All @@ -762,15 +771,6 @@ async def create_room(
check_membership=False,
)

if is_public:
if not self.config.roomdirectory.is_publishing_room_allowed(
user_id, room_id, room_alias
):
# Lets just return a generic message, as there may be all sorts of
# reasons why we said no. TODO: Allow configurable error messages
# per alias creation rule?
raise SynapseError(403, "Not allowed to publish room")

preset_config = config.get(
"preset",
RoomCreationPreset.PRIVATE_CHAT
Expand Down