diff --git a/changelog.d/12846.feature b/changelog.d/12846.feature deleted file mode 100644 index eaf777e108d3..000000000000 --- a/changelog.d/12846.feature +++ /dev/null @@ -1 +0,0 @@ -Experimental: expand `check_event_for_spam` with ability to return additional fields. \ No newline at end of file diff --git a/changelog.d/12846.misc b/changelog.d/12846.misc new file mode 100644 index 000000000000..f72d3d2bea23 --- /dev/null +++ b/changelog.d/12846.misc @@ -0,0 +1 @@ +Experimental: expand `check_event_for_spam` with ability to return additional fields. This enables spam-checker implementations to experiment with mechanisms to give users more information about why they are blocked and whether any action is needed from them to be unblocked. \ No newline at end of file diff --git a/synapse/handlers/message.py b/synapse/handlers/message.py index 920dc4c5e9ba..fa5909cf9785 100644 --- a/synapse/handlers/message.py +++ b/synapse/handlers/message.py @@ -888,14 +888,21 @@ async def create_and_send_nonmember_event( 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): - [code, dict] = spam_check - raise SynapseError( - 403, - "This message had been rejected as probable spam", - code, - dict, + try: + if isinstance(spam_check, tuple): + [code, dict] = spam_check + raise SynapseError( + 403, + "This message had been rejected as probable spam", + code, + dict, + ) + except ValueError: + logger.warning( + "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 )