use x-forwarded-for http header when logging remote_addr
-
I am getting lots of brute force login requests and simple history is recording the attempts nicely but the IP address it lists is not very helpful.
In SimplePluginLogger.php when it is recording the _server_remote_addr it uses the $_SERVER[“REMOTE_ADDR”] but this is always the same IP address when the server is behind a load balancer (e.g. it is running on AWS with ELB).
A better IP address would be the value of the X-Forwarded-For header. If it is set then it will be the real IP of the user access the site (or maybe the proxy IP if they are going through an outbound proxy). Either way it will be better than the load balancer IP. If it is not available then it’s fine to fall back to the REMOTE_ADDR.
https://devcentral.f5.com/articles/using-quotx-forwarded-for-quot-in-apache-or-php
PHP code:
$headers = apache_request_headers(); $real_client_ip = $headers[“X-Forwarded-For”];apache_request_headers() doesn’t seem like a great name since I imagine you can run PHP on non-Apache servers.
There is a newer method getallheaders() (https://php.net/getallheaders) which is an alias for apache_request_headers() but it is not available in older versions of PHP.
- The topic ‘use x-forwarded-for http header when logging remote_addr’ is closed to new replies.