summary refs log tree commit diff
path: root/synapse/handlers/message.py
diff options
context:
space:
mode:
authorDavid Teller <D.O.Teller@gmail.com>2022-05-30 18:24:56 +0200
committerGitHub <noreply@github.com>2022-05-30 18:24:56 +0200
commitaf7db19e1e89e9b4ac4818c47b7f389ad46a7c9b (patch)
tree6752f92e20c89834c553fc5ff71e898e30c8f313 /synapse/handlers/message.py
parentdemo: check if we are in a virtualenv before overriding PYTHONPATH (#12916) (diff)
downloadsynapse-af7db19e1e89e9b4ac4818c47b7f389ad46a7c9b.tar.xz
Uniformize spam-checker API, part 3: Expand check_event_for_spam with the ability to return additional fields (#12846)
Signed-off-by: David Teller <davidt@element.io>
Diffstat (limited to 'synapse/handlers/message.py')
-rw-r--r--synapse/handlers/message.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/synapse/handlers/message.py b/synapse/handlers/message.py
index 7ca126dbd1..38b71a2c96 100644
--- a/synapse/handlers/message.py
+++ b/synapse/handlers/message.py
@@ -895,6 +895,21 @@ class EventCreationHandler:
 
             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):
+                    try:
+                        [code, dict] = spam_check
+                        raise SynapseError(
+                            403,
+                            "This message had been rejected as probable spam",
+                            code,
+                            dict,
+                        )
+                    except ValueError:
+                        logger.error(
+                            "Spam-check module returned invalid error value. Expecting [code, dict], got %s",
+                            spam_check,
+                        )
+                        spam_check = Codes.FORBIDDEN
                 raise SynapseError(
                     403, "This message had been rejected as probable spam", spam_check
                 )