MvcThrottle icon indicating copy to clipboard operation
MvcThrottle copied to clipboard

System.FormatException thrown by poorly formatted HTTP_X_FORWARDED_FOR

Open jcoleson opened this issue 7 years ago • 0 comments

If a client doesn't properly format the HTTP_X_FORWARDED_FOR request header MvcThrottle.IpAddressParser.ParseIp will throw a System.FormatException.

In these cases, we would rather it just use the IP address of the request. While it's true this is an error on the client's part, if the request is otherwise valid we'd still like to serve something to the user.

I'd suggest returning IPAddress.None:

            IPAddress parsedIP;
            if (IPAddress.TryParse(ipAddress, out parsedIP))
            {
                return parsedIP;
            } else
            {
                return IPAddress.None;
            }

jcoleson avatar Oct 09 '18 17:10 jcoleson