mirror of
https://github.com/dani-garcia/vaultwarden.git
synced 2026-07-15 10:02:09 -05:00
[GH-ISSUE #7009] User account key rotation is not atomic #30082
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @0x484558 on GitHub (Mar 24, 2026).
Original GitHub issue: https://github.com/dani-garcia/vaultwarden/issues/7009
(most of bug report form is irrelevant)
POST /accounts/key-management/rotate-user-account-keyscurrently performs a long sequence of database operations without a DB transaction and returns early on error. This allows partial commits across account data categories which can leave account state inconsistent. The endpoint is intended as all-or-nothing key rotation operation, and partial success means some encrypted payloads/key metadata are updated while others are not.If my understanding of the code is correct, it is possible to run into an exact failure like this:
send.deletionDateto an invalid (bear with me here) far-future value (e.g. now + 31 days);Rotate request will fail with 400, folder update will be committed anyway but user key material will not get updated, and send will remain unchanged.
This exact example relies on an invalid request as a precondition, which of course not something clients would normally do, but it is just one way to trigger all sorts of unpredictable consequences from user account keys rotation code path. Transient database errors and process interruptions also happen. The real issue here is lack of defensive programming.
I'm submitting this as an issue because unfortunately, it appears architecturally to be slightly non-trivial to fix.
@BlackDex commented on GitHub (Mar 24, 2026):
I'm not sure if we need to keep this as an issue, we already know about this as there is a ToDo line regarding this exact item
235cf88231/src/api/core/accounts.rs (L810)It would more be an enhancement. And this call site isn't the only location which could benefit from running within a transaction, like purging the vault, import, and probably a few more.