From ae6d52a6384a19e81b069af9b7b55c9630d2157e Mon Sep 17 00:00:00 2001 From: qaz741wsd856 Date: Sun, 30 Nov 2025 10:44:16 +0000 Subject: [PATCH] fix: handle null folder IDs in account data to prevent errors during updates --- src/handlers/accounts.rs | 16 +++++++++++++--- src/models/user.rs | 5 ++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/handlers/accounts.rs b/src/handlers/accounts.rs index c6e869a..9a7599c 100644 --- a/src/handlers/accounts.rs +++ b/src/handlers/accounts.rs @@ -302,8 +302,13 @@ pub async fn post_rotatekey( .filter(|c| c.organization_id.is_none()) .map(|c| c.id.clone()) .collect(); - let request_folder_ids: Vec = - payload.account_data.folders.iter().map(|f| f.id.clone()).collect(); + // Filter out null folder IDs (Bitwarden client bug: https://github.com/bitwarden/clients/issues/8453) + let request_folder_ids: Vec = payload + .account_data + .folders + .iter() + .filter_map(|f| f.id.clone()) + .collect(); let cipher_ids_json = serde_json::to_string(&request_cipher_ids).map_err(|_| AppError::Internal)?; @@ -371,15 +376,20 @@ pub async fn post_rotatekey( let now = Utc::now().format("%Y-%m-%dT%H:%M:%S%.3fZ").to_string(); // Update all folders with new encrypted names (batch operation) + // Skip null folder IDs (Bitwarden client bug: https://github.com/bitwarden/clients/issues/8453) let mut folder_statements: Vec = Vec::with_capacity(payload.account_data.folders.len()); for folder in &payload.account_data.folders { + // Skip null folder id entries + let Some(folder_id) = &folder.id else { + continue; + }; let stmt = query!( &db, "UPDATE folders SET name = ?1, updated_at = ?2 WHERE id = ?3 AND user_id = ?4", folder.name, now, - folder.id, + folder_id, user_id ) .map_err(|_| AppError::Database)?; diff --git a/src/models/user.rs b/src/models/user.rs index ed102cd..cb9f3a2 100644 --- a/src/models/user.rs +++ b/src/models/user.rs @@ -223,6 +223,9 @@ pub struct RotateCipherData { #[derive(Debug, Deserialize)] #[serde(rename_all = "camelCase")] pub struct RotateFolderData { - pub id: String, + // There is a bug in 2024.3.x which adds a `null` item. + // To bypass this we allow an Option here, but skip it during the updates + // See: https://github.com/bitwarden/clients/issues/8453 + pub id: Option, pub name: String, }