[BUGFIX] Respect cacheHash excludedParameters in TSFE::reqCHash() 96/60296/22
authorGrigory Rechkin <gr.rechkin@gmail.com>
Mon, 18 Mar 2019 12:32:05 +0000 (17:32 +0500)
committerBenni Mack <benni@typo3.org>
Sat, 9 Nov 2019 08:41:35 +0000 (09:41 +0100)
* Requests with a parameter from "excludedParameters" settings
  will not raise a cHash comparison error
* Requests with configured enhancers will not raise the
  "Page ID is missing" error when used with additional parameters

Resolves: #87845
Releases: master, 9.5
Change-Id: I4312aa790d6660e0e7f9214841fe3d27c5f1b4ea
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/60296
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Susanne Moog <look@susi.dev>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Susanne Moog <look@susi.dev>
Reviewed-by: Benni Mack <benni@typo3.org>
typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php
typo3/sysext/frontend/Tests/Unit/Controller/TypoScriptFrontendControllerTest.php

index c108542..37a9c95 100644 (file)
@@ -1733,6 +1733,13 @@ class TypoScriptFrontendController implements LoggerAwareInterface
         if (!empty($this->pageArguments->getArguments()['cHash']) || empty($this->pageArguments->getDynamicArguments())) {
             return;
         }
+        $queryParams = $this->pageArguments->getDynamicArguments();
+        $queryParams['id'] = $this->pageArguments->getPageId();
+        $argumentsThatWouldRequireCacheHash = GeneralUtility::makeInstance(CacheHashCalculator::class)
+                ->getRelevantParameters(HttpUtility::buildQueryString($queryParams));
+        if (empty($argumentsThatWouldRequireCacheHash)) {
+            return;
+        }
         if ($GLOBALS['TYPO3_CONF_VARS']['FE']['pageNotFoundOnCHashError']) {
             $response = GeneralUtility::makeInstance(ErrorController::class)->pageNotFoundAction(
                 $GLOBALS['TYPO3_REQUEST'],
index d78c4a9..d6bf344 100644 (file)
@@ -19,6 +19,7 @@ use TYPO3\CMS\Core\Cache\Backend\NullBackend;
 use TYPO3\CMS\Core\Cache\CacheManager;
 use TYPO3\CMS\Core\Context\Context;
 use TYPO3\CMS\Core\Domain\Repository\PageRepository;
+use TYPO3\CMS\Core\Http\ImmediateResponseException;
 use TYPO3\CMS\Core\Http\ServerRequest;
 use TYPO3\CMS\Core\Http\ServerRequestFactory;
 use TYPO3\CMS\Core\Http\Uri;
@@ -552,4 +553,81 @@ class TypoScriptFrontendControllerTest extends UnitTestCase
         // since PageRenderer is a singleton, this can be queried via the makeInstance call
         self::assertEquals('fr', $languageService->lang);
     }
+
+    public function requireCacheHashValidateRelevantParametersDataProvider(): array
+    {
+        return [
+            'no extra params' => [
+                [],
+                false,
+            ],
+            'with required param' => [
+                [
+                    'abc' => 1,
+                ],
+                true,
+            ],
+            'with required params' => [
+                [
+                    'abc' => 1,
+                    'abcd' => 1,
+                ],
+                true,
+            ],
+            'with not required param' => [
+                [
+                    'fbclid' => 1,
+                ],
+                false,
+            ],
+            'with not required params' => [
+                [
+                    'fbclid' => 1,
+                    'gclid' => 1,
+                    'foo' => [
+                        'bar' => 1,
+                    ],
+                ],
+                false,
+            ],
+            'with combined params' => [
+                [
+                    'abc' => 1,
+                    'fbclid' => 1,
+                ],
+                true,
+            ],
+            'with multiple combined params' => [
+                [
+                    'abc' => 1,
+                    'fbclid' => 1,
+                    'abcd' => 1,
+                    'gclid' => 1
+                ],
+                true,
+            ]
+        ];
+    }
+
+    /**
+     * @test
+     *
+     * @dataProvider requireCacheHashValidateRelevantParametersDataProvider
+     * @param array $remainingArguments
+     * @param bool $expected
+     */
+    public function requireCacheHashValidateRelevantParameters(array $remainingArguments, bool $expected): void
+    {
+        $GLOBALS['TYPO3_REQUEST'] = new ServerRequest();
+        $GLOBALS['TYPO3_CONF_VARS']['FE']['pageNotFoundOnCHashError'] = true;
+        $GLOBALS['TYPO3_CONF_VARS']['FE']['cacheHash']['excludedParameters'] = ['gclid', 'fbclid', 'foo[bar]'];
+
+        $this->subject = $this->getAccessibleMock(TypoScriptFrontendController::class, ['dummy'], [], '', false);
+        $this->subject->_set('pageArguments', new PageArguments(1, '0', ['tx_test' => 1], ['tx_test' => 1], $remainingArguments));
+
+        if ($expected) {
+            static::expectException(ImmediateResponseException::class);
+        }
+        $this->subject->reqCHash();
+    }
 }