Browse Source

Align My Items rules and vault purge with Bitwarden

pull/7776/head
tom27052006 10 hours ago
parent
commit
d80b9a3f2f
  1. 3
      .env.template
  2. 8
      src/api/core/ciphers.rs
  3. 38
      src/api/core/organizations.rs
  4. 6
      src/db/models/cipher.rs

3
.env.template

@ -406,7 +406,8 @@
## - "pm-30529-webauthn-related-origins": Allow passkeys stored in the vault to be used on related origins listed in a site's /.well-known/webauthn file (Browser >= 2026.2.0) ## - "pm-30529-webauthn-related-origins": Allow passkeys stored in the vault to be used on related origins listed in a site's /.well-known/webauthn file (Browser >= 2026.2.0)
## - "pm-32009-new-item-types": Enable new item types: Bank Account, Driver's License, and Passport (Clients >= 2026.4.0) ## - "pm-32009-new-item-types": Enable new item types: Bank Account, Driver's License, and Passport (Clients >= 2026.4.0)
## - "pm-34171-card-scanner": Enable the new card scanner feature on mobile (Android >= 2026.4.1, iOS >= 2026.4.1) ## - "pm-34171-card-scanner": Enable the new card scanner feature on mobile (Android >= 2026.4.1, iOS >= 2026.4.1)
## - "pm-20558-migrate-myvault-to-myitems": On mobile, ask members that the organization data ownership policy applies to, and that still have personal items, to transfer them to their My Items or to leave the organization (Android, iOS) ## - "pm-20558-migrate-myvault-to-myitems": On mobile, ask members that the organization data ownership policy applies to, and that still have personal items, to transfer them to their My Items or to leave the organization (Android 2026.1.0 - 2026.11.0, iOS 2026.1.1 - 2026.10.1)
## Newer mobile versions no longer read this flag and always ask.
## - "enable-basic-auth-response": Enable HTTP Basic Auth autofill in the browser extension (Browser >= 2026.9.0) ## - "enable-basic-auth-response": Enable HTTP Basic Auth autofill in the browser extension (Browser >= 2026.9.0)
## - "undetermined-cipher-scenario-logic": Enable the rewritten add/update login notification triggering logic in the browser extension (Browser >= 2026.2.0) ## - "undetermined-cipher-scenario-logic": Enable the rewritten add/update login notification triggering logic in the browser extension (Browser >= 2026.2.0)
## - "biometrics-sdk-ipc": Enable biometric unlock over the SDK IPC framework (Desktop >= 2026.9.0, Browser >= 2026.9.0) ## - "biometrics-sdk-ipc": Enable biometric unlock over the SDK IPC framework (Desktop >= 2026.9.0, Browser >= 2026.9.0)

8
src/api/core/ciphers.rs

@ -1228,6 +1228,14 @@ async fn update_collections_by_scope(
let Some(org_uuid) = cipher.organization_uuid.clone() else { let Some(org_uuid) = cipher.organization_uuid.clone() else {
err!("Cipher is not owned by an organization") err!("Cipher is not owned by an organization")
}; };
// Like upstream's `SaveCollectionsAsync`, on both routes: another member's personal cipher, one that is
// only in their My Items collection, may not be shared, even by an admin
if CollectionCipher::find_my_items_owners_if_only(&cipher.uuid, &conn)
.await
.is_some_and(|owners| owners.iter().any(|owner| owner != &headers.user.uuid))
{
err_code!("Resource not found", "Cannot share another member's My Items", Status::NotFound.code)
}
let posted = HashSet::<CollectionId>::from_iter(data.collection_ids); let posted = HashSet::<CollectionId>::from_iter(data.collection_ids);
let current = HashSet::<CollectionId>::from_iter(match scope { let current = HashSet::<CollectionId>::from_iter(match scope {
CipherAccessScope::User => cipher.get_collections(headers.user.uuid.clone(), &conn).await, CipherAccessScope::User => cipher.get_collections(headers.user.uuid.clone(), &conn).await,

38
src/api/core/organizations.rs

@ -1854,10 +1854,21 @@ async fn edit_member(
} }
} }
// Like upstream, the posted access leaves out My Items collections, before it is authorized: they are no member's
// to give. The member keeps their own one, see below.
let org_collections: HashMap<CollectionId, Collection> =
Collection::find_by_organization(&org_id, &conn).await.into_iter().map(|c| (c.uuid.clone(), c)).collect();
let posted_collections: Vec<&CollectionData> = data
.collections
.iter()
.flatten()
.filter(|col| !org_collections.get(&col.id).is_some_and(Collection::is_default_user_collection))
.collect();
// A Custom member with Manage users only gives what they have themselves. Manage users authorizes member access // A Custom member with Manage users only gives what they have themselves. Manage users authorizes member access
// to every collection in this organization. // to every collection in this organization.
if headers.membership_type == MembershipType::Custom { if headers.membership_type == MembershipType::Custom {
let collections: Vec<&CollectionId> = data.collections.iter().flatten().map(|c| &c.id).collect(); let collections: Vec<&CollectionId> = posted_collections.iter().map(|c| &c.id).collect();
let groups = data.groups.iter().flatten().cloned().collect(); let groups = data.groups.iter().flatten().cloned().collect();
check_custom_member_grants( check_custom_member_grants(
&headers.membership, &headers.membership,
@ -1881,25 +1892,12 @@ async fn edit_member(
// We need to perform the check after changing the type since `admin` is exempt. // We need to perform the check after changing the type since `admin` is exempt.
OrgPolicy::check_user_allowed(&member_to_edit, "modify", &conn).await?; OrgPolicy::check_user_allowed(&member_to_edit, "modify", &conn).await?;
// Like upstream, reject a My Items collection before changing anything
let org_collections: HashMap<CollectionId, Collection> =
Collection::find_by_organization(&org_id, &conn).await.into_iter().map(|c| (c.uuid.clone(), c)).collect();
if !access_all
&& data
.collections
.iter()
.flatten()
.any(|col| org_collections.get(&col.id).is_some_and(Collection::is_default_user_collection))
{
err!("Default collections cannot be assigned to a member.")
}
// Delete all the odd collections, but keep the member's My Items // Delete all the odd collections, but keep the member's My Items
CollectionUser::delete_all_but_my_items_by_user_and_org(&member_to_edit.user_uuid, &org_id, &conn).await?; CollectionUser::delete_all_but_my_items_by_user_and_org(&member_to_edit.user_uuid, &org_id, &conn).await?;
// If no accessAll, add the collections received // If no accessAll, add the collections received
if !access_all { if !access_all {
for col in data.collections.iter().flatten() { for col in posted_collections {
match org_collections.get(&col.id) { match org_collections.get(&col.id) {
None => err!("Collection not found in Organization"), None => err!("Collection not found in Organization"),
Some(collection) => { Some(collection) => {
@ -2171,12 +2169,10 @@ async fn validate_org_import_collections(
}; };
for col in imported { for col in imported {
if let Some(collection) = col.id.as_ref().and_then(|id| existing.get(id)) { if let Some(collection) = col.id.as_ref().and_then(|id| existing.get(id)) {
if collection.is_default_user_collection() { // Like upstream's `ImportCiphers` authorization, also for a My Items collection: Owners, Admins and
// Only its owner can import into a My Items collection, whatever else the member may do // members who may edit any collection may import into it, others only into one they may manage or
if collection.default_user_uuid.as_ref() != Some(&membership.user_uuid) { // write to, which for a My Items collection is only its owner
err!(Compact, "The current user isn't allowed to manage this collection") if membership.atype < MembershipType::Admin && !membership.can_edit_any_collection() {
}
} else if membership.atype < MembershipType::Admin && !membership.can_edit_any_collection() {
let can_import = if let Some(manageable) = &manageable { let can_import = if let Some(manageable) = &manageable {
manageable.contains(&collection.uuid) manageable.contains(&collection.uuid)
} else { } else {

6
src/db/models/cipher.rs

@ -630,8 +630,10 @@ impl Cipher {
} }
/// Purges the organization vault like upstream's `Cipher_DeleteByOrganizationId`: the items stored in a /// Purges the organization vault like upstream's `Cipher_DeleteByOrganizationId`: the items stored in a
/// member's My Items collection are kept, they are only removed from the shared collections. /// member's My Items collection are kept, they are only removed from the shared collections. In one transaction
/// like there; as there, the attachment files are removed along with their items.
pub async fn purge_organization(org_uuid: &OrganizationId, conn: &DbConn) -> EmptyResult { pub async fn purge_organization(org_uuid: &OrganizationId, conn: &DbConn) -> EmptyResult {
conn.transaction(async || {
let my_items = CollectionCipher::find_my_items_by_org(org_uuid, conn).await; let my_items = CollectionCipher::find_my_items_by_org(org_uuid, conn).await;
for cipher in Self::find_by_org(org_uuid, conn).await { for cipher in Self::find_by_org(org_uuid, conn).await {
if !my_items.contains_key(&cipher.uuid) { if !my_items.contains_key(&cipher.uuid) {
@ -645,6 +647,8 @@ impl Cipher {
User::update_uuid_revisions(members.into_iter().map(|m| m.user_uuid).collect(), conn).await; User::update_uuid_revisions(members.into_iter().map(|m| m.user_uuid).collect(), conn).await;
} }
Ok(()) Ok(())
})
.await
} }
pub async fn delete_all_by_user(user_uuid: &UserId, conn: &DbConn) -> EmptyResult { pub async fn delete_all_by_user(user_uuid: &UserId, conn: &DbConn) -> EmptyResult {

Loading…
Cancel
Save