Добавил X Forwarded Proto
All checks were successful
Create and publish a Docker image / Publish image (push) Successful in 3m1s
All checks were successful
Create and publish a Docker image / Publish image (push) Successful in 3m1s
This commit is contained in:
@@ -76,7 +76,9 @@ builder.Services.AddRateLimiter(options =>
|
||||
{
|
||||
options.AddPolicy("throttle", httpContext =>
|
||||
RateLimitPartition.GetFixedWindowLimiter(
|
||||
partitionKey: httpContext.Connection.RemoteIpAddress?.ToString() ?? "unknown",
|
||||
partitionKey: (httpContext.Request.Headers.TryGetValue("X-Forwarded-For", out var xff) && !string.IsNullOrWhiteSpace(xff.ToString()))
|
||||
? xff.ToString().Split(',')[0].Trim()
|
||||
: (httpContext.Connection.RemoteIpAddress?.ToString() ?? "unknown"),
|
||||
factory: _ => new FixedWindowRateLimiterOptions
|
||||
{
|
||||
PermitLimit = 20,
|
||||
@@ -92,8 +94,10 @@ builder.Services.AddRateLimiter(options =>
|
||||
cancellationToken);
|
||||
|
||||
var reqLogger = context.HttpContext.RequestServices.GetRequiredService<ILogger<Program>>();
|
||||
reqLogger.LogWarning("Rate limit exceeded for IP: {IpAddress}",
|
||||
context.HttpContext.Connection.RemoteIpAddress);
|
||||
var clientIp = (context.HttpContext.Request.Headers.TryGetValue("X-Forwarded-For", out var xff) && !string.IsNullOrWhiteSpace(xff.ToString()))
|
||||
? xff.ToString().Split(',')[0].Trim()
|
||||
: context.HttpContext.Connection.RemoteIpAddress?.ToString();
|
||||
reqLogger.LogWarning("Rate limit exceeded for IP: {IpAddress}", clientIp);
|
||||
};
|
||||
});
|
||||
|
||||
|
@@ -4,6 +4,7 @@ services:
|
||||
- '8088:8080'
|
||||
container_name: SfeduSchedule
|
||||
environment:
|
||||
- ASPNETCORE_FORWARDEDHEADERS_ENABLED=true
|
||||
- AzureAd:Instance=https://login.microsoftonline.com/
|
||||
- AzureAd:TenantId=sfedu.ru
|
||||
- AzureAd:ClientId=
|
||||
|
@@ -4,6 +4,7 @@ services:
|
||||
- '8088:8080'
|
||||
container_name: SfeduSchedule
|
||||
environment:
|
||||
- ASPNETCORE_FORWARDEDHEADERS_ENABLED=true
|
||||
- AzureAd:Instance=https://login.microsoftonline.com/
|
||||
- AzureAd:TenantId=sfedu.ru
|
||||
- AzureAd:ClientId=
|
||||
|
Reference in New Issue
Block a user