How to troubleshoot client IP detection?
-
I’m trying to set up a site that allows certain IPs to access it regardless, and if a client is connecting from an IP not in that range, to force authentication. The problem is that the plugin appears not to be detecting the client IP address properly, even though it’s provided to the server via an X-Forwarded-For: header.
My network architecture is a bit more complicated than some — clients connect to a load-balancer (an F5 hardware device), which connects to a Varnish cache, which then finally connects to the Web server (pretty standard Apache on Red Hat), which then passes the request to php-fpm). The IP info appears to be making it back to the Web server — $_SERVER[‘REMOTE_ADDR’] correctly reflects the IP of the Varnish cache that’s actually doing the connecting (this is the IP I don’t want to use), and $_SERVER[‘HTTP_X_FORWARDED_FOR’] correctly reflects the client IP, before any firewalling, NAT, and so on. (This came from creating a page inside the wp-admin/ directory that just calls
phpinfo()
and verifying that its contents look correct. If there’s a scenario where WordPress thinks things are different from vanilla PHP, I wouldn’t know about it.)My read of the code in the Restricted Site Access plugin’s
get_client_ip_address()
function is that the plugin should see the HTTP_X_FORWARDED_FOR header first, and use the contents of that server variable as the perceived client IP address. Unfortunately, it appears not to be doing so — I don’t know if it’s reading the headers in the wrong order (and thus pulling, say, REMOTE_ADDR), or if all these headers are being ignored (and thus probably defaulting to the “real” IP-level client info, which would be the same as REMOTE_ADDR in this case).In the plugin-specific management settings, when I click “Add My Current IP Address”, the IP used is the Varnish IP, not the correct client IP. This would seem to verify that
get_client_ip_address()
is ultimately responsible, since that button just calls it and uses its output to populate the box.Unfortunately, I’m not really sure how to further debug this. Any suggestions on how to dig into this function, or how to override the IP detection, would be greatly appreciated.
- The topic ‘How to troubleshoot client IP detection?’ is closed to new replies.