R – Method to get the client ip address

ip addressPROXYrubyruby-on-rails

I'm developing an application where it seems likely that people will attempt to hide what their client IP address is behind a proxy server.

Is there a unified way to get what the actual client IP Address is behind the proxy? Looking at the Ruby docs, it explicitly states that

request.remote_ip

and

request.remote_addr

both would return the proxy address and not the actual client IP and I'm thrown by the "may contain" descriptions in the rest of the HTTP headers.

Best Answer

It depends if the proxy supports X-Forwarded-For. I'd run some tests to be sure that remote_ip isn't what you're looking for - based on a quick glance at the code it attempts to read the HTTP_X_FORWARDED_FOR header.