diff options
author | Brendan Abolivier <babolivier@matrix.org> | 2021-05-12 16:05:28 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-12 16:05:28 +0200 |
commit | a683028d81606708f686b890c0a44f5a20b54798 (patch) | |
tree | 62d52062df2ebf4617b5297f1315f1bf6314d8ee /synapse/handlers/room_member.py | |
parent | Change the format of access tokens away from macaroons (#5588) (diff) | |
download | synapse-a683028d81606708f686b890c0a44f5a20b54798.tar.xz |
Correctly ratelimit invites when creating a room (#9968)
* Correctly ratelimit invites when creating a room Also allow ratelimiting for more than one action at a time.
Diffstat (limited to 'synapse/handlers/room_member.py')
-rw-r--r-- | synapse/handlers/room_member.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/synapse/handlers/room_member.py b/synapse/handlers/room_member.py index 20700fc5a8..9a092da715 100644 --- a/synapse/handlers/room_member.py +++ b/synapse/handlers/room_member.py @@ -163,6 +163,31 @@ class RoomMemberHandler(metaclass=abc.ABCMeta): async def forget(self, user: UserID, room_id: str) -> None: raise NotImplementedError() + async def ratelimit_multiple_invites( + self, + requester: Optional[Requester], + room_id: Optional[str], + n_invites: int, + update: bool = True, + ): + """Ratelimit more than one invite sent by the given requester in the given room. + + Args: + requester: The requester sending the invites. + room_id: The room the invites are being sent in. + n_invites: The amount of invites to ratelimit for. + update: Whether to update the ratelimiter's cache. + + Raises: + LimitExceededError: The requester can't send that many invites in the room. + """ + await self._invites_per_room_limiter.ratelimit( + requester, + room_id, + update=update, + n_actions=n_invites, + ) + async def ratelimit_invite( self, requester: Optional[Requester], |