mirror of
https://github.com/bitwarden/server.git
synced 2025-07-02 16:42:50 -05:00
adjusted serilog inclusion predicate with bypassid
This commit is contained in:
@ -16,7 +16,7 @@ namespace Bit.Core.Utilities
|
||||
private readonly IpRateLimitOptions _options;
|
||||
private readonly IMemoryCache _memoryCache;
|
||||
private readonly IBlockIpService _blockIpService;
|
||||
private readonly ILogger<IpRateLimitMiddleware> _logger;
|
||||
private readonly ILogger<CustomIpRateLimitMiddleware> _logger;
|
||||
|
||||
public CustomIpRateLimitMiddleware(
|
||||
IMemoryCache memoryCache,
|
||||
@ -25,7 +25,7 @@ namespace Bit.Core.Utilities
|
||||
IOptions<IpRateLimitOptions> options,
|
||||
IRateLimitCounterStore counterStore,
|
||||
IIpPolicyStore policyStore,
|
||||
ILogger<IpRateLimitMiddleware> logger,
|
||||
ILogger<CustomIpRateLimitMiddleware> logger,
|
||||
IIpAddressParser ipParser = null)
|
||||
: base(next, options, counterStore, policyStore, logger, ipParser)
|
||||
{
|
||||
@ -59,11 +59,13 @@ namespace Bit.Core.Utilities
|
||||
if(blockedCount > 10)
|
||||
{
|
||||
_blockIpService.BlockIpAsync(identity.ClientIp, false);
|
||||
_logger.LogInformation($"Banned {identity.ClientIp}. \nInfo: \n{GetRequestInfo(httpContext)}");
|
||||
_logger.LogInformation(Constants.BypassFiltersEventId, null,
|
||||
"Banned {0}. \nInfo: \n{1}", identity.ClientIp, GetRequestInfo(httpContext));
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogInformation($"Request blocked {identity.ClientIp}. \nInfo: \n{GetRequestInfo(httpContext)}");
|
||||
_logger.LogInformation(Constants.BypassFiltersEventId, null,
|
||||
"Request blocked {0}. \nInfo: \n{1}", identity.ClientIp, GetRequestInfo(httpContext));
|
||||
_memoryCache.Set(key, blockedCount,
|
||||
new MemoryCacheEntryOptions().SetSlidingExpiration(new TimeSpan(0, 5, 0)));
|
||||
}
|
||||
|
@ -22,14 +22,23 @@ namespace Bit.Core.Utilities
|
||||
return factory;
|
||||
}
|
||||
|
||||
if(filter == null)
|
||||
bool inclusionPredicate(LogEvent e)
|
||||
{
|
||||
filter = (e) => true;
|
||||
if(filter == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
var eventId = e.Properties.ContainsKey("EventId") ? e.Properties["EventId"].ToString() : null;
|
||||
if(eventId?.Contains(Constants.BypassFiltersEventId.ToString()) ?? false)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return filter(e);
|
||||
}
|
||||
|
||||
var config = new LoggerConfiguration()
|
||||
.Enrich.FromLogContext()
|
||||
.Filter.ByIncludingOnly(filter);
|
||||
.Filter.ByIncludingOnly(inclusionPredicate);
|
||||
|
||||
if(CoreHelpers.SettingHasValue(globalSettings?.DocumentDb.Uri) &&
|
||||
CoreHelpers.SettingHasValue(globalSettings?.DocumentDb.Key))
|
||||
|
Reference in New Issue
Block a user