mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-09-03 17:45:44 +00:00
fix(web): scope GET /api/v1/sessions to the authenticated user (#2445)
handle_list_all_sessions returned client_mgr.list_sessions(), which iterates user_clients_map across ALL users and returns every session's StorageToken (token, client_url, machine_id, user_id). The handler is mounted under login_required! but performed no per-user authorization: it fetched get_group_permissions() only to println! the result, then returned the full cross-user list. Any authenticated user could read every other user's device token and public client_url. Scope the result to the caller by adding Storage::list_user_client_tokens(user_id) / ClientManager::list_sessions_by_user_id(user_id), mirroring the existing per-user pattern in handle_get_summary (list_machine_by_user_id). Also drop the leftover debug println! and the unwrap() on the current user (return 401 instead).
This commit is contained in:
@@ -143,6 +143,21 @@ impl Storage {
|
||||
self.list_clients_with_auth(true)
|
||||
}
|
||||
|
||||
/// List authorized client sessions that belong to a single user only.
|
||||
pub fn list_user_client_tokens(&self, user_id: UserIdInDb) -> Vec<StorageToken> {
|
||||
self.0
|
||||
.user_clients_map
|
||||
.get(&user_id)
|
||||
.map(|info_map| {
|
||||
info_map
|
||||
.iter()
|
||||
.filter(|info| info.value().authorized)
|
||||
.map(|info| info.value().storage_token.clone())
|
||||
.collect()
|
||||
})
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
pub fn list_all_clients(&self) -> Vec<StorageToken> {
|
||||
self.list_clients_with_auth(false)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user