From de71731c9d5350b5077bffb4a495c66f8e4adb0b Mon Sep 17 00:00:00 2001 From: "shuwen.wu" Date: Thu, 8 Oct 2026 14:03:55 +0800 Subject: [PATCH] Validate SSH key cipher required fields on write path Bitwarden cloud rejects SSH key ciphers (type 5) where privateKey, publicKey, or keyFingerprint is null or empty, returning a validation error. Vaultwarden previously accepted such payloads and returned a success response, but the read path (src/db/models/cipher.rs) would silently nullify the invalid sshKey object, causing silent data loss. This adds matching validation on the create/update path so invalid ciphers are rejected with an error rather than appearing to succeed while losing data on reload. Fixes #7514 --- src/api/core/ciphers.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/api/core/ciphers.rs b/src/api/core/ciphers.rs index 46766896..6fe671b8 100644 --- a/src/api/core/ciphers.rs +++ b/src/api/core/ciphers.rs @@ -551,6 +551,7 @@ pub async fn update_cipher_from_data( _ => err!("Invalid type"), }; + let cipher_type = data.r#type; let type_data = if let Some(mut data) = type_data_opt { // Remove the 'Response' key from the base object. if let Some(data_obj) = data.as_object_mut() { @@ -560,6 +561,18 @@ pub async fn update_cipher_from_data( if data["uris"].is_array() { data["uris"] = clean_cipher_data(data["uris"].clone()); } + // Validate SSH key required fields. Bitwarden cloud rejects ciphers where + // privateKey, publicKey, or keyFingerprint is null or empty; matching that + // validation here prevents silent data loss on the round-trip (the read + // path nullifies invalid SSH keys, so an invalid write would look like it + // succeeded but the data would disappear on reload). + if cipher_type == 5 + && (data["keyFingerprint"].as_str().is_none_or(str::is_empty) + || data["privateKey"].as_str().is_none_or(str::is_empty) + || data["publicKey"].as_str().is_none_or(str::is_empty)) + { + err!("SSH Key must provide non-empty privateKey, publicKey, and keyFingerprint") + } data } else { err!("Data missing")