diff --git a/Classes/Cache/Listener/NoIntScriptsListener.php b/Classes/Cache/Listener/NoIntScriptsListener.php index becabd8c8b9..aa90e06190a 100644 --- a/Classes/Cache/Listener/NoIntScriptsListener.php +++ b/Classes/Cache/Listener/NoIntScriptsListener.php @@ -6,9 +6,8 @@ use SFC\Staticfilecache\Event\CacheRuleEvent; use SFC\Staticfilecache\Service\ConfigurationService; -use TYPO3\CMS\Core\TypoScript\FrontendTypoScript; use TYPO3\CMS\Frontend\Cache\NonceValueSubstitution; -use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; +use TYPO3\CMS\Frontend\Page\PageParts; class NoIntScriptsListener { @@ -16,34 +15,43 @@ public function __construct(protected readonly ConfigurationService $configurati public function __invoke(CacheRuleEvent $event): void { - $frontendTypoScript = $event->getRequest()->getAttribute('frontend.typoscript'); - if ($frontendTypoScript instanceof FrontendTypoScript) { - $configArray = $frontendTypoScript->getConfigArray(); - if (isset($configArray['INTincScript']) && is_array($configArray['INTincScript'])) { - foreach ($configArray['INTincScript'] as $key => $configuration) { - - $cspGenerationOverride = (bool) $this->configurationService->get('cspGenerationOverride'); - if ($cspGenerationOverride && isset($configuration['target']) && $configuration['target'] === NonceValueSubstitution::class . '->substituteNonce') { - continue; - } - - $event->addExplanation(__CLASS__ . ':' . $key, 'The page has a INTincScript: ' . implode(', ', $this->getInformation($configuration))); - } + // @todo PageParts is marked "@internal Experimental, will change" by the TYPO3 core + // and may change during v14/v15 development. Re-check this listener with + // every major TYPO3 update, see Breaking-107831/107578 (TSFE removal series). + $pageParts = $event->getRequest()->getAttribute('frontend.page.parts'); + if (!$pageParts instanceof PageParts) { + return; + } + $cspGenerationOverride = (bool) $this->configurationService->get('cspGenerationOverride'); + foreach ($pageParts->getNotCachedContentElementRegistry() as $key => $configuration) { + if ($cspGenerationOverride + && isset($configuration['target']) + && $configuration['target'] === NonceValueSubstitution::class . '->substituteNonce' + ) { + continue; } + + $event->addExplanation( + __CLASS__ . ':' . $key, + 'The page has a not-cached content element: ' . implode(', ', $this->getInformation($configuration)) + ); } } /** * Get the debug information. * - * @param array $configuration + * @param array $configuration + * + * @return array */ - protected function getInformation($configuration): array + protected function getInformation(array $configuration): array { $info = []; // Root properties foreach ([ + 'substKey', 'target', 'type', ] as $value) {