summary refs log tree commit diff
path: root/synapse/api/auth.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2014-11-12 11:22:51 +0000
committerErik Johnston <erik@matrix.org>2014-11-12 11:24:11 +0000
commit6fea478d2e7737c2462b074b935d4427ced5f3d4 (patch)
treeb14646c2e337e3a4d44fd7a61cb6bac60b8c42c6 /synapse/api/auth.py
parentSYWEB-146: Fix room ID leaking on recents page when the name of the room is j... (diff)
downloadsynapse-6fea478d2e7737c2462b074b935d4427ced5f3d4.tar.xz
Fix bugs with invites/joins across federatiom.
Both in terms of auth and not trying to fetch missing PDUs for invites,
joins etc.
Diffstat (limited to 'synapse/api/auth.py')
-rw-r--r--synapse/api/auth.py19
1 files changed, 16 insertions, 3 deletions
diff --git a/synapse/api/auth.py b/synapse/api/auth.py
index 6c2d3db26e..87f19a96d6 100644
--- a/synapse/api/auth.py
+++ b/synapse/api/auth.py
@@ -36,6 +36,7 @@ class Auth(object):
     def __init__(self, hs):
         self.hs = hs
         self.store = hs.get_datastore()
+        self.state = hs.get_state_handler()
 
     def check(self, event, raises=False):
         """ Checks if this event is correctly authed.
@@ -90,7 +91,7 @@ class Auth(object):
             )
             logger.info("Denying! %s", event)
             if raises:
-                raise e
+                raise
 
         return False
 
@@ -109,9 +110,21 @@ class Auth(object):
 
     @defer.inlineCallbacks
     def check_host_in_room(self, room_id, host):
-        joined_hosts = yield self.store.get_joined_hosts_for_room(room_id)
+        curr_state = yield self.state.get_current_state(room_id)
+
+        for event in curr_state:
+            if event.type == RoomMemberEvent.TYPE:
+                try:
+                    if self.hs.parse_userid(event.state_key).domain != host:
+                        continue
+                except:
+                    logger.warn("state_key not user_id: %s", event.state_key)
+                    continue
+
+                if event.content["membership"] == Membership.JOIN:
+                    defer.returnValue(True)
 
-        defer.returnValue(host in joined_hosts)
+        defer.returnValue(False)
 
     def check_event_sender_in_room(self, event):
         key = (RoomMemberEvent.TYPE, event.user_id, )