Handling IpSpoofAttackError

For a very small amount of traffic, users occasionally encounter a ActionDispatch::RemoteIp::IpSpoofAttackError.

Based on the error reporting, this is what the HTTP_CLIENT_IP and HTTP_X_FORWARDED_FOR were set at the time of the error:

IP spoofing attack?!HTTP_CLIENT_IP=""HTTP_X_FORWARDED_FOR=",,"

I’ve read over this popular article (http://blog.gingerlime.com/2012/rails-ip-spoofing-vulnerabilities-and-protection/), which offers a number of solutions but was interested in getting feedback from the Prime community.

I’ve reviewed all the IpSpoofAttackErrors and the requests all appear to be from legitimate traffic. I’ve noticed that the HTTP_CLIENT_IP tends to be very similar to one included in the HTTP_X_FORWARDED_FOR array but is slightly different (thus causing the error to be raised). For example, in the above example, the HTTP_CLIENT_IP is “” and the IP in the HTTP_X_FORWARDED_FOR is “”

I’m interested in the best ways to solve this as well as being curious as to why the IPs are close but different. Thanks!