dotnet / AspNetCore.Docs

Documentation for ASP.NET Core
https://docs.microsoft.com/aspnet/core
Creative Commons Attribution 4.0 International
12.58k stars 25.3k forks source link

RemoteIpAddress #21615

Open heapstack-developer opened 3 years ago

heapstack-developer commented 3 years ago

Hi,

The description about HttpContext.Connection.RemoteIpAddress is a little bit confusing. I would suggest putting an example of how it exactly works including also the options.ForwardLimit.


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Rick-Anderson commented 3 years ago

@Tratcher please review

Tratcher commented 3 years ago

Yeah, it's a complicated flow and an execution example would help. There's the start of one here that shows the setup: https://github.com/dotnet/AspNetCore.Docs/blob/master/aspnetcore/host-and-deploy/proxy-load-balancer.md#forwarded-headers-middleware-options (I'm ignoring the X-Forwarded-For-My-Custom-Header-Name setting...)

Next you'd need to specify the initial values for RemoteIpAddress, Scheme, and Host (127.0.10.1, http, and internalhost). These represent the connection to the most immediate proxy.

Now you need some headers: X-Forwarded-For: 1.1.1.1, 2.2.2.2, 3.3.3.3 X-Forwarded-Proto: https, http X-Forwarded-Host: publicdomain.org, middletier.mydomain

Now for the flow:

If I added 3.3.3.3 to the KnownProxies list then it would have continued on to the next set.

Also note that values are removed from the x-forwarded- headers as they're processed, and old values are stored in x-original- headers.