diff options
author | reivilibre <oliverw@matrix.org> | 2021-11-01 15:45:56 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-01 15:45:56 +0000 |
commit | 69ab3dddbc1595ee64c428df7a7f3c861a84b5b0 (patch) | |
tree | d765576c98cd2620dfbc87d4c6597c4a34ff5262 /synapse | |
parent | Remove deprecated delete room admin API (#11213) (diff) | |
download | synapse-69ab3dddbc1595ee64c428df7a7f3c861a84b5b0.tar.xz |
Make `check_event_allowed` module API callback not fail open (accept events) when an exception is raised (#11033)
Diffstat (limited to 'synapse')
-rw-r--r-- | synapse/api/errors.py | 7 | ||||
-rw-r--r-- | synapse/events/third_party_rules.py | 9 |
2 files changed, 12 insertions, 4 deletions
diff --git a/synapse/api/errors.py b/synapse/api/errors.py index 685d1c25cf..85302163da 100644 --- a/synapse/api/errors.py +++ b/synapse/api/errors.py @@ -596,3 +596,10 @@ class ShadowBanError(Exception): This should be caught and a proper "fake" success response sent to the user. """ + + +class ModuleFailedException(Exception): + """ + Raised when a module API callback fails, for example because it raised an + exception. + """ diff --git a/synapse/events/third_party_rules.py b/synapse/events/third_party_rules.py index 8816ef4b76..1bb8ca7145 100644 --- a/synapse/events/third_party_rules.py +++ b/synapse/events/third_party_rules.py @@ -14,7 +14,7 @@ import logging from typing import TYPE_CHECKING, Any, Awaitable, Callable, List, Optional, Tuple -from synapse.api.errors import SynapseError +from synapse.api.errors import ModuleFailedException, SynapseError from synapse.events import EventBase from synapse.events.snapshot import EventContext from synapse.types import Requester, StateMap @@ -233,9 +233,10 @@ class ThirdPartyEventRules: # This module callback needs a rework so that hacks such as # this one are not necessary. raise e - except Exception as e: - logger.warning("Failed to run module API callback %s: %s", callback, e) - continue + except Exception: + raise ModuleFailedException( + "Failed to run `check_event_allowed` module API callback" + ) # Return if the event shouldn't be allowed or if the module came up with a # replacement dict for the event. |