[PR #7068] [MERGED] fix: return Err instead of panic on unknown cipher atype in to_json() #20743

Closed
opened 2026-04-25 22:42:35 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/dani-garcia/vaultwarden/pull/7068
Author: @mango766
Created: 4/9/2026
Status: Merged
Merged: 4/29/2026
Merged by: @dani-garcia

Base: mainHead: fix/cipher-type-panic


📝 Commits (3)

  • d37a0a4 fix: return error instead of panicking on invalid cipher type in to_json
  • cdb4a06 Merge branch 'main' into fix/cipher-type-panic
  • 8fb0843 Merge branch 'main' into fix/cipher-type-panic

📊 Changes

1 file changed (+1 additions, -1 deletions)

View changed files

📝 src/db/models/cipher.rs (+1 -1)

📄 Description

Fixes #7067

What

Cipher::to_json() returns Result<Value, Error> but the wildcard arm of the atype match called panic!("Wrong type"). This means if a cipher with an unrecognised type exists in the database, the whole request (and potentially the server) panics instead of failing gracefully.

Change

One-line fix — replace panic! with err!, which is already used elsewhere in the same file:

-            _ => panic!("Wrong type"),
+            _ => err!(format!("Cipher {} has an invalid type {}", self.uuid, self.atype)),

This lets callers receive a proper Err, the error gets logged, and the sync request returns a failure response without crashing the server.

How it can happen

  • A cipher row is edited directly in the database
  • A future Bitwarden protocol version introduces a new type that vaultwarden doesn't yet recognise
  • Data migration from a third-party tool writes an unexpected value

In all these cases the current code would terminate the Rocket worker thread for every sync request that includes that cipher, affecting all concurrent users.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/dani-garcia/vaultwarden/pull/7068 **Author:** [@mango766](https://github.com/mango766) **Created:** 4/9/2026 **Status:** ✅ Merged **Merged:** 4/29/2026 **Merged by:** [@dani-garcia](https://github.com/dani-garcia) **Base:** `main` ← **Head:** `fix/cipher-type-panic` --- ### 📝 Commits (3) - [`d37a0a4`](https://github.com/dani-garcia/vaultwarden/commit/d37a0a4219f0bfe6f83070bb006e1d20de6ff326) fix: return error instead of panicking on invalid cipher type in to_json - [`cdb4a06`](https://github.com/dani-garcia/vaultwarden/commit/cdb4a06b3d8deb1a8160a8a8367401eebe623b71) Merge branch 'main' into fix/cipher-type-panic - [`8fb0843`](https://github.com/dani-garcia/vaultwarden/commit/8fb0843376828e645283068568332069960f7730) Merge branch 'main' into fix/cipher-type-panic ### 📊 Changes **1 file changed** (+1 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `src/db/models/cipher.rs` (+1 -1) </details> ### 📄 Description Fixes #7067 ## What `Cipher::to_json()` returns `Result<Value, Error>` but the wildcard arm of the `atype` match called `panic!("Wrong type")`. This means if a cipher with an unrecognised type exists in the database, the whole request (and potentially the server) panics instead of failing gracefully. ## Change One-line fix — replace `panic!` with `err!`, which is already used elsewhere in the same file: ```diff - _ => panic!("Wrong type"), + _ => err!(format!("Cipher {} has an invalid type {}", self.uuid, self.atype)), ``` This lets callers receive a proper `Err`, the error gets logged, and the sync request returns a failure response without crashing the server. ## How it can happen - A cipher row is edited directly in the database - A future Bitwarden protocol version introduces a new type that vaultwarden doesn't yet recognise - Data migration from a third-party tool writes an unexpected value In all these cases the current code would terminate the Rocket worker thread for every sync request that includes that cipher, affecting all concurrent users. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-25 22:42:35 -05:00
GiteaMirror changed title from [PR #7068] fix: return Err instead of panic on unknown cipher atype in to_json() to [PR #7068] [MERGED] fix: return Err instead of panic on unknown cipher atype in to_json() 2026-04-30 08:24:39 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/vaultwarden#20743