MDL-67861 core: Added $CFG->reverseproxyignore IP subnet list

If your server is behind multiple reverse proxies that append to the
X-Forwarded-For header then you will need to specify a comma separated
list of ip addresses or subnets of the reverse proxies to be ignored
in order to find the users correct IP address.
This commit is contained in:
Brendan Heywood
2020-03-05 01:13:12 +01:00
committed by Eloy Lafuente (stronk7)
parent e6e07e0960
commit 7251f154ef
3 changed files with 8 additions and 0 deletions
+5
View File
@@ -9028,6 +9028,11 @@ function getremoteaddr($default='0.0.0.0') {
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$forwardedaddresses = explode(",", $_SERVER['HTTP_X_FORWARDED_FOR']);
$forwardedaddresses = array_filter($forwardedaddresses, function($ip) {
global $CFG;
return !\core\ip_utils::is_ip_in_subnet_list($ip, $CFG->reverseproxyignore, ',');
});
// Multiple proxies can append values to this header including an
// untrusted original request header so we must only trust the last ip.
$address = end($forwardedaddresses);