From 6f77f7ee9ecec594f96c76406866861ca1d7c087 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20K=C3=B6sters?= Date: Wed, 13 Mar 2024 11:37:28 -0400 Subject: [PATCH] dont leak users in room directory if sender is not allowed to see them Signed-off-by: strawberry --- src/api/client_server/user_directory.rs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/api/client_server/user_directory.rs b/src/api/client_server/user_directory.rs index b71c42e0..9a84a2da 100644 --- a/src/api/client_server/user_directory.rs +++ b/src/api/client_server/user_directory.rs @@ -41,6 +41,9 @@ pub async fn search_users_route(body: Ruma) -> Result return None; } + // It's a matching user, but is the sender allowed to see them? + let mut user_visible = false; + let user_is_in_public_rooms = services().rooms.state_cache.rooms_joined(&user_id).filter_map(std::result::Result::ok).any(|room| { services().rooms.state_accessor.room_state_get(&room, &StateEventType::RoomJoinRules, "").map_or( @@ -55,17 +58,21 @@ pub async fn search_users_route(body: Ruma) -> Result }); if user_is_in_public_rooms { - return Some(user); + user_visible = true; + } else { + let user_is_in_shared_rooms = + services().rooms.user.get_shared_rooms(vec![sender_user.clone(), user_id]).ok()?.next().is_some(); + + if user_is_in_shared_rooms { + user_visible = true; + } } - let user_is_in_shared_rooms = - services().rooms.user.get_shared_rooms(vec![sender_user.clone(), user_id]).ok()?.next().is_some(); - - if user_is_in_shared_rooms { - return Some(user); + if !user_visible { + return None; } - None + Some(user) }); let results = users.by_ref().take(limit).collect();