MDL-67861 core: Use last ip in X-Forwarded-For list

This commit is contained in:
Brendan Heywood
2020-03-05 01:27:48 +01:00
committed by Eloy Lafuente (stronk7)
parent 31260f8667
commit 4a3a673d1e
+4 -1
View File
@@ -9149,7 +9149,10 @@ function getremoteaddr($default='0.0.0.0') {
if (!($variablestoskip & GETREMOTEADDR_SKIP_HTTP_X_FORWARDED_FOR)) {
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$forwardedaddresses = explode(",", $_SERVER['HTTP_X_FORWARDED_FOR']);
$address = $forwardedaddresses[0];
// 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);
if (substr_count($address, ":") > 1) {
// Remove port and brackets from IPv6.