[PR #6936] [MERGED] Replace organization_uuid unwrap with proper error handling #32894

Closed
opened 2026-06-20 19:35:57 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/dani-garcia/vaultwarden/pull/6936
Author: @xjohnyknox
Created: 3/13/2026
Status: Merged
Merged: 4/29/2026
Merged by: @dani-garcia

Base: mainHead: fix/remove-unwrap-organization-uuid


📝 Commits (3)

  • 8e78a3b Replace organization_uuid unwrap with proper error handling
  • b78498f Merge branch 'main' into fix/remove-unwrap-organization-uuid
  • 4286c08 Merge branch 'main' into fix/remove-unwrap-organization-uuid

📊 Changes

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

View changed files

📝 src/api/core/ciphers.rs (+12 -4)

📄 Description

Summary

The collection update endpoints (post_collections_update and post_collections_admin) call .unwrap() on cipher.organization_uuid in four places. If a cipher without an organization UUID reaches these code paths, the server panics instead of returning an error.

Root cause

cipher.organization_uuid is Option<OrganizationId>. While the earlier is_in_editable_collection_by_user guard should prevent user-owned ciphers from reaching this code, the .unwrap() calls create a hard dependency on that guard — any future changes to the guard logic could silently introduce a panic path.

Fix

Extract organization_uuid early in each function using let Some(ref org_uuid) = ... else { err!(...) }, then reuse the binding throughout. This replaces four .unwrap() calls with a single, clear error return per function.

Test plan

  • Assign a cipher to a collection as a normal org user — should work as before
  • Update collections via admin endpoint — should work as before
  • Attempt to update collections on a cipher with no organization (if reachable) — should return error instead of panicking

🔄 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/6936 **Author:** [@xjohnyknox](https://github.com/xjohnyknox) **Created:** 3/13/2026 **Status:** ✅ Merged **Merged:** 4/29/2026 **Merged by:** [@dani-garcia](https://github.com/dani-garcia) **Base:** `main` ← **Head:** `fix/remove-unwrap-organization-uuid` --- ### 📝 Commits (3) - [`8e78a3b`](https://github.com/dani-garcia/vaultwarden/commit/8e78a3bfd778cfff4c86ddfb71ea0e67fd60d5ad) Replace organization_uuid unwrap with proper error handling - [`b78498f`](https://github.com/dani-garcia/vaultwarden/commit/b78498f82fea89325d2f75f23e486d45833eae25) Merge branch 'main' into fix/remove-unwrap-organization-uuid - [`4286c08`](https://github.com/dani-garcia/vaultwarden/commit/4286c08f94a5478078d9983cf937b1c13b147c74) Merge branch 'main' into fix/remove-unwrap-organization-uuid ### 📊 Changes **1 file changed** (+12 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `src/api/core/ciphers.rs` (+12 -4) </details> ### 📄 Description ## Summary The collection update endpoints (`post_collections_update` and `post_collections_admin`) call `.unwrap()` on `cipher.organization_uuid` in four places. If a cipher without an organization UUID reaches these code paths, the server panics instead of returning an error. ### Root cause `cipher.organization_uuid` is `Option<OrganizationId>`. While the earlier `is_in_editable_collection_by_user` guard should prevent user-owned ciphers from reaching this code, the `.unwrap()` calls create a hard dependency on that guard — any future changes to the guard logic could silently introduce a panic path. ### Fix Extract `organization_uuid` early in each function using `let Some(ref org_uuid) = ... else { err!(...) }`, then reuse the binding throughout. This replaces four `.unwrap()` calls with a single, clear error return per function. ## Test plan - [ ] Assign a cipher to a collection as a normal org user — should work as before - [ ] Update collections via admin endpoint — should work as before - [ ] Attempt to update collections on a cipher with no organization (if reachable) — should return error instead of panicking --- <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-06-20 19:35:57 -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#32894