]> git.mxchange.org Git - friendica.git/commitdiff
adaptions :-)
authorPhilipp <admin@philipp.info>
Thu, 23 Jun 2022 21:01:09 +0000 (23:01 +0200)
committerPhilipp <admin@philipp.info>
Thu, 23 Jun 2022 21:01:09 +0000 (23:01 +0200)
src/App/Request.php
tests/src/App/RequestTest.php
tests/src/Model/User/CookieTest.php

index 43cabba856e513e76b39c0c4f7df14e491251e7a..83f7d25cab6649779454f7ace7dd29639cf28a2d 100644 (file)
@@ -32,8 +32,13 @@ use Friendica\Core\Config\Capability\IManageConfigValues;
  */
 class Request
 {
-       /** @var string the default possible headers, which could contain the client IP */
-       const ORDERED_FORWARD_FOR_HEADER = 'HTTP_X_FORWARDED_FOR';
+       /**
+        * A comma separated list of default headers that could contain the client IP in a proxy request
+        * Beware: This list is ordered
+        *
+        * @var string
+        */
+       const DEFAULT_FORWARD_FOR_HEADER = 'HTTP_X_FORWARDED_FOR';
 
        /** @var string The remote IP address of the current request */
        protected $remoteAddress;
@@ -108,7 +113,7 @@ class Request
         * specified in this header will be returned instead.
         *
         * @param IManageConfigValues $config
-        * @param array               $server
+        * @param array               $server The $_SERVER array
         *
         * @return string
         */
@@ -118,7 +123,7 @@ class Request
                $trustedProxies = preg_split('/(\s*,*\s*)*,+(\s*,*\s*)*/', $config->get('proxy', 'trusted_proxies', ''));
 
                if (\is_array($trustedProxies) && $this->isTrustedProxy($trustedProxies, $remoteAddress)) {
-                       $forwardedForHeaders = preg_split('/(\s*,*\s*)*,+(\s*,*\s*)*/', $config->get('proxy', 'forwarded_for_headers')) ?? static::ORDERED_FORWARD_FOR_HEADER;
+                       $forwardedForHeaders = preg_split('/(\s*,*\s*)*,+(\s*,*\s*)*/', $config->get('proxy', 'forwarded_for_headers', static::DEFAULT_FORWARD_FOR_HEADER));
 
                        foreach ($forwardedForHeaders as $header) {
                                if (isset($server[$header])) {
index e4379b052a416587f7e3c22f0445a638e432376d..4ab557358a334e0bdffef01b7b74cdccd0bab30c 100644 (file)
@@ -120,7 +120,7 @@ class RequestTest extends MockedTest
        {
                $configClass = \Mockery::mock(IManageConfigValues::class);
                $configClass->shouldReceive('get')->with('proxy', 'trusted_proxies', '')->andReturn($config['trusted_proxies']);
-               $configClass->shouldReceive('get')->with('proxy', 'forwarded_for_headers')->andReturn($config['forwarded_for_headers']);
+               $configClass->shouldReceive('get')->with('proxy', 'forwarded_for_headers', Request::DEFAULT_FORWARD_FOR_HEADER)->andReturn($config['forwarded_for_headers']);
 
                $request = new Request($configClass, $server);
 
index b5db3495268d4774548c15725d83f25c515a1ae1..fa99a0b75bf081b41c7fc864eef5a6f58b5239a3 100644 (file)
@@ -252,7 +252,7 @@ class CookieTest extends MockedTest
                $this->config->shouldReceive('get')->with('system', 'site_prvkey')->andReturn($serverKey)->once();
                $this->config->shouldReceive('get')->with('system', 'auth_cookie_lifetime', Cookie::DEFAULT_EXPIRE)->andReturn(Cookie::DEFAULT_EXPIRE)->once();
                $this->config->shouldReceive('get')->with('proxy', 'trusted_proxies', '')->andReturn('')->once();
-               $this->config->shouldReceive('get')->with('proxy', 'forwarded_for_headers')->andReturn(Request::ORDERED_FORWARD_FOR_HEADER);
+               $this->config->shouldReceive('get')->with('proxy', 'forwarded_for_headers')->andReturn(Request::DEFAULT_FORWARD_FOR_HEADER);
 
 
                $request = new Request($this->config, $serverArray);
@@ -279,7 +279,7 @@ class CookieTest extends MockedTest
                $this->config->shouldReceive('get')->with('system', 'site_prvkey')->andReturn($serverKey)->once();
                $this->config->shouldReceive('get')->with('system', 'auth_cookie_lifetime', Cookie::DEFAULT_EXPIRE)->andReturn(Cookie::DEFAULT_EXPIRE)->once();
                $this->config->shouldReceive('get')->with('proxy', 'trusted_proxies', '')->andReturn('')->once();
-               $this->config->shouldReceive('get')->with('proxy', 'forwarded_for_headers')->andReturn(Request::ORDERED_FORWARD_FOR_HEADER);
+               $this->config->shouldReceive('get')->with('proxy', 'forwarded_for_headers')->andReturn(Request::DEFAULT_FORWARD_FOR_HEADER);
 
                $request = new Request($this->config, $serverArray);