GHSA-v576-3wvq-xh3c: Loop-carried user_created flag in send_invite deletes a pre-existing user's account and entire vault when an invite e-mail fails
- Published:
- Fetched:
- Updated:
- Affects:
- dani-garcia vaultwarden
https://github.com/dani-garcia/vaultwarden/security/advisories/GHSA-v576-3wvq-xh3c ↗
Loop-carried user_created flag in send_invite deletes a pre-existing user's account and entire vault when an invite e-mail fails ### Summary In `send_invite`, the `user_created` flag is declared **outside** the per-e-mail loop and is never reset. Once any iteration creates a shell account for a new address, the flag stays `true` for every later iteration. If a later iteration resolves to a **pre-existing account** and that invite e-mail fails to send, the error handler takes the `user_created` branch and calls `user.delete()` on **that pre-existing user** — destroying their entire account: all ciphers, folders, attachments, Sends, devices, 2FA registrations, emergency-access grants and organization memberships. There is no transaction, so the deletion persists even though the request returns `500`/`400`. An authenticated attacker can trigger this deliberately (organization creation is open by default, so any registered user can become an Owner of their own organization and invite arbitrary addresses). It also fires **accidentally**: an administrator inviting `[new user, existing user]` whose second message is rejected by the mail relay — greylisting, rate limiting, a full mailbox, a size limit — silently destroys the existing user's vault. Verified end-to-end against a stock `vaultwarden/server:1.37.1` container. ### Details `src/api/core/organizations.rs`: ```rust let mut user_created: bool = false; // :1078 — OUTSIDE the loop for email in &data.emails { // :1079 let user = match User::find_by_mail(email, &conn).await { None => { // address has no account ... let mut new_user = User::new(email, None); new_user.save(&conn).await?; user_created = true; // :1097 — set, never reset new_user } Some(user) => { // :1100 — a PRE-EXISTING account if Membership::find_by_user_and_org(...).is_some() { err!(format!("User already in organization: {email}")) } ... user } }; ... if CONFIG.mail_enabled() { ... if let Err(e) = mail::send_invite(&user, ...).await { // Upon error delete the user, invite and org member records when needed if user_created { // :1140 — still true from an earlier iteration user.delete(&conn).await?; // :1141 — deletes THIS iteration's user } else { new_member.delete(&conn).await?; // the correct action } err!(format!("Error sending invite: {e:?} ")); } } ``` The intent of `:1140-1144` is clearly "if I just created this shell account, roll it back; otherwise only remove the membership". Because the flag is loop-carried rather than per-iteration, the rollback is applied to a user the handler did **not** create. `User::de Affected packages: rust:vaultwarden Patched: vaultwarden 1.37.4