Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Update FaviconController to log failed favicon extraction as information instead of warning (#383)
Leendert de Borstcc4a2e087fd4
diff --git a/src/AliasVault.Api/Controllers/FaviconController.cs b/src/AliasVault.Api/Controllers/FaviconController.csindex 8bbb68953..516c1d93c 100644--- a/src/AliasVault.Api/Controllers/FaviconController.cs+++ b/src/AliasVault.Api/Controllers/FaviconController.cs@@ -18,8 +18,9 @@ using Microsoft.AspNetCore.Mvc;/// Controller for retrieving favicons from external websites./// </summary>/// <param name="userManager">UserManager instance.</param>+/// <param name="logger">Logger instance.</param>[ApiVersion("1")]-public class FaviconController(UserManager<AliasVaultUser> userManager) : AuthenticatedRequestController(userManager)+public class FaviconController(UserManager<AliasVaultUser> userManager, ILogger<FaviconController> logger) : AuthenticatedRequestController(userManager){/// <summary>/// Proxies the request to the identity generator to generate a random identity.@@ -36,9 +37,22 @@ public class FaviconController(UserManager<AliasVaultUser> userManager) : Authen}// Get the favicon from the URL.- var image = await FaviconExtractor.FaviconExtractor.GetFaviconAsync(url);+ try+ {+ var image = await FaviconExtractor.FaviconExtractor.GetFaviconAsync(url);++ // Return the favicon as base64 string of image representation.+ return Ok(new FaviconExtractModel { Image = image });+ }+ catch (Exception ex)+ {+ // Anonymize the URL by replacing all a-Z characters with 'x' before logging.+ // This will still allow to see the host structure but not the actual domain.+ var anonymizedUrl = new string(url.Select(c => char.IsLetter(c) ? 'x' : c).ToArray());+ logger.LogInformation(ex, "Failed to extract favicon from {Url}", anonymizedUrl);+ }- // Return the favicon as base64 string of image representation.- return Ok(new FaviconExtractModel { Image = image });+ // Return null if favicon extraction failed.+ return Ok(new FaviconExtractModel { Image = null });}}