Explicitly trust `x-forwarded-proto` for Diactoros' ServerRequest
authorTim Düsterhus <duesterhus@woltlab.com>
Thu, 30 Jun 2022 08:49:42 +0000 (10:49 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Thu, 30 Jun 2022 08:49:42 +0000 (10:49 +0200)
This is required to future-proof the Diactoros configuration to be consistent
with RouteHandler::secureConnection().

see https://github.com/laminas/laminas-diactoros/blob/c272a93fc716456599d26bf7cc3281ccb708dabf/docs/book/v2/forward-migration.md

wcfsetup/install/files/lib/system/request/RequestHandler.class.php

index 592b711f3e4ac440e6ca98f323bb2c1ab77ccd45..ee6711e5f66c5ec7bfd07e5a591c21d8c62742aa 100644 (file)
@@ -4,6 +4,7 @@ namespace wcf\system\request;
 
 use Laminas\Diactoros\Response\RedirectResponse;
 use Laminas\Diactoros\ServerRequestFactory;
+use Laminas\Diactoros\ServerRequestFilter\FilterUsingXForwardedHeaders;
 use Laminas\HttpHandlerRunner\Emitter\SapiEmitter;
 use Psr\Http\Message\RequestInterface;
 use Psr\Http\Message\ResponseInterface;
@@ -72,7 +73,12 @@ final class RequestHandler extends SingletonFactory
                 }
             }
 
-            $psrRequest = ServerRequestFactory::fromGlobals();
+            $psrRequest = ServerRequestFactory::fromGlobals(
+                requestFilter: FilterUsingXForwardedHeaders::trustProxies(
+                    ['*'],
+                    [FilterUsingXForwardedHeaders::HEADER_PROTO]
+                )
+            );
 
             $builtRequest = $this->buildRequest($psrRequest, $application);