Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Update favicon display in client to handle SVG (#622)

Leendert de Borstf9977fb29e7f
diff --git a/docs/misc/dev/browser-extensions.md b/docs/misc/dev/browser-extensions.md
index ef8e1eb5a..0a96d2644 100644
--- a/docs/misc/dev/browser-extensions.md
+++ b/docs/misc/dev/browser-extensions.md
@@ -56,5 +56,5 @@ The following websites have been known to cause issues in the past (but should b
| --- | --- |
| https://www.paprika-shopping.nl/nieuwsbrief/newsletter-register-landing.html | Popup CSS style conflicts |
| https://bloshing.com/inschrijven-nieuwsbrief | Popup CSS style conflicts |
-| https://gamefaqs.gamespot.com/user | Popup buttons not working |
-| https://news.ycombinator.com/login?goto=news | Popup logo not showing due to SVG format after identity creation |
\ No newline at end of file
+| https://gamefaqs.gamespot.com/user | Popup buttons not working |
+| https://news.ycombinator.com/login?goto=news | Popup and client favicon not showing due to SVG format |
diff --git a/src/AliasVault.Client/Main/Components/Credentials/DisplayFavicon.razor b/src/AliasVault.Client/Main/Components/Credentials/DisplayFavicon.razor
index a3186fc28..fe0237ede 100644
--- a/src/AliasVault.Client/Main/Components/Credentials/DisplayFavicon.razor
+++ b/src/AliasVault.Client/Main/Components/Credentials/DisplayFavicon.razor
@@ -26,6 +26,9 @@ else
[Parameter]
public bool Padding { get; set; }
+ /// <summary>
+ /// The data URL of the favicon.
+ /// </summary>
private string? _faviconDataUrl;
/// <inheritdoc />
@@ -33,8 +36,46 @@ else
{
if (FaviconBytes is not null)
{
+ string mimeType = DetectMimeType(FaviconBytes);
string base64String = Convert.ToBase64String(FaviconBytes);
- _faviconDataUrl = $"data:image/x-icon;base64,{base64String}";
+ _faviconDataUrl = $"data:{mimeType};base64,{base64String}";
+ }
+ }
+
+ /// <summary>
+ /// Detect the mime type of the favicon.
+ /// </summary>
+ /// <param name="bytes">The bytes of the favicon.</param>
+ /// <returns>The mime type of the favicon.</returns>
+ private string DetectMimeType(byte[] bytes)
+ {
+ // Check for SVG.
+ if (bytes.Length >= 5)
+ {
+ string header = System.Text.Encoding.ASCII.GetString(bytes.Take(5).ToArray()).ToLower();
+ if (header.Contains("<?xml") || header.Contains("<svg"))
+ {
+ return "image/svg+xml";
+ }
+ }
+
+ // Check for ICO.
+ if (bytes.Length >= 4 &&
+ bytes[0] == 0x00 && bytes[1] == 0x00 &&
+ bytes[2] == 0x01 && bytes[3] == 0x00)
+ {
+ return "image/x-icon";
}
+
+ // Check for PNG.
+ if (bytes.Length >= 4 &&
+ bytes[0] == 0x89 && bytes[1] == 0x50 &&
+ bytes[2] == 0x4E && bytes[3] == 0x47)
+ {
+ return "image/png";
+ }
+
+ // Default to x-icon if unknown.
+ return "image/x-icon";
}
}