Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 25 additions & 17 deletions Classes/Cache/Listener/NoIntScriptsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,52 @@

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
{
public function __construct(protected readonly ConfigurationService $configurationService) {}

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<string, mixed> $configuration
*
* @return array<int, string>
*/
protected function getInformation($configuration): array
protected function getInformation(array $configuration): array
{
$info = [];

// Root properties
foreach ([
'substKey',
'target',
'type',
] as $value) {
Expand Down