fix: handle null folder IDs in account data to prevent errors during updates

This commit is contained in:
qaz741wsd856 2025-11-30 10:44:16 +00:00
parent b3c3aa2f33
commit ae6d52a638
2 changed files with 17 additions and 4 deletions

View file

@ -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<String> =
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<String> = 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<D1PreparedStatement> =
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)?;

View file

@ -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<String>,
pub name: String,
}