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

Commit affbb58

Browse files
committed
Treat an unknown alias as a BAD_ALIAS for the canonical alias event.
1 parent c2db659 commit affbb58

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

changelog.d/7109.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Return the proper error (M_BAD_ALIAS) when a non-existant canonical alias is provided.

synapse/handlers/message.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,18 @@ def persist_and_notify_client_event(
906906
directory_handler = self.hs.get_handlers().directory_handler
907907
if room_alias_str and room_alias_str != original_alias:
908908
room_alias = RoomAlias.from_string(room_alias_str)
909-
mapping = yield directory_handler.get_association(room_alias)
909+
try:
910+
mapping = yield directory_handler.get_association(room_alias)
911+
except SynapseError as e:
912+
# Turn M_NOT_FOUND errors into M_BAD_ALIAS errors.
913+
if e.errcode == Codes.NOT_FOUND:
914+
raise SynapseError(
915+
400,
916+
"Room alias %s does not point to the room"
917+
% (room_alias_str,),
918+
Codes.BAD_ALIAS,
919+
)
920+
raise
910921

911922
if mapping["room_id"] != event.room_id:
912923
raise SynapseError(
@@ -932,7 +943,18 @@ def persist_and_notify_client_event(
932943
if new_alt_aliases:
933944
for alias_str in new_alt_aliases:
934945
room_alias = RoomAlias.from_string(alias_str)
935-
mapping = yield directory_handler.get_association(room_alias)
946+
try:
947+
mapping = yield directory_handler.get_association(room_alias)
948+
except SynapseError as e:
949+
# Turn M_NOT_FOUND errors into M_BAD_ALIAS errors.
950+
if e.errcode == Codes.NOT_FOUND:
951+
raise SynapseError(
952+
400,
953+
"Room alias %s does not point to the room"
954+
% (room_alias_str,),
955+
Codes.BAD_ALIAS,
956+
)
957+
raise
936958

937959
if mapping["room_id"] != event.room_id:
938960
raise SynapseError(

0 commit comments

Comments
 (0)