mirror of
https://github.com/bitwarden/server.git
synced 2024-11-26 12:55:17 +01:00
dont try to fetch ip address icons
This commit is contained in:
parent
f74dfb5fbb
commit
7fd79388e2
@ -69,7 +69,7 @@ namespace Bit.Icons.Controllers
|
||||
// Only cache not found and smaller images (<= 50kb)
|
||||
if(_iconsSettings.CacheEnabled && (icon == null || icon.Image.Length <= 50012))
|
||||
{
|
||||
_logger.LogWarning("Cache the icon for {0}.", domain);
|
||||
_logger.LogInformation("Cache icon for {0}.", domain);
|
||||
_memoryCache.Set(mappedDomain, icon, new MemoryCacheEntryOptions
|
||||
{
|
||||
AbsoluteExpirationRelativeToNow = new TimeSpan(_iconsSettings.CacheHours, 0, 0),
|
||||
|
@ -8,6 +8,7 @@ using System.Threading.Tasks;
|
||||
using Bit.Icons.Models;
|
||||
using AngleSharp.Parser.Html;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Bit.Icons.Services
|
||||
{
|
||||
@ -31,10 +32,16 @@ namespace Bit.Icons.Services
|
||||
private readonly HashSet<string> _allowedMediaTypes;
|
||||
private readonly HttpClient _httpClient;
|
||||
private readonly ILogger<IIconFetchingService> _logger;
|
||||
private readonly Regex _ipRegex;
|
||||
|
||||
public IconFetchingService(ILogger<IIconFetchingService> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
_ipRegex = new Regex("^" +
|
||||
"(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\." +
|
||||
"(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\." +
|
||||
"(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\." +
|
||||
"(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$");
|
||||
_allowedMediaTypes = new HashSet<string>
|
||||
{
|
||||
_pngMediaType,
|
||||
@ -53,6 +60,12 @@ namespace Bit.Icons.Services
|
||||
|
||||
public async Task<IconResult> GetIconAsync(string domain)
|
||||
{
|
||||
if(_ipRegex.IsMatch(domain))
|
||||
{
|
||||
_logger.LogWarning("IP address: {0}.", domain);
|
||||
return null;
|
||||
}
|
||||
|
||||
if(!Uri.TryCreate($"https://{domain}", UriKind.Absolute, out var parsedHttpsUri))
|
||||
{
|
||||
_logger.LogWarning("Bad domain: {0}.", domain);
|
||||
|
Loading…
Reference in New Issue
Block a user