summary refs log tree commit diff
path: root/synapse/handlers
diff options
context:
space:
mode:
authorAndrew Morgan <andrew@amorgan.xyz>2020-03-23 17:38:09 +0000
committerAndrew Morgan <andrew@amorgan.xyz>2020-03-23 17:38:09 +0000
commitb683d4b07e7dccac79fc853ccf2c08ec271e1bd0 (patch)
tree6d98aa0954d24448b1dd7eb27d99d306e8b914d1 /synapse/handlers
parentUpdate changelog for #6905 to group it with upcoming PRs (diff)
parentFilter the results of user directory searching via the spam checker (#6888) (diff)
downloadsynapse-b683d4b07e7dccac79fc853ccf2c08ec271e1bd0.tar.xz
Filter the results of user directory searching via the spam checker (#6888)
* commit '49f877d32':
  Filter the results of user directory searching via the spam checker (#6888)
Diffstat (limited to 'synapse/handlers')
-rw-r--r--synapse/handlers/federation.py2
-rw-r--r--synapse/handlers/user_directory.py14
2 files changed, 13 insertions, 3 deletions
diff --git a/synapse/handlers/federation.py b/synapse/handlers/federation.py
index 1ec61340ad..a9464b4cf8 100644
--- a/synapse/handlers/federation.py
+++ b/synapse/handlers/federation.py
@@ -1538,7 +1538,7 @@ class FederationHandler(BaseHandler):
         if self.hs.config.block_non_admin_invites:
             raise SynapseError(403, "This server does not accept room invites")
 
-        is_published = yield self.store.is_room_published(event.room_id)
+        is_published = await self.store.is_room_published(event.room_id)
 
         if not self.spam_checker.user_may_invite(
             event.sender,
diff --git a/synapse/handlers/user_directory.py b/synapse/handlers/user_directory.py
index 81aa58dc8c..722760c59d 100644
--- a/synapse/handlers/user_directory.py
+++ b/synapse/handlers/user_directory.py
@@ -52,6 +52,7 @@ class UserDirectoryHandler(StateDeltasHandler):
         self.is_mine_id = hs.is_mine_id
         self.update_user_directory = hs.config.update_user_directory
         self.search_all_users = hs.config.user_directory_search_all_users
+        self.spam_checker = hs.get_spam_checker()
         # The current position in the current_state_delta stream
         self.pos = None
 
@@ -65,7 +66,7 @@ class UserDirectoryHandler(StateDeltasHandler):
             # we start populating the user directory
             self.clock.call_later(0, self.notify_new_event)
 
-    def search_users(self, user_id, search_term, limit):
+    async def search_users(self, user_id, search_term, limit):
         """Searches for users in directory
 
         Returns:
@@ -82,7 +83,16 @@ class UserDirectoryHandler(StateDeltasHandler):
                     ]
                 }
         """
-        return self.store.search_user_dir(user_id, search_term, limit)
+        results = await self.store.search_user_dir(user_id, search_term, limit)
+
+        # Remove any spammy users from the results.
+        results["results"] = [
+            user
+            for user in results["results"]
+            if not self.spam_checker.check_username_for_spam(user)
+        ]
+
+        return results
 
     def notify_new_event(self):
         """Called when there may be more deltas to process