aspnet / BasicMiddleware

[Archived] Basic middleware components for ASP.NET Core. Project moved to https://github.com/aspnet/AspNetCore
Apache License 2.0
169 stars 84 forks source link

UseForwardedHeaders not supporting IPv6 addresses? #302

Closed rhegner closed 5 years ago

rhegner commented 6 years ago

My app runs behind Ngnix and I'm trying to get client's IP address using Connection.RemoteIpAddress.

The request contains a X-Forwarded-For header like this: ::ffff:xxx.xxx.xxx.xxx:12345 and it does not seem to be recognized by the middleware using the following settings:

app.UseForwardedHeaders(new ForwardedHeadersOptions {  ForwardLimit = null, RequireHeaderSymmetry = false,  ForwardedHeaders = Microsoft.AspNetCore.HttpOverrides.ForwardedHeaders.XForwardedFor });

If I set the same header manually to a IPv4 address, everything works as expected.

So does not middleware not support IPv6?

Tratcher commented 6 years ago

IPv6 is supported. That value isn't well formatted though, it's supposed to be [::ffff:xxx.xxx.xxx.xxx]:12345. Raw IPv6 addresses can't have ports appended without the brackets, the colons become ambiguous.

muratg commented 5 years ago

This was fixed in 2.2. If you still see issues, please let us know.