From 76d1c9c4f3a30c81b300eff454d23dd3dc3f9a18 Mon Sep 17 00:00:00 2001
From: Benni Mack <benni@typo3.org>
Date: Thu, 13 Sep 2018 13:41:29 +0200
Subject: [PATCH] [BUGFIX] Evaluate config.defaultGetVars in middleware

The config.defaultGetVars is executed and $_GET is modified,
but not the middleware where this method is called.

In order to also modify the middleware's request object, the
option config.defaultGetVars is also evaluted again in the PSR-15
middleware.

Resolves: #86241
Related: #86046
Releases: master
Change-Id: I2238d93b4974a40b2228c099cef7c8a04bd6cf74
Reviewed-on: https://review.typo3.org/58266
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Daniel Sattler <sattler@b13.de>
Tested-by: Daniel Sattler <sattler@b13.de>
Reviewed-by: Daniel Goerz <daniel.goerz@posteo.de>
Tested-by: Daniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
---
 .../Controller/TypoScriptFrontendController.php    |  1 +
 .../PrepareTypoScriptFrontendRendering.php         | 14 ++++++++++++++
 2 files changed, 15 insertions(+)

diff --git a/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php b/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php
index 370f1f70b9eb..860835db40e8 100644
--- a/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php
+++ b/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php
@@ -2591,6 +2591,7 @@ class TypoScriptFrontendController implements LoggerAwareInterface
             $this->set_no_cache('config.no_cache is set');
         }
         // Merge GET with defaultGetVars
+        // Please note that this code will get removed in TYPO3 v10.0 as it is done in the PSR-15 middleware.
         if (!empty($this->config['config']['defaultGetVars.'])) {
             $modifiedGetVars = GeneralUtility::removeDotsFromTS($this->config['config']['defaultGetVars.']);
             ArrayUtility::mergeRecursiveWithOverrule($modifiedGetVars, GeneralUtility::_GET());
diff --git a/typo3/sysext/frontend/Classes/Middleware/PrepareTypoScriptFrontendRendering.php b/typo3/sysext/frontend/Classes/Middleware/PrepareTypoScriptFrontendRendering.php
index dd57e6ce2530..ff6388a93a1c 100644
--- a/typo3/sysext/frontend/Classes/Middleware/PrepareTypoScriptFrontendRendering.php
+++ b/typo3/sysext/frontend/Classes/Middleware/PrepareTypoScriptFrontendRendering.php
@@ -21,6 +21,7 @@ use Psr\Http\Message\ServerRequestInterface;
 use Psr\Http\Server\MiddlewareInterface;
 use Psr\Http\Server\RequestHandlerInterface as PsrRequestHandlerInterface;
 use TYPO3\CMS\Core\TimeTracker\TimeTracker;
+use TYPO3\CMS\Core\Utility\ArrayUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
 
@@ -64,6 +65,19 @@ class PrepareTypoScriptFrontendRendering implements MiddlewareInterface
         // Get config if not already gotten
         // After this, we should have a valid config-array ready
         $this->controller->getConfigArray();
+
+        // Merge Query Parameters with config.defaultGetVars
+        // This is done in getConfigArray as well, but does not override the current middleware request object
+        // Since we want to stay in sync with this, the option needs to be set as well.
+        if (!empty($this->controller->config['config']['defaultGetVars.'] ?? null)) {
+            $modifiedGetVars = GeneralUtility::removeDotsFromTS($this->controller->config['config']['defaultGetVars.']);
+            if (!empty($request->getQueryParams())) {
+                ArrayUtility::mergeRecursiveWithOverrule($modifiedGetVars, $request->getQueryParams());
+            }
+            $request = $request->withQueryParams($modifiedGetVars);
+            $GLOBALS['TYPO3_REQUEST'] = $request;
+        }
+
         // Setting language and locale
         $this->timeTracker->push('Setting language and locale');
         $this->controller->settingLanguage();
-- 
GitLab