|
@@ -31,7 +31,7 @@ from synapse.rest.media.v1._base import FileInfo
|
|
|
from synapse.rest.media.v1.media_storage import ReadableFileWrapper
|
|
|
from synapse.spam_checker_api import RegistrationBehaviour
|
|
|
from synapse.types import RoomAlias, UserProfile
|
|
|
-from synapse.util.async_helpers import maybe_awaitable
|
|
|
+from synapse.util.async_helpers import delay_cancellation, maybe_awaitable
|
|
|
|
|
|
if TYPE_CHECKING:
|
|
|
import synapse.events
|
|
@@ -255,7 +255,7 @@ class SpamChecker:
|
|
|
will be used as the error message returned to the user.
|
|
|
"""
|
|
|
for callback in self._check_event_for_spam_callbacks:
|
|
|
- res: Union[bool, str] = await callback(event)
|
|
|
+ res: Union[bool, str] = await delay_cancellation(callback(event))
|
|
|
if res:
|
|
|
return res
|
|
|
|
|
@@ -276,7 +276,10 @@ class SpamChecker:
|
|
|
Whether the user may join the room
|
|
|
"""
|
|
|
for callback in self._user_may_join_room_callbacks:
|
|
|
- if await callback(user_id, room_id, is_invited) is False:
|
|
|
+ may_join_room = await delay_cancellation(
|
|
|
+ callback(user_id, room_id, is_invited)
|
|
|
+ )
|
|
|
+ if may_join_room is False:
|
|
|
return False
|
|
|
|
|
|
return True
|
|
@@ -297,7 +300,10 @@ class SpamChecker:
|
|
|
True if the user may send an invite, otherwise False
|
|
|
"""
|
|
|
for callback in self._user_may_invite_callbacks:
|
|
|
- if await callback(inviter_userid, invitee_userid, room_id) is False:
|
|
|
+ may_invite = await delay_cancellation(
|
|
|
+ callback(inviter_userid, invitee_userid, room_id)
|
|
|
+ )
|
|
|
+ if may_invite is False:
|
|
|
return False
|
|
|
|
|
|
return True
|
|
@@ -322,7 +328,10 @@ class SpamChecker:
|
|
|
True if the user may send the invite, otherwise False
|
|
|
"""
|
|
|
for callback in self._user_may_send_3pid_invite_callbacks:
|
|
|
- if await callback(inviter_userid, medium, address, room_id) is False:
|
|
|
+ may_send_3pid_invite = await delay_cancellation(
|
|
|
+ callback(inviter_userid, medium, address, room_id)
|
|
|
+ )
|
|
|
+ if may_send_3pid_invite is False:
|
|
|
return False
|
|
|
|
|
|
return True
|
|
@@ -339,7 +348,8 @@ class SpamChecker:
|
|
|
True if the user may create a room, otherwise False
|
|
|
"""
|
|
|
for callback in self._user_may_create_room_callbacks:
|
|
|
- if await callback(userid) is False:
|
|
|
+ may_create_room = await delay_cancellation(callback(userid))
|
|
|
+ if may_create_room is False:
|
|
|
return False
|
|
|
|
|
|
return True
|
|
@@ -359,7 +369,10 @@ class SpamChecker:
|
|
|
True if the user may create a room alias, otherwise False
|
|
|
"""
|
|
|
for callback in self._user_may_create_room_alias_callbacks:
|
|
|
- if await callback(userid, room_alias) is False:
|
|
|
+ may_create_room_alias = await delay_cancellation(
|
|
|
+ callback(userid, room_alias)
|
|
|
+ )
|
|
|
+ if may_create_room_alias is False:
|
|
|
return False
|
|
|
|
|
|
return True
|
|
@@ -377,7 +390,8 @@ class SpamChecker:
|
|
|
True if the user may publish the room, otherwise False
|
|
|
"""
|
|
|
for callback in self._user_may_publish_room_callbacks:
|
|
|
- if await callback(userid, room_id) is False:
|
|
|
+ may_publish_room = await delay_cancellation(callback(userid, room_id))
|
|
|
+ if may_publish_room is False:
|
|
|
return False
|
|
|
|
|
|
return True
|
|
@@ -400,7 +414,7 @@ class SpamChecker:
|
|
|
for callback in self._check_username_for_spam_callbacks:
|
|
|
# Make a copy of the user profile object to ensure the spam checker cannot
|
|
|
# modify it.
|
|
|
- if await callback(user_profile.copy()):
|
|
|
+ if await delay_cancellation(callback(user_profile.copy())):
|
|
|
return True
|
|
|
|
|
|
return False
|
|
@@ -428,7 +442,7 @@ class SpamChecker:
|
|
|
"""
|
|
|
|
|
|
for callback in self._check_registration_for_spam_callbacks:
|
|
|
- behaviour = await (
|
|
|
+ behaviour = await delay_cancellation(
|
|
|
callback(email_threepid, username, request_info, auth_provider_id)
|
|
|
)
|
|
|
assert isinstance(behaviour, RegistrationBehaviour)
|
|
@@ -472,7 +486,7 @@ class SpamChecker:
|
|
|
"""
|
|
|
|
|
|
for callback in self._check_media_file_for_spam_callbacks:
|
|
|
- spam = await callback(file_wrapper, file_info)
|
|
|
+ spam = await delay_cancellation(callback(file_wrapper, file_info))
|
|
|
if spam:
|
|
|
return True
|
|
|
|