Author: desrod
Description:
I run Apache behind Squid accellerators which sets a header of
HTTP_X_FORWARDED_FOR to represent the remote client IP address (instead of
Apache's REMOTE_ADDR header). MediaWiki's test for this is incorrect (fix
below). I tried using $wgUseSquid = true; in LocalSettings.php which did not
solve the problem for me.
In the file includes/ProxyTools.php there is a test for the header REMOTE_ADDR,
which will always be true, even when running behind Squid. In my case, the IP
reported for all clients is 127.0.0.1, which isn't useful when trying to track
down abuse of the wiki from outsiders.
I updated includes/ProxyTools.php to test for HTTP_X_FORWARDED_FOR first, then
REMOTE_ADDR. If HTTP_X_FORWARDED_FOR is found, it is used. If it isn't found,
REMOTE_ADDR is tested and used instead. The current test never reaches the
second clause, and this fixes that condition.
Below is my fixed stanza, in full. I've tested this and it works perfectly as
expected:
/* collect the originating ips */ # Client connecting to this webserver if ( isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) { $ipchain = array( $_SERVER['HTTP_X_FORWARDED_FOR'] ); } else if ( isset( $_SERVER['REMOTE_ADDR'] ) ) { $ipchain = array( $_SERVER['REMOTE_ADDR'] ); } else { # Running on CLI? $ipchain = array( '127.0.0.1' ); } $ip = $ipchain[0];
Version: 1.5.x
Severity: major