bitwarden / bitwarden/server

Icon Cache Invalidated By Change Password URL Cache?

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

Description

### Steps To Reproduce

1. Self-host Bitwarden
2. Add a new item with a Website URL with valid favicon
3. Reload the Bitwarden client, eventually the icon disappears

### Expected Result

Valid icons stay correctly cached so they show up correctly in the client.

### Actual Result

Icons randomly disappear off some items.

### Screenshots or Videos

_No response_

### Additional Context

I tried to track down why this is occurring, and I can't say for sure, but I think it is to do with a shared Memory Cache between the IconController and ChangePasswordUriController in the Icons server component.

In [server/src/Icons/Startup.cs](https://github.com/bitwarden/server/blob/8bd4af7a382c6a242dbae002110bcab0773c6066/src/Icons/Startup.cs#L43-L46)

```
// Cache
services.AddMemoryCache(options =>
{
options.SizeLimit = iconsSettings.CacheSizeLimit;
});
services.AddMemoryCache(options =>
{
options.SizeLimit = changePasswordUriSettings.CacheSizeLimit;
});
```

AddMemoryCache is called twice, but I'm not sure that calling this twice actually adds a separate memory cache to each controller instance. I'm not even sure iconsSettings.CacheSizeLimit ever gets used, as I think it is overwritten by the changePasswordUriSettings.CacheSizeLimit

Both the ChangePasswordUriController and IconsController use the same key (the domain) to cache values for the result. I am pretty sure that IconsController caches an icon successfully, then the ChangePasswordUriController runs, gets a null result and caches that null result.....overwriting the icon.

I created a patched version that uses a unique key in each controller, when accessing the MemoryCache, and the issue seems resolved.

e.g.
```
var mappedDomain = "Icon-" + _domainMappingService.MapDomain(domain);
var mappedDomain = "ChangedPasswordUri-" + _domainMappingService.MapDomain(domain);
```

### Build Version

2026.4.2

### Environment

Self-Hosted

### Environment Details

- Ubuntu 26.04 with podman

### 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 by reading server/src/Icons/Startup.cs and the IconsController and ChangePasswordUriController cache access described in the issue. Verify whether the two AddMemoryCache registrations share a cache and whether both controllers use the domain as a key. Done means icon entries remain available after reload without being replaced by change-password URI results.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.