diff options
author | Joas Schilling <coding@schilljs.com> | 2023-10-30 14:14:20 +0100 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2023-11-16 07:45:19 +0100 |
commit | 2fa78f62452cfa69adc86f6730866a28b723ca05 (patch) | |
tree | 38248b35e9dc43f1da6b5a80f9f5f96aabb2d4f3 /lib/private/AppFramework | |
parent | 50f8d6c1295f2847160d615343fae924a043bdf2 (diff) | |
download | nextcloud-server-2fa78f62452cfa69adc86f6730866a28b723ca05.tar.gz nextcloud-server-2fa78f62452cfa69adc86f6730866a28b723ca05.zip |
Reverse X-Forwarded-For list to read the correct proxy remote address
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/private/AppFramework')
-rw-r--r-- | lib/private/AppFramework/Http/Request.php | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/private/AppFramework/Http/Request.php b/lib/private/AppFramework/Http/Request.php index 26a76e0da27..1186753ac73 100644 --- a/lib/private/AppFramework/Http/Request.php +++ b/lib/private/AppFramework/Http/Request.php @@ -593,9 +593,11 @@ class Request implements \ArrayAccess, \Countable, IRequest { // only have one default, so we cannot ship an insecure product out of the box ]); - foreach ($forwardedForHeaders as $header) { + // Read the x-forwarded-for headers and values in reverse order as per + // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-For#selecting_an_ip_address + foreach (array_reverse($forwardedForHeaders) as $header) { if (isset($this->server[$header])) { - foreach (explode(',', $this->server[$header]) as $IP) { + foreach (array_reverse(explode(',', $this->server[$header])) as $IP) { $IP = trim($IP); // remove brackets from IPv6 addresses @@ -603,6 +605,10 @@ class Request implements \ArrayAccess, \Countable, IRequest { $IP = substr($IP, 1, -1); } + if ($this->isTrustedProxy($trustedProxies, $IP)) { + continue; + } + if (filter_var($IP, FILTER_VALIDATE_IP) !== false) { return $IP; } |