Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions application/AppGateway/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using PlatformPlatform.AppGateway.Transformations;
using PlatformPlatform.SharedKernel.Configuration;
using Scalar.AspNetCore;
using Yarp.ReverseProxy.Transforms;

var builder = WebApplication.CreateBuilder(args);

Expand All @@ -14,12 +13,7 @@
.LoadFromConfig(builder.Configuration.GetSection("ReverseProxy"))
.AddConfigFilter<ClusterDestinationConfigFilter>()
.AddConfigFilter<ApiExplorerRouteFilter>()
.AddTransforms(context =>
{
context.AddXForwarded();
context.RequestTransforms.Add(context.Services.GetRequiredService<BlockInternalApiTransform>());
}
);
.AddTransforms(context => context.RequestTransforms.Add(context.Services.GetRequiredService<BlockInternalApiTransform>()));

if (SharedInfrastructureConfiguration.IsRunningInAzure)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,18 @@ public IPAddress ClientIpAddress
return field = IPAddress.None;
}

// UseForwardedHeaders() middleware already processes X-Forwarded-For and sets RemoteIpAddress
// Read X-Forwarded-For header directly to get client IP (first IP in the chain is the original client)
var forwardedFor = httpContextAccessor.HttpContext.Request.Headers["X-Forwarded-For"].ToString();
if (!string.IsNullOrEmpty(forwardedFor))
{
var clientIp = forwardedFor.Split(',').FirstOrDefault()?.Trim();
if (IPAddress.TryParse(clientIp, out var parsedIpAddress))
{
return field = NormalizeLoopbackAddress(parsedIpAddress);
}
}

// Fall back to RemoteIpAddress for local development without proxies
var remoteIpAddress = httpContextAccessor.HttpContext.Connection.RemoteIpAddress ?? IPAddress.None;
return field = NormalizeLoopbackAddress(remoteIpAddress);
}
Expand Down
Loading