diff options
author | Erik Johnston <erik@matrix.org> | 2022-05-31 14:48:22 +0100 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2022-05-31 14:48:22 +0100 |
commit | 3594f6c1f340f12bfcb2fec9e99ac108a714b508 (patch) | |
tree | f7f995f24f23cc3b270b625971f60bc4ad98fb46 /synapse/handlers | |
parent | Test Synapse against Complement with workers. (#12810) (diff) | |
parent | Update changelog (diff) | |
download | synapse-3594f6c1f340f12bfcb2fec9e99ac108a714b508.tar.xz |
Merge branch 'master' into develop
Diffstat (limited to 'synapse/handlers')
-rw-r--r-- | synapse/handlers/message.py | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/synapse/handlers/message.py b/synapse/handlers/message.py index f377769071..cf7c2d1979 100644 --- a/synapse/handlers/message.py +++ b/synapse/handlers/message.py @@ -23,7 +23,6 @@ from canonicaljson import encode_canonical_json from twisted.internet.interfaces import IDelayedCall -import synapse from synapse import event_auth from synapse.api.constants import ( EventContentFields, @@ -897,11 +896,11 @@ class EventCreationHandler: event.sender, ) - spam_check = await self.spam_checker.check_event_for_spam(event) - if spam_check is not synapse.spam_checker_api.Allow.ALLOW: - if isinstance(spam_check, tuple): + spam_check_result = await self.spam_checker.check_event_for_spam(event) + if spam_check_result != self.spam_checker.NOT_SPAM: + if isinstance(spam_check_result, tuple): try: - [code, dict] = spam_check + [code, dict] = spam_check_result raise SynapseError( 403, "This message had been rejected as probable spam", @@ -911,11 +910,24 @@ class EventCreationHandler: except ValueError: logger.error( "Spam-check module returned invalid error value. Expecting [code, dict], got %s", - spam_check, + spam_check_result, ) - spam_check = Codes.FORBIDDEN + spam_check_result = Codes.FORBIDDEN + + if isinstance(spam_check_result, Codes): + raise SynapseError( + 403, + "This message has been rejected as probable spam", + spam_check_result, + ) + + # Backwards compatibility: if the return value is not an error code, it + # means the module returned an error message to be included in the + # SynapseError (which is now deprecated). raise SynapseError( - 403, "This message had been rejected as probable spam", spam_check + 403, + spam_check_result, + Codes.FORBIDDEN, ) ev = await self.handle_new_client_event( |