Skip to content

[PM-33500] - delete attachments from deleted ciphers#7208

Open
jaasen-livefront wants to merge 1 commit intomainfrom
PM-33500
Open

[PM-33500] - delete attachments from deleted ciphers#7208
jaasen-livefront wants to merge 1 commit intomainfrom
PM-33500

Conversation

@jaasen-livefront
Copy link
Collaborator

🎟️ Tracking

https://bitwarden.atlassian.net/browse/PM-33500

📔 Objective

Fix orphaned attachment files left behind when ciphers are deleted in bulk, an organization vault is purged, or an organization is deleted.

When a single cipher is deleted via CipherService.DeleteAsync, attachment files are properly removed from blob/disk storage via DeleteAttachmentsForCipherAsync. However, three other deletion paths only removed DB records, leaving attachment files permanently orphaned in storage:

  1. CipherService.DeleteManyAsync (bulk cipher delete) — deleted cipher rows but never cleaned up attachment storage.
  2. CipherService.PurgeAsync (org vault purge) — deleted cipher rows but never cleaned up attachment storage.
  3. OrganizationDeleteCommand.DeleteAsync (org deletion) — cascade-deleted cipher rows via SQL stored proc but never cleaned up attachment storage.

Changes

  • CipherService.DeleteManyAsync: After DB deletion, iterate deleted ciphers and call DeleteAttachmentsForCipherAsync for each.
  • CipherService.PurgeAsync: Fetch org cipher IDs before DB deletion, then clean up each cipher's attachments after.
  • OrganizationDeleteCommand.DeleteAsync: Inject ICipherRepository and IAttachmentStorageService. Fetch org cipher IDs before DB cascade delete, then clean up each cipher's attachments after.
  • Updated unit tests for DeleteManyAsync (org admin + personal owner paths) and OrganizationDeleteCommand.Delete_Success to assert attachment cleanup. Added new PurgeAsync_WithOrganizationId_DeletesCiphersAndAttachments test.

📸 Screenshots

@sonarqubecloud
Copy link

@github-actions
Copy link
Contributor

Logo
Checkmarx One – Scan Summary & Detailsdd616c24-57ab-4f53-ba42-d5b485b10e43

Great job! No new security vulnerabilities introduced in this pull request

@codecov
Copy link

codecov bot commented Mar 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 57.46%. Comparing base (8688cfc) to head (fe0f808).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7208      +/-   ##
==========================================
+ Coverage   57.44%   57.46%   +0.01%     
==========================================
  Files        2032     2032              
  Lines       89410    89428      +18     
  Branches     7951     7954       +3     
==========================================
+ Hits        51366    51388      +22     
+ Misses      36201    36196       -5     
- Partials     1843     1844       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants