From fb65c5ac5566fe2cecc7976615b43957214a5d5b Mon Sep 17 00:00:00 2001 From: lukasdenk Date: Sun, 2 Jan 2022 17:57:19 +0100 Subject: [PATCH 1/2] Solve issue #11245 Will raise M_FORBIDDEN instead of M_UNKNOWN whenever synapse/events/spamcheck.py:user_may_create_room returns False. Note: The M_FORBIDDEN code is set in the methods which call user_may_create_room, not in the method user_may_create_room itself. Signed-off-by: Lukas Denk --- changelog.d/11672.feature | 4 ++++ synapse/handlers/room.py | 8 ++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 changelog.d/11672.feature diff --git a/changelog.d/11672.feature b/changelog.d/11672.feature new file mode 100644 index 000000000000..0cff0bab5ada --- /dev/null +++ b/changelog.d/11672.feature @@ -0,0 +1,4 @@ +Whenever the `spamcheck` forbids a user to create a room, a `SynapseError` with `errcode` `M_UNKNOWN` is returned to the client. However, it would be more specific to return the `errcode` `M_UNKNOWN`. + +Therefore, this PR will raise `M_FORBIDDEN` instead of `M_UNKNOWN` whenever `synapse/events/spamcheck.py:user_may_create_room` returns `False`. +Note: The `M_FORBIDDEN` code is set in the methods which currently call `user_may_create_room`, not in the method `user_may_create_room` itself. diff --git a/synapse/handlers/room.py b/synapse/handlers/room.py index 2bcdf32dcce1..895a1224b756 100644 --- a/synapse/handlers/room.py +++ b/synapse/handlers/room.py @@ -393,7 +393,9 @@ async def clone_existing_room( user_id = requester.user.to_string() if not await self.spam_checker.user_may_create_room(user_id): - raise SynapseError(403, "You are not permitted to create rooms") + raise SynapseError( + 403, "You are not permitted to create rooms", Codes.FORBIDDEN + ) creation_content: JsonDict = { "room_version": new_room_version.identifier, @@ -685,7 +687,9 @@ async def create_room( invite_3pid_list, ) ): - raise SynapseError(403, "You are not permitted to create rooms") + raise SynapseError( + 403, "You are not permitted to create rooms", Codes.FORBIDDEN + ) if ratelimit: await self.request_ratelimiter.ratelimit(requester) From e8418a8833eacd4b4e4de5eee39a863a59c876bd Mon Sep 17 00:00:00 2001 From: reivilibre Date: Thu, 6 Jan 2022 12:49:23 +0000 Subject: [PATCH 2/2] Update changelog.d/11672.feature --- changelog.d/11672.feature | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/changelog.d/11672.feature b/changelog.d/11672.feature index 0cff0bab5ada..ce8b3e9547f1 100644 --- a/changelog.d/11672.feature +++ b/changelog.d/11672.feature @@ -1,4 +1 @@ -Whenever the `spamcheck` forbids a user to create a room, a `SynapseError` with `errcode` `M_UNKNOWN` is returned to the client. However, it would be more specific to return the `errcode` `M_UNKNOWN`. - -Therefore, this PR will raise `M_FORBIDDEN` instead of `M_UNKNOWN` whenever `synapse/events/spamcheck.py:user_may_create_room` returns `False`. -Note: The `M_FORBIDDEN` code is set in the methods which currently call `user_may_create_room`, not in the method `user_may_create_room` itself. +Return an `M_FORBIDDEN` error code instead of `M_UNKNOWN` when a spam checker module prevents a user from creating a room.