Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IPAddress.IsLoopBack returns false for ::ffff:127.0.0.1 #28740

Closed
oliverholliday opened this issue Feb 20, 2019 · 0 comments
Closed

IPAddress.IsLoopBack returns false for ::ffff:127.0.0.1 #28740

oliverholliday opened this issue Feb 20, 2019 · 0 comments
Assignees
Milestone

Comments

@oliverholliday
Copy link

Local connections to an aspnetcore app running on win10 have the HttpContext.Connection.RemoteIpAddress property set to ::ffff:127.0.0.1.

The IPAddress.IsLoopBack() method returns false for this address - the method checks for IPv6 and IPv4 loopback addresses but doesn't check a loopback IPv4 address mapped to IPv6. I believe this is confusing.

https://github.com/dotnet/corefx/blob/master/src/System.Net.Primitives/src/System/Net/IPAddress.cs#L418

I worked around this by doing:

IPAddress.IsLoopback(address.IsIPv4MappedToIPv6 ? address.MapToIPv4() : address)
@oliverholliday oliverholliday changed the title IPAddress.IsLoopBack returns false for ::ffff:127.0.0.1 IPAddress.IsLoopBack returns false for ::ffff:127.0.0.1 Feb 20, 2019
@stephentoub stephentoub self-assigned this Feb 20, 2019
@msftgits msftgits transferred this issue from dotnet/corefx Feb 1, 2020
@msftgits msftgits added this to the 3.0 milestone Feb 1, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants