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

Commit

Permalink
Check that the canonical room alias actually points to the room
Browse files Browse the repository at this point in the history
  • Loading branch information
erikjohnston committed Aug 20, 2015
1 parent d7272f8 commit aadb223
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion synapse/handlers/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from synapse.api.errors import LimitExceededError, SynapseError
from synapse.crypto.event_signing import add_hashes_and_signatures
from synapse.api.constants import Membership, EventTypes
from synapse.types import UserID
from synapse.types import UserID, RoomAlias

from synapse.util.logcontext import PreserveLoggingContext

Expand Down Expand Up @@ -130,6 +130,22 @@ def handle_new_client_event(self, event, context, extra_destinations=[],
returned_invite.signatures
)

if event.type == EventTypes.CanonicalAlias:
# Check the alias is acually valid (at this time at least)
room_alias_str = event.content.get("alias", None)
if room_alias_str:
room_alias = RoomAlias.from_string(room_alias_str)
directory_handler = self.hs.get_handlers().directory_handler
mapping = yield directory_handler.get_association(room_alias)

if mapping["room_id"] != event.room_id:
raise SynapseError(
400,
"Room alias %s does not point to the room" % (
room_alias_str,
)
)

destinations = set(extra_destinations)
for k, s in context.current_state.items():
try:
Expand Down

0 comments on commit aadb223

Please sign in to comment.