GHSA-q5x6-grh5-fqgc: Unbounded client-declared attachment fileSize causes an out-of-bounds panic that permanently breaks vault sync for every user who can see the cipher
- Published:
- Fetched:
- Updated:
- Affects:
- dani-garcia vaultwarden
https://github.com/dani-garcia/vaultwarden/security/advisories/GHSA-q5x6-grh5-fqgc ↗
Unbounded client-declared attachment fileSize causes an out-of-bounds panic that permanently breaks vault sync for every user who can see the cipher ### Summary `POST /api/ciphers/{id}/attachment/v2` accepts a client-declared `fileSize` and validates only that it is not negative. A value above `1024^6` (~1.15e18, well within `i64`) makes `get_display_size()` index a fixed 6-element array out of bounds and panic. The attachment row is committed to the database **before** the panic, and the operation is not wrapped in a transaction, so the poisoned row persists. Afterwards every endpoint that serialises that cipher — `GET /api/sync`, `GET /api/ciphers`, `GET /api/ciphers/{id}` — panics and returns `500` **permanently**. No file is ever uploaded; the request body is a few hundred bytes. If the poisoned cipher is shared with an organization collection, **every member who can see it — including owners and admins — permanently loses vault sync**. That is a cross-user denial of service triggered by an ordinary member with edit rights. Confirmed at runtime against a stock `vaultwarden/server:1.37.1` container. ### Details `src/util.rs:334` — `get_display_size()`: ```rust pub fn get_display_size(size: i64) -> String { const UNITS: [&str; 6] = ["bytes", "KB", "MB", "GB", "TB", "PB"]; // valid indices 0..=5 ... let mut unit_counter = 0; loop { if size > 1024. { size /= 1024.; unit_counter += 1; } else { break; } } format!("{size:.2} {}", UNITS[unit_counter]) // src/util.rs:353 — unchecked index } ``` Any value that survives six divisions by 1024 yields `unit_counter == 6` and panics at `src/util.rs:353` (`core::panicking::panic_bounds_check`). `src/api/core/ciphers.rs` — the v2 attachment endpoint (guard: plain `Headers`, i.e. any logged-in user): ```rust let file_size = data.file_size.into_i64()?; // src/api/core/ciphers.rs:1150 if file_size < 0 { ... } // :1152 — only a lower bound is checked ... Attachment::new(attachment_id, cipher.uuid, data.file_name, file_size, Some(data.key)); // :1157 — persisted ``` `file_size` is a `NumberOrString`, so the full `i64` range is accepted. The storage-quota checks live in the separate upload step, which the attacker simply never performs. The row is saved at `:1157`; the panic then occurs while building the response, so the write is never rolled back. `Attachment::to_json` (`src/db/models/attachment.rs:74`) calls `get_display_size(self.file_size)`, and is reached from `Cipher::to_json`, which backs `/api/sync`, `/api/ciphers` and `/api/ciphers/{id}`. Because every listing endpoint panics, the victim cannot discover the attachment id through the API in order to delete it — recovery requires direct database access. ### PoC Verified against a clean `vaultwarden/server:1.37.1` instance: ``` docker run -d --name vw -p 127.0.0.1:8089:80 -e SIGNUPS_ALLOWED=true vaultwarden/server:1.37.1 ``` **Variant 1 — single account:** ``` GET /api/sync -> 200 (baseline) POST /a Affected packages: rust:vaultwarden Patched: vaultwarden 1.37.4