mirror of
https://github.com/dani-garcia/vaultwarden.wiki.git
synced 2026-11-23 02:49:38 +02:00
Return an error instead of panicking on invalid attachment/cipher input (#7989)
Several handlers pass request-controlled values to the database and .expect() the result, so a value the database rejects (for example a string containing a NUL byte, which PostgreSQL refuses in text columns) turns a normal error into a panic: - POST /api/ciphers/<cipher_id>/attachment/v2 with a NUL byte in the attachment key or file name - POST/PUT /api/ciphers/move with a NUL byte in an ids entry (IDs from a JSON body are not validated the way UuidFromParam validates path params) On the default unwinding builds Rocket catches this and returns 500; on builds compiled with panic=abort it terminates the process. Any authenticated user can trigger it, including on their own cipher. Make the attachment saves propagate the error (the enclosing functions already return Result), and validate the move handler's cipher IDs up front, so both return a normal error response instead of panicking. Co-authored-by: Voucher Security <security@vouchersecurity.com>
This commit is contained in:
1 parent
baff1cabae
commit
2c9b7c06a9
1 file changed
+13
-3
+13
-3
@@ -1697,7 +1697,7 @@ async fn post_attachment_v2(
|
||||
let attachment_id = crypto::generate_attachment_id();
|
||||
let attachment =
|
||||
Attachment::new(attachment_id.clone(), cipher.uuid.clone(), data.file_name, file_size, Some(data.key));
|
||||
attachment.save(&conn).await.expect("Error saving attachment");
|
||||
attachment.save(&conn).await?;
|
||||
notify_attachment_created(&cipher, &headers, &conn, &nt).await;
|
||||
|
||||
let url = format!("/ciphers/{}/attachment/{attachment_id}", cipher.uuid);
|
||||
@@ -1791,7 +1791,7 @@ async fn save_attachment(
|
||||
if size != attachment.file_size {
|
||||
// Update the attachment with the actual file size.
|
||||
attachment.file_size = size;
|
||||
attachment.save(&conn).await.expect("Error updating attachment");
|
||||
attachment.save(&conn).await?;
|
||||
}
|
||||
} else {
|
||||
attachment.delete(&conn).await.ok();
|
||||
@@ -1813,7 +1813,7 @@ async fn save_attachment(
|
||||
}
|
||||
let attachment =
|
||||
Attachment::new(file_id.clone(), cipher_id.clone(), encrypted_filename.unwrap(), size, data.key);
|
||||
attachment.save(&conn).await.expect("Error saving attachment");
|
||||
attachment.save(&conn).await?;
|
||||
}
|
||||
|
||||
save_temp_file(&PathType::Attachments, &format!("{cipher_id}/{file_id}"), data.data, true).await?;
|
||||
@@ -2205,6 +2205,16 @@ async fn move_cipher_selected(
|
||||
let data = data.into_inner();
|
||||
let user_id = &headers.user.uuid;
|
||||
|
||||
// Validate the cipher IDs are well-formed before they reach the query.
|
||||
// Unlike path parameters (UuidFromParam), IDs deserialized from a JSON body
|
||||
// are not checked, so a malformed value (e.g. one containing a NUL byte)
|
||||
// would otherwise reach the database and error out.
|
||||
for cipher_id in &data.ids {
|
||||
if uuid::Uuid::parse_str(cipher_id.as_ref()).is_err() {
|
||||
err!("Invalid cipher ID provided")
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(ref folder_id) = data.folder_id
|
||||
&& Folder::find_by_uuid_and_user(folder_id, user_id, &conn).await.is_none()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user