Allow spam checker to reject invites too

pull/2492/head
David Baker 2017-10-03 13:53:09 +01:00
parent e4779be97a
commit 84716d267c
2 changed files with 18 additions and 6 deletions

View File

@ -77,6 +77,7 @@ class FederationHandler(BaseHandler):
self.action_generator = hs.get_action_generator() self.action_generator = hs.get_action_generator()
self.is_mine_id = hs.is_mine_id self.is_mine_id = hs.is_mine_id
self.pusher_pool = hs.get_pusherpool() self.pusher_pool = hs.get_pusherpool()
self.spam_checker = hs.get_spam_checker()
self.replication_layer.set_handler(self) self.replication_layer.set_handler(self)
@ -1077,6 +1078,9 @@ class FederationHandler(BaseHandler):
if self.hs.config.block_non_admin_invites: if self.hs.config.block_non_admin_invites:
raise SynapseError(403, "This server does not accept room invites") raise SynapseError(403, "This server does not accept room invites")
if not self.spam_checker.user_may_invite(requester.user):
raise SynapseError(403, "This user is not permitted to send invites to this server")
membership = event.content.get("membership") membership = event.content.get("membership")
if event.type != EventTypes.Member or membership != Membership.INVITE: if event.type != EventTypes.Member or membership != Membership.INVITE:
raise SynapseError(400, "The event was not an m.room.member invite event") raise SynapseError(400, "The event was not an m.room.member invite event")

View File

@ -48,6 +48,7 @@ class RoomMemberHandler(BaseHandler):
self.member_linearizer = Linearizer(name="member") self.member_linearizer = Linearizer(name="member")
self.clock = hs.get_clock() self.clock = hs.get_clock()
self.spam_checker = hs.get_spam_checker()
self.distributor = hs.get_distributor() self.distributor = hs.get_distributor()
self.distributor.declare("user_joined_room") self.distributor.declare("user_joined_room")
@ -210,12 +211,19 @@ class RoomMemberHandler(BaseHandler):
if is_blocked: if is_blocked:
raise SynapseError(403, "This room has been blocked on this server") raise SynapseError(403, "This room has been blocked on this server")
if (effective_membership_state == "invite" and if effective_membership_state == "invite":
self.hs.config.block_non_admin_invites): block_invite = False
is_requester_admin = yield self.auth.is_server_admin( if self.hs.config.block_non_admin_invites:
requester.user, is_requester_admin = yield self.auth.is_server_admin(
) requester.user,
if not is_requester_admin: )
if not is_requester_admin:
block_invite = True
if not self.spam_checker.user_may_invite(requester.user):
block_invite = True
if block_invite:
raise SynapseError( raise SynapseError(
403, "Invites have been disabled on this server", 403, "Invites have been disabled on this server",
) )