From cb46fcb9483a31a9b08a9b95ec893e0a68edf714 Mon Sep 17 00:00:00 2001 From: eason <85663565+mango766@users.noreply.github.com> Date: Thu, 30 Apr 2026 04:58:50 +0800 Subject: [PATCH] fix: return Err instead of panic on unknown cipher atype in to_json() (#7068) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `Cipher::to_json()` returns `Result` but its match arm for unknown `atype` values called `panic!("Wrong type")` instead of propagating an error. This means if a cipher with an invalid/unknown type ends up in the database (via direct DB edits, data migration issues, or future type additions in the upstream Bitwarden protocol), the entire server process would crash on the next sync request. Replace the `panic!` with `err!()` so callers receive a proper `Err` and can handle or log it gracefully without taking down the server. Co-authored-by: easonysliu Co-authored-by: Claude Opus 4.6 (1M context) Co-authored-by: Daniel GarcĂ­a --- src/db/models/cipher.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/db/models/cipher.rs b/src/db/models/cipher.rs index 87f3e415..db906179 100644 --- a/src/db/models/cipher.rs +++ b/src/db/models/cipher.rs @@ -403,7 +403,7 @@ impl Cipher { 3 => "card", 4 => "identity", 5 => "sshKey", - _ => panic!("Wrong type"), + _ => err!(format!("Cipher {} has an invalid type {}", self.uuid, self.atype)), }; json_object[key] = type_data_json;