Добавил X Forwarded Proto
All checks were successful
Create and publish a Docker image / Publish image (push) Successful in 3m1s

This commit is contained in:
2025-09-06 22:27:32 +03:00
parent ea254c1c02
commit 0211b5d881
3 changed files with 9 additions and 3 deletions

View File

@@ -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);
};
});

View File

@@ -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=

View File

@@ -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=