0
0
Fork 1
mirror of https://mau.dev/maunium/synapse.git synced 2024-12-14 11:33:53 +01:00

Merge pull request #5104 from matrix-org/erikj/ratelimit_3pid_invite

Ratelimit 3pid invites
This commit is contained in:
Erik Johnston 2019-05-07 10:12:49 +01:00 committed by GitHub
commit de655e669a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 0 deletions

1
changelog.d/5104.bugfix Normal file
View file

@ -0,0 +1 @@
Fix the ratelimting on third party invites.

View file

@ -33,6 +33,8 @@ from synapse.types import RoomID, UserID
from synapse.util.async_helpers import Linearizer from synapse.util.async_helpers import Linearizer
from synapse.util.distributor import user_joined_room, user_left_room from synapse.util.distributor import user_joined_room, user_left_room
from ._base import BaseHandler
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
id_server_scheme = "https://" id_server_scheme = "https://"
@ -72,6 +74,11 @@ class RoomMemberHandler(object):
self._server_notices_mxid = self.config.server_notices_mxid self._server_notices_mxid = self.config.server_notices_mxid
self._enable_lookup = hs.config.enable_3pid_lookup self._enable_lookup = hs.config.enable_3pid_lookup
# This is only used to get at ratelimit function, and
# maybe_kick_guest_users. It's fine there are multiple of these as
# it doesn't store state.
self.base_handler = BaseHandler(hs)
@abc.abstractmethod @abc.abstractmethod
def _remote_join(self, requester, remote_room_hosts, room_id, user, content): def _remote_join(self, requester, remote_room_hosts, room_id, user, content):
"""Try and join a room that this server is not in """Try and join a room that this server is not in
@ -703,6 +710,10 @@ class RoomMemberHandler(object):
Codes.FORBIDDEN, Codes.FORBIDDEN,
) )
# We need to rate limit *before* we send out any 3PID invites, so we
# can't just rely on the standard ratelimiting of events.
yield self.base_handler.ratelimit(requester)
invitee = yield self._lookup_3pid( invitee = yield self._lookup_3pid(
id_server, medium, address id_server, medium, address
) )