Skip to content

Commit

Permalink
[TASK] Fix #244: restore cHash calculation as optional feature
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitryd committed Sep 14, 2016
1 parent e1bf7d0 commit 2404138
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions Classes/Configuration/ConfigurationReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class ConfigurationReader {
'fileName/defaultToHTMLsuffixOnPrev' => FALSE,
'init/appendMissingSlash' => 'ifNotFile,redirect[301]',
'init/emptySegmentValue' => '',
'init/calculateChashIfMissing' => false,
'pagePath/spaceCharacter' => '-', // undocumented & deprecated!
);

Expand Down
29 changes: 28 additions & 1 deletion Classes/Decoder/UrlDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,33 @@ public function storeCacheRecord() {
}
}

/**
* Calculates and adds cHash to the entry. This function is only called
* if we had to decode the entry, which was not in the cache. Even if we
* had cHash in the URL, we force to re-calculate it because we could have
* decoded parameters differently than the original URL had (for example,
* skipped some noMatch parameters).
*
* cHash recalculation can have bad consequences for the page cache. For
* details see the following links:
* - https://typo3.org/teams/security/security-bulletins/typo3-extensions/typo3-ext-sa-2016-021/
* - https://github.com/dmitryd/typo3-realurl/issues/244#issuecomment-245844501
*
* @param UrlCacheEntry $cacheEntry
* @return void
*/
protected function calculateChash(UrlCacheEntry $cacheEntry) {
$requestVariables = $cacheEntry->getRequestVariables();
$cacheHashCalculator = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Page\\CacheHashCalculator');
/* @var \TYPO3\CMS\Frontend\Page\CacheHashCalculator $cacheHashCalculator */
$cHashParameters = $cacheHashCalculator->getRelevantParameters(GeneralUtility::implodeArrayForUrl('', $requestVariables));

if (count($cHashParameters) > 0) {
$requestVariables['cHash'] = $cacheHashCalculator->calculateCacheHash($cHashParameters);
$cacheEntry->setRequestVariables($requestVariables);
}
}

/**
* Calls user-defined hooks.
*
Expand Down Expand Up @@ -1358,8 +1385,8 @@ protected function runDecoding() {

$probablyMissingChash = $this->isChashMissing($cacheEntry);
}
$this->checkExpiration($cacheEntry);

$this->checkExpiration($cacheEntry);
$this->setRequestVariables($cacheEntry);

if ($newCacheEntry && !$probablyMissingChash) {
Expand Down

0 comments on commit 2404138

Please sign in to comment.