Skip to content

[PM-33152] Fix: InvalidCastException on attachment upload as admin#7148

Open
boris324 wants to merge 1 commit intobitwarden:mainfrom
boris324:fix/attachment-upload-invalid-cast
Open

[PM-33152] Fix: InvalidCastException on attachment upload as admin#7148
boris324 wants to merge 1 commit intobitwarden:mainfrom
boris324:fix/attachment-upload-invalid-cast

Conversation

@boris324
Copy link

@boris324 boris324 commented Mar 4, 2026

Summary

  • Fixes Unable to upload attachments due to InvalidCastException #7062
  • CipherOrganizationDetails cannot be cast to CipherDetails when admin uploads attachments
  • Added type check with fallback to base ReplaceAsync(Cipher) in two locations:
    • CreateAttachmentForDelayedUploadAsync (line ~236)
    • CreateAttachmentAsync (line ~290)
  • Matches existing pattern already used in DeleteAttachmentAsync (line ~897)

Test plan

  • Upload attachment as org admin → should succeed (was 500 error)
  • Upload attachment as regular user → should still work as before
  • Delete attachment as admin → should still work (unchanged)

When AdminRequest is true, CiphersController fetches the cipher via
GetOrganizationDetailsByIdAsync() which returns CipherOrganizationDetails.
The hard cast to CipherDetails in CreateAttachmentForDelayedUploadAsync
and CreateAttachmentAsync throws InvalidCastException.

Use type checking with fallback to base ReplaceAsync(Cipher), matching
the existing pattern already used in DeleteAttachmentAsync.

Resolves bitwarden#7062
@boris324 boris324 requested a review from a team as a code owner March 4, 2026 20:59
@boris324 boris324 requested a review from nick-livefront March 4, 2026 20:59
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

1 similar comment
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@bitwarden-bot
Copy link

Thank you for your contribution! We've added this to our internal tracking system for review.
ID: PM-33152
Link: https://bitwarden.atlassian.net/browse/PM-33152

Details on our contribution process can be found here: https://contributing.bitwarden.com/contributing/pull-requests/community-pr-process.

@bitwarden-bot bitwarden-bot changed the title Fix: InvalidCastException on attachment upload as admin [PM-33152] Fix: InvalidCastException on attachment upload as admin Mar 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to upload attachments due to InvalidCastException

3 participants