bitwarden / bitwarden/server

Unable to upload attachments due to InvalidCastException

Open
#7,062 2 comments 0 reactions 0 assignees View on GitHub
bug bw-lite-deploy
Dominant language
C#
Stars
20.1k
Forks
1.8k
Avg merge
4d 8h
Merged PRs (30d)
75

Description

### Steps To Reproduce

1. Add new `Login` entry and save it (or open existing one)
2. Edit entry to upload new attachment
3. Select file and click on `Upload`

### Expected Result

File is uploaded successfully and stored.

### Actual Result

The upload fails with a 500 error:
```json
{"message":"An unhandled server error has occurred.","validationErrors":null,"exceptionMessage":null,"exceptionStackTrace":null,"innerExceptionMessage":null,"object":"error"}
```

In the api logs on the server, I can see this error message:
```
2026-02-24T08:36:04.4202136+00:00 0HNJJFTGM9AJI:00000001 [ERR] Unhandled exception (f80f533c)
System.InvalidCastException: Unable to cast object of type 'Bit.Core.Vault.Models.Data.CipherOrganizationDetails' to type 'Bit.Core.Vault.Models.Data.CipherDetails'.
at Bit.Core.Vault.Services.CipherService.CreateAttachmentForDelayedUploadAsync(Cipher cipher, String key, String fileName, Int64 fileSize, Boolean adminRequest, Guid savingUserId, Nullable`1 lastKnownRevisionDate) in /source/src/Core/Vault/Services/Implementations/CipherService.cs:line 236
at Bit.Api.Vault.Controllers.CiphersController.PostAttachment(Guid id, AttachmentRequestModel request) in /source/src/Api/Vault/Controllers/CiphersController.cs:line 1364
at lambda_method1871(Closure, Object)
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(ActionContext actionContext, IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Logged|12_1(ControllerActionInvoker invoker)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|26_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
```

### Screenshots or Videos

_No response_

### Additional Context

Bitwarden was running on self-hosted unified version 2025.7.2-beta for long time and without issues, until this error started happening. It was first seen last week, without any changes to the deployment or infrastructure. Now it blocks all uploads consistently, no new uploads are possible.
I tried to update to latest lite version 2026.2.0 to see if it fixes the issue, but it still remains. The logs/stacktrace are from latest version.

### Githash Version

56b85d4b

### Environment Details

Running in AWS ECS Fargate with RDS Aurora Postgres 16 cluster and EFS volume.

### Database Image

_No response_

### Issue Tracking Info

- [x] I understand that work is tracked outside of Github. A PR will be linked to this issue should one be opened to address it, but Bitwarden doesn't use fields like "assigned", "milestone", or "project" to track progress.

Contributor guide

Open the contributing guide

Research direction

Start in src/Core/Vault/Services/Implementations/CipherService.cs at line 236, then trace the attachment request from PostAttachment in src/Api/Vault/Controllers/CiphersController.cs at line 1364. Reproduce the upload failure with a Login entry and add regression coverage for the affected path. Done means attachments upload successfully without the InvalidCastException.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.