stefanprodan/AspNetCoreRateLimit

Get the real User's desktop IP vs proxy ip address

Opened this issue · 0 comments

Hi,
it might been already asked by someone here, but asking this anyways as I'm facing this issue on my end.

so, I have a web server/app server application as following and want to get the real user's IP address

Step1: User desktop send a request to the web application(web server) which is on our firewall.
Step2: the web server calls some services in app server (micro service) where I have implemented my rate limit which is also on our firewall

so, I have tried both "X-Real-IP" and "X-Forwarded-For" but still capturing the same firewall IP address which is wrong

btw, I am on .Net 6 and here is my code

services.AddSingleton(rateLimitingConfig);
services.Configure(options =>
{
options.EnableEndpointRateLimiting = true;
options.StackBlockedRequests = false;
options.DisableRateLimitHeaders = true;
options.HttpStatusCode = 429;
options.RealIpHeader = "X-Real-IP"; // this is supposed to get the ip behind proxy based on the link above
options.ClientIdHeader = "X-ClientId";
options.GeneralRules = new List
{
new RateLimitRule
{
Endpoint = rateLimitingConfig.Endpoint,
Period = rateLimitingConfig.Period,
Limit = rateLimitingConfig.Limit,
}
};
});
services.AddSingleton<IIpPolicyStore, MemoryCacheIpPolicyStore>();
services.AddSingleton<IRateLimitCounterStore, MemoryCacheRateLimitCounterStore>();
services.AddSingleton<IRateLimitConfiguration, RateLimitConfiguration>();
services.AddSingleton<IProcessingStrategy, AsyncKeyLockProcessingStrategy>();
services.AddInMemoryRateLimiting();
services.AddSingleton<IIpPolicyStore, DistributedCacheIpPolicyStore>();
services.AddSingleton<IRateLimitCounterStore, DistributedCacheRateLimitCounterStore>();

builder.UseIpRateLimiting();

any thoughts?