Fix joining rooms you have been unbanned from (#15323)

* Fix joining rooms you have been unbanned from

Since forever synapse did not allow you to join a room after you have
been unbanned from it over federation. This was not actually because of
the unban event not federating. Synapse simply used outdated state to
validate the join transition. This skips the validation if we are not in
the room and for that reason won't have the current room state.

Fixes #1563

Signed-off-by: Nicolas Werner <nicolas.werner@hotmail.de>

* Add changelog

Signed-off-by: Nicolas Werner <nicolas.werner@hotmail.de>

* Update changelog.d/15323.bugfix

---------

Signed-off-by: Nicolas Werner <nicolas.werner@hotmail.de>
This commit is contained in:
DeepBlueV7.X 2023-03-29 08:37:27 +00:00 committed by GitHub
parent 5282ba1e2b
commit 753d1d9cde
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 63 additions and 57 deletions

1
changelog.d/15323.bugfix Normal file
View File

@ -0,0 +1 @@
Fix a long-standing bug preventing users from joining rooms, that they had been unbanned from, over federation. Contributed by Nico.

View File

@ -583,7 +583,7 @@ class FederationEventHandler:
await self._check_event_auth(origin, event, context) await self._check_event_auth(origin, event, context)
if context.rejected: if context.rejected:
raise SynapseError(400, "Join event was rejected") raise SynapseError(403, "Join event was rejected")
# the remote server is responsible for sending our join event to the rest # the remote server is responsible for sending our join event to the rest
# of the federation. Indeed, attempting to do so will result in problems # of the federation. Indeed, attempting to do so will result in problems

View File

@ -850,15 +850,22 @@ class RoomMemberHandler(metaclass=abc.ABCMeta):
# `is_partial_state_room` also indicates whether `partial_state_before_join` is # `is_partial_state_room` also indicates whether `partial_state_before_join` is
# partial. # partial.
is_host_in_room = await self._is_host_in_room(partial_state_before_join)
# if we are not in the room, we won't have the current state
if is_host_in_room:
# TODO: Refactor into dictionary of explicitly allowed transitions # TODO: Refactor into dictionary of explicitly allowed transitions
# between old and new state, with specific error messages for some # between old and new state, with specific error messages for some
# transitions and generic otherwise # transitions and generic otherwise
old_state_id = partial_state_before_join.get( old_state_id = partial_state_before_join.get(
(EventTypes.Member, target.to_string()) (EventTypes.Member, target.to_string())
) )
if old_state_id: if old_state_id:
old_state = await self.store.get_event(old_state_id, allow_none=True) old_state = await self.store.get_event(old_state_id, allow_none=True)
old_membership = old_state.content.get("membership") if old_state else None old_membership = (
old_state.content.get("membership") if old_state else None
)
if action == "unban" and old_membership != "ban": if action == "unban" and old_membership != "ban":
raise SynapseError( raise SynapseError(
403, 403,
@ -906,8 +913,6 @@ class RoomMemberHandler(metaclass=abc.ABCMeta):
if action == "kick": if action == "kick":
raise AuthError(403, "The target user is not in the room") raise AuthError(403, "The target user is not in the room")
is_host_in_room = await self._is_host_in_room(partial_state_before_join)
if effective_membership_state == Membership.JOIN: if effective_membership_state == Membership.JOIN:
if requester.is_guest: if requester.is_guest:
guest_can_join = await self._can_guest_join(partial_state_before_join) guest_can_join = await self._can_guest_join(partial_state_before_join)