Commit e94aefa0 authored by Grigory Rechkin's avatar Grigory Rechkin Committed by Benni Mack
Browse files

[BUGFIX] Respect cacheHash excludedParameters in TSFE::reqCHash()

* 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: default avatarTYPO3com <noreply@typo3.com>
Tested-by: Susanne Moog's avatarSusanne Moog <look@susi.dev>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Reviewed-by: Susanne Moog's avatarSusanne Moog <look@susi.dev>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
parent e89e1a5a
......@@ -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'],
......
......@@ -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();
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment