api::core::ciphers::put_cipher_share_selected does not use cipher_ids #1343

Closed
opened 2026-04-06 01:48:36 +02:00 by MrUnknownDE · 0 comments
Owner

Originally created by @zacknewman on 11/26/2023

This may not be a bug, but it could be if cipher_ids is actually important. Anyway, cipher_ids in api::core::ciphers::put_cipher_share_selected is never read from. Is this accidental? What's the point of pushing IDs into it without ever reading the IDs?

Possible fix if that variable is unimportant:

#[put("/ciphers/share", data = "<data>")]
async fn put_cipher_share_selected(
    data: JsonUpcase<ShareSelectedCipherData>,
    headers: Headers,
    mut conn: DbConn,
    nt: Notify<'_>,
) -> EmptyResult {
    let mut data: ShareSelectedCipherData = data.into_inner().data;

    if data.Ciphers.is_empty() {
        err!("You must select at least one cipher.")
    }

    if data.CollectionIds.is_empty() {
        err!("You must select at least one collection.")
    }

    for cipher in data.Ciphers.iter() {
        if cipher.Id.is_none() {
            err!("Request missing ids field");
        }
    }

    while let Some(cipher) = data.Ciphers.pop() {
        let mut shared_cipher_data = ShareCipherData {
            Cipher: cipher,
            CollectionIds: data.CollectionIds.clone(),
        };

        match shared_cipher_data.Cipher.Id.take() {
            Some(id) => share_cipher_by_uuid(&id, shared_cipher_data, &headers, &mut conn, &nt).await?,
            None => err!("Request missing ids field"),
        };
    }
    Ok(())
}
*Originally created by @zacknewman on 11/26/2023* This may not be a bug, but it could be if `cipher_ids` is actually important. Anyway, `cipher_ids` in [`api::core::ciphers::put_cipher_share_selected`](https://github.com/dani-garcia/vaultwarden/blob/main/src/api/core/ciphers.rs#L852) is never read from. Is this accidental? What's the point of `push`ing IDs into it without ever reading the IDs? Possible fix if that variable is unimportant: ```rust #[put("/ciphers/share", data = "<data>")] async fn put_cipher_share_selected( data: JsonUpcase<ShareSelectedCipherData>, headers: Headers, mut conn: DbConn, nt: Notify<'_>, ) -> EmptyResult { let mut data: ShareSelectedCipherData = data.into_inner().data; if data.Ciphers.is_empty() { err!("You must select at least one cipher.") } if data.CollectionIds.is_empty() { err!("You must select at least one collection.") } for cipher in data.Ciphers.iter() { if cipher.Id.is_none() { err!("Request missing ids field"); } } while let Some(cipher) = data.Ciphers.pop() { let mut shared_cipher_data = ShareCipherData { Cipher: cipher, CollectionIds: data.CollectionIds.clone(), }; match shared_cipher_data.Cipher.Id.take() { Some(id) => share_cipher_by_uuid(&id, shared_cipher_data, &headers, &mut conn, &nt).await?, None => err!("Request missing ids field"), }; } Ok(()) } ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/vaultwarden#1343