mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-09-24 18:48:27 -04:00
Add a spamchecker callback to allow or deny room joins (#10910)
Co-authored-by: Erik Johnston <erik@matrix.org>
This commit is contained in:
parent
b0460936c8
commit
829f2a82b0
6 changed files with 174 additions and 0 deletions
|
@ -860,6 +860,7 @@ class RoomCreationHandler(BaseHandler):
|
|||
"invite",
|
||||
ratelimit=False,
|
||||
content=content,
|
||||
new_room=True,
|
||||
)
|
||||
|
||||
for invite_3pid in invite_3pid_list:
|
||||
|
@ -962,6 +963,7 @@ class RoomCreationHandler(BaseHandler):
|
|||
"join",
|
||||
ratelimit=ratelimit,
|
||||
content=creator_join_profile,
|
||||
new_room=True,
|
||||
)
|
||||
|
||||
# We treat the power levels override specially as this needs to be one
|
||||
|
|
|
@ -434,6 +434,7 @@ class RoomMemberHandler(metaclass=abc.ABCMeta):
|
|||
third_party_signed: Optional[dict] = None,
|
||||
ratelimit: bool = True,
|
||||
content: Optional[dict] = None,
|
||||
new_room: bool = False,
|
||||
require_consent: bool = True,
|
||||
outlier: bool = False,
|
||||
prev_event_ids: Optional[List[str]] = None,
|
||||
|
@ -451,6 +452,8 @@ class RoomMemberHandler(metaclass=abc.ABCMeta):
|
|||
third_party_signed: Information from a 3PID invite.
|
||||
ratelimit: Whether to rate limit the request.
|
||||
content: The content of the created event.
|
||||
new_room: Whether the membership update is happening in the context of a room
|
||||
creation.
|
||||
require_consent: Whether consent is required.
|
||||
outlier: Indicates whether the event is an `outlier`, i.e. if
|
||||
it's from an arbitrary point and floating in the DAG as
|
||||
|
@ -485,6 +488,7 @@ class RoomMemberHandler(metaclass=abc.ABCMeta):
|
|||
third_party_signed=third_party_signed,
|
||||
ratelimit=ratelimit,
|
||||
content=content,
|
||||
new_room=new_room,
|
||||
require_consent=require_consent,
|
||||
outlier=outlier,
|
||||
prev_event_ids=prev_event_ids,
|
||||
|
@ -504,6 +508,7 @@ class RoomMemberHandler(metaclass=abc.ABCMeta):
|
|||
third_party_signed: Optional[dict] = None,
|
||||
ratelimit: bool = True,
|
||||
content: Optional[dict] = None,
|
||||
new_room: bool = False,
|
||||
require_consent: bool = True,
|
||||
outlier: bool = False,
|
||||
prev_event_ids: Optional[List[str]] = None,
|
||||
|
@ -523,6 +528,8 @@ class RoomMemberHandler(metaclass=abc.ABCMeta):
|
|||
third_party_signed:
|
||||
ratelimit:
|
||||
content:
|
||||
new_room: Whether the membership update is happening in the context of a room
|
||||
creation.
|
||||
require_consent:
|
||||
outlier: Indicates whether the event is an `outlier`, i.e. if
|
||||
it's from an arbitrary point and floating in the DAG as
|
||||
|
@ -726,6 +733,30 @@ class RoomMemberHandler(metaclass=abc.ABCMeta):
|
|||
# so don't really fit into the general auth process.
|
||||
raise AuthError(403, "Guest access not allowed")
|
||||
|
||||
# Figure out whether the user is a server admin to determine whether they
|
||||
# should be able to bypass the spam checker.
|
||||
if (
|
||||
self._server_notices_mxid is not None
|
||||
and requester.user.to_string() == self._server_notices_mxid
|
||||
):
|
||||
# allow the server notices mxid to join rooms
|
||||
bypass_spam_checker = True
|
||||
|
||||
else:
|
||||
bypass_spam_checker = await self.auth.is_server_admin(requester.user)
|
||||
|
||||
inviter = await self._get_inviter(target.to_string(), room_id)
|
||||
if (
|
||||
not bypass_spam_checker
|
||||
# We assume that if the spam checker allowed the user to create
|
||||
# a room then they're allowed to join it.
|
||||
and not new_room
|
||||
and not await self.spam_checker.user_may_join_room(
|
||||
target.to_string(), room_id, is_invited=inviter is not None
|
||||
)
|
||||
):
|
||||
raise SynapseError(403, "Not allowed to join this room")
|
||||
|
||||
# Check if a remote join should be performed.
|
||||
remote_join, remote_room_hosts = await self._should_perform_remote_join(
|
||||
target.to_string(), room_id, remote_room_hosts, content, is_host_in_room
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue