Browse Source

fix: return error instead of panicking on invalid cipher type in to_json

`Cipher::to_json()` returns `Result<Value, Error>` 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: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
pull/7068/head
easonysliu 2 weeks ago
parent
commit
d37a0a4219
  1. 2
      src/db/models/cipher.rs

2
src/db/models/cipher.rs

@ -398,7 +398,7 @@ impl Cipher {
3 => "card", 3 => "card",
4 => "identity", 4 => "identity",
5 => "sshKey", 5 => "sshKey",
_ => panic!("Wrong type"), _ => err!(format!("Cipher {} has an invalid type {}", self.uuid, self.atype)),
}; };
json_object[key] = type_data_json; json_object[key] = type_data_json;

Loading…
Cancel
Save