Skip to content

Replace organization_uuid unwrap with proper error handling#6936

Merged
dani-garcia merged 3 commits intodani-garcia:mainfrom
xjohnyknox:fix/remove-unwrap-organization-uuid
Apr 29, 2026
Merged

Replace organization_uuid unwrap with proper error handling#6936
dani-garcia merged 3 commits intodani-garcia:mainfrom
xjohnyknox:fix/remove-unwrap-organization-uuid

Conversation

@xjohnyknox
Copy link
Copy Markdown
Contributor

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

The collection update endpoints (post_collections_update and
post_collections_admin) call .unwrap() on cipher.organization_uuid
in four places. If a user-owned cipher without an organization
somehow reaches these code paths, the server would panic.

Extract the organization UUID early with a descriptive error message
instead of relying on .unwrap(), preventing potential panics and
providing a clear API error response.
@BlackDex
Copy link
Copy Markdown
Collaborator

BlackDex commented Apr 4, 2026

I'm not sure if this is really needed. It doesn't add any useful from my point of view, except maybe for some more nice messages. But since this is the case for more function besides only these, I'm leaning towards closing this as it will not be that beneficial in any way. But, if @dani-garcia finds this useful it can be added of course.

@tessus
Copy link
Copy Markdown
Contributor

tessus commented Apr 4, 2026

I think not crashing the vw service is quite useful. While I don't know how likely or unlikely a panic is in this case, unwrap should never be used in production without proper handling (or extensive comments). Just my 2 cents.

P.S.: I have just recently used unwrap, but tracked down that it cannot panic unless being run on an embedded system without home dirs and/or file systems. Thus I added a comment: cannot panic (with a link to a gh issue).

@BlackDex
Copy link
Copy Markdown
Collaborator

BlackDex commented Apr 5, 2026

Well in this case it can't panic, as organization items require a collection, and there is already a check done to validate the user has access to the collections.

While I'm for trying to minimize unwrap, or even deny them at all. This pattern is located at several places which also need to change. This could be a start, but maybe more can be done.

@tessus
Copy link
Copy Markdown
Contributor

tessus commented Apr 5, 2026

Thanks for the explanation. In this case nothing further is required as you pointed out earlier. But please consider adding a comment in the source. Something like: "Cannot panic, checks done previously".

An unwrap (without proper handling) is a red flag, which can be easily dismissed with a proper comment.
I also use expect instead of unwrap. e.g. if the comment of the panic is "cannot panic - checks already done previously", then it is clear in case of a panic that the previous checks were not complete, in which case a panic might not even be a bad idea. (Although I would still prefer an error rather than the service to die.)

Copy link
Copy Markdown
Owner

@dani-garcia dani-garcia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable enough when the changes are so minimal, thanks!

@dani-garcia dani-garcia merged commit b89648a into dani-garcia:main Apr 29, 2026
9 checks passed
pieska pushed a commit to pieska/vaultwarden that referenced this pull request May 3, 2026
…cia#6936)

The collection update endpoints (post_collections_update and
post_collections_admin) call .unwrap() on cipher.organization_uuid
in four places. If a user-owned cipher without an organization
somehow reaches these code paths, the server would panic.

Extract the organization UUID early with a descriptive error message
instead of relying on .unwrap(), preventing potential panics and
providing a clear API error response.

Co-authored-by: Daniel García <dani-garcia@users.noreply.github.com>
dadezzz pushed a commit to dadezzz/infra_docker-compose that referenced this pull request May 4, 2026
…(#243)

This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [quay.io/vaultwarden/server](https://github.com/dani-garcia/vaultwarden) | minor | `1.35.8` → `1.36.0` |

---

### Release Notes

<details>
<summary>dani-garcia/vaultwarden (quay.io/vaultwarden/server)</summary>

### [`v1.36.0`](https://github.com/dani-garcia/vaultwarden/releases/tag/1.36.0)

[Compare Source](dani-garcia/vaultwarden@1.35.8...1.36.0)

#### Security Fixes

This release contains security fixes for the following advisories. We strongly advice to update as soon as possible.

- SSO Login CSRF
  [GHSA-pfp2-jhgq-6hg5](https://github.com/dani-garcia/vaultwarden/security/advisories/GHSA-pfp2-jhgq-6hg5)
  [GHSA-w6h6-8r66-hcv7](https://github.com/dani-garcia/vaultwarden/security/advisories/GHSA-w6h6-8r66-hcv7)
- User/Organization Enumeration
  [GHSA-hxqh-ff5p-wfr3](https://github.com/dani-garcia/vaultwarden/security/advisories/GHSA-hxqh-ff5p-wfr3)
- SSO existing-user binding
  [GHSA-j4j8-gpvj-7fqr](https://github.com/dani-garcia/vaultwarden/security/advisories/GHSA-j4j8-gpvj-7fqr)
  [GHSA-6x5c-84vm-5j56](https://github.com/dani-garcia/vaultwarden/security/advisories/GHSA-6x5c-84vm-5j56)
- SSRF via Icon Endpoint
  [GHSA-72vh-x5jq-m82g](https://github.com/dani-garcia/vaultwarden/security/advisories/GHSA-72vh-x5jq-m82g)
- Some crate's updated and other minor security enhancements

These are private for now, pending CVE assignment.

#### Notes

- Archiving of items is available
  <https://bitwarden.com/blog/keep-your-vault-tidy-with-item-archiving/>
  <https://bitwarden.com/nl-nl/help/managing-items/#archive>
- Web Vault updated to v2026.4.1

#### What's Changed

- SSO fallback to UserInfo preferred\_username by [@&#8203;Timshel](https://github.com/Timshel) in [#&#8203;7128](dani-garcia/vaultwarden#7128)
- Dummy identifier need to pass for a guid by [@&#8203;Timshel](https://github.com/Timshel) in [#&#8203;7154](dani-garcia/vaultwarden#7154)
- add new /identity/accounts/prelogin/password by [@&#8203;stefan0xC](https://github.com/stefan0xC) in [#&#8203;7156](dani-garcia/vaultwarden#7156)
- Add DuckDuckGo browser device type by [@&#8203;dfunkt](https://github.com/dfunkt) in [#&#8203;7147](dani-garcia/vaultwarden#7147)
- Apply `duration_suboptimal_units` lint findings by [@&#8203;dfunkt](https://github.com/dfunkt) in [#&#8203;7144](dani-garcia/vaultwarden#7144)
- Apply `ref_option` lint findings by [@&#8203;dfunkt](https://github.com/dfunkt) in [#&#8203;7143](dani-garcia/vaultwarden#7143)
- Fix hardcoded sso identifier by [@&#8203;Timshel](https://github.com/Timshel) in [#&#8203;7157](dani-garcia/vaultwarden#7157)
- Update crates and fix a nightly lint by [@&#8203;BlackDex](https://github.com/BlackDex) in [#&#8203;7161](dani-garcia/vaultwarden#7161)
- Fix Host/IP resolving by [@&#8203;BlackDex](https://github.com/BlackDex) in [#&#8203;7162](dani-garcia/vaultwarden#7162)
- Several SSO Fixes by [@&#8203;BlackDex](https://github.com/BlackDex) in [#&#8203;7163](dani-garcia/vaultwarden#7163)
- Add support for archiving items by [@&#8203;matt-aaron](https://github.com/matt-aaron) in [#&#8203;6916](dani-garcia/vaultwarden#6916)
- Fix favicon fetching to check all icon links instead of just the first one by [@&#8203;Shocker](https://github.com/Shocker) in [#&#8203;6880](dani-garcia/vaultwarden#6880)
- Fix merge conflict by [@&#8203;dani-garcia](https://github.com/dani-garcia) in [#&#8203;7164](dani-garcia/vaultwarden#7164)
- Replace organization\_uuid unwrap with proper error handling by [@&#8203;xjohnyknox](https://github.com/xjohnyknox) in [#&#8203;6936](dani-garcia/vaultwarden#6936)
- fix: return Err instead of panic on unknown cipher atype in to\_json() by [@&#8203;mango766](https://github.com/mango766) in [#&#8203;7068](dani-garcia/vaultwarden#7068)
- Allow SQLite to be linked against dynamically by [@&#8203;ISSOtm](https://github.com/ISSOtm) in [#&#8203;7057](dani-garcia/vaultwarden#7057)
- Update crates and web-vault by [@&#8203;BlackDex](https://github.com/BlackDex) in [#&#8203;7171](dani-garcia/vaultwarden#7171)
- Update hickory by [@&#8203;BlackDex](https://github.com/BlackDex) in [#&#8203;7175](dani-garcia/vaultwarden#7175)

#### New Contributors

- [@&#8203;matt-aaron](https://github.com/matt-aaron) made their first contribution in [#&#8203;6916](dani-garcia/vaultwarden#6916)
- [@&#8203;Shocker](https://github.com/Shocker) made their first contribution in [#&#8203;6880](dani-garcia/vaultwarden#6880)
- [@&#8203;xjohnyknox](https://github.com/xjohnyknox) made their first contribution in [#&#8203;6936](dani-garcia/vaultwarden#6936)
- [@&#8203;mango766](https://github.com/mango766) made their first contribution in [#&#8203;7068](dani-garcia/vaultwarden#7068)
- [@&#8203;ISSOtm](https://github.com/ISSOtm) made their first contribution in [#&#8203;7057](dani-garcia/vaultwarden#7057)

**Full Changelog**: <dani-garcia/vaultwarden@1.35.8...1.36.0>

You can discuss this release here <dani-garcia/vaultwarden#7177>

</details>

---

### Configuration

📅 **Schedule**: (UTC)

- Branch creation
  - At any time (no schedule defined)
- Automerge
  - At any time (no schedule defined)

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4xNDEuNiIsInVwZGF0ZWRJblZlciI6IjQzLjE0MS42IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119-->
birme pushed a commit to eyevinn-osaas/vaultwarden that referenced this pull request May 5, 2026
…cia#6936)

The collection update endpoints (post_collections_update and
post_collections_admin) call .unwrap() on cipher.organization_uuid
in four places. If a user-owned cipher without an organization
somehow reaches these code paths, the server would panic.

Extract the organization UUID early with a descriptive error message
instead of relying on .unwrap(), preventing potential panics and
providing a clear API error response.

Co-authored-by: Daniel García <dani-garcia@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants