Issue Bug Resolved

#106561CSP prevents sitemap.xml inline CSS styles with script-src: strict-dynamic

André Buchmann 04/11/25, 20:12 updated 11/18/26, 08:25

Description

When setting the script-src to “strict-dynamic” the CSS/Sitemap.xsl causes CSP violations:

Refused to load the script 'https://smk.ddev.site/_assets/984e6ee9829f85eb447bb6a36455204a/CSS/Sitemap.xsl' because it violates the following Content Security Policy directive: "script-src 'strict-dynamic' 'unsafe-inline' https: 'report-sample'". Note that 'strict-dynamic' is present, so host-based allowlisting is disabled. Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.

Minimal csp.yaml to reproduce:

inheritDefault: true
mutations:
  - mode: "extend"
    directive: "script-src"
    sources:
      - "'strict-dynamic'"

TYPO3 13.4.9

The solution of https://forge.typo3.org/issues/103149 is not compatible with strict-dynamic.

Reviews 2

History 614

  1. André Buchmann commented <span data-processor="relativetime" data-value="2025-08-25T10:08:36+00:00" > 08/25/25, 10:08 </span>

    My solution for usage with strict-dynamic (on site level) is, to overwrite the CSP config completely for sitemap requests:

    <?php
    
    declare(strict_types=1);
    
    /*
     * This file is part of the TYPO3 CMS project.
     *
     * It is free software; you can redistribute it and/or modify it under
     * the terms of the GNU General Public License, either version 2
     * of the License, or any later version.
     *
     * For the full copyright and license information, please read the
     * LICENSE.txt file that was distributed with this source code.
     *
     * The TYPO3 project - inspiring people to share!
     */
    
    namespace MyVender\SiteDistribution\ContentSecurityPolicy\EventListener;
    
    use TYPO3\CMS\Core\Attribute\AsEventListener;
    use TYPO3\CMS\Core\Routing\PageArguments;
    use TYPO3\CMS\Core\Security\ContentSecurityPolicy\Directive;
    use TYPO3\CMS\Core\Security\ContentSecurityPolicy\Event\PolicyMutatedEvent;
    use TYPO3\CMS\Core\Security\ContentSecurityPolicy\Policy;
    use TYPO3\CMS\Core\Security\ContentSecurityPolicy\SourceKeyword;
    
    #[AsEventListener(
        identifier: 'myvendor-sitedistribution/sitemap-policy',
    )]
    final readonly class SitemapCspEventListener
    {
        private const string PAGE_TYPE_TO_CHECK = '1533906435'; // Page type of XML sitemap from EXT:seo
    
        public function __invoke(PolicyMutatedEvent $event): void
        {
            if ($event->scope->type->isBackend()) {
                return;
            }
    
            $routing = $event->request->getAttribute('routing');
            if (!$routing instanceof PageArguments || $routing->getPageType() !== self::PAGE_TYPE_TO_CHECK) {
                return;
            }
    
            // Define a new policy for the XML sitemap
            $policy = new Policy();
            $policy->set(Directive::DefaultSrc, SourceKeyword::none);
            $policy->set(Directive::ScriptSrcElem, SourceKeyword::self);
            $policy->set(Directive::StyleSrc, SourceKeyword::unsafeInline);
            $event->setCurrentPolicy($policy);
    
            $event->stopPropagation();
        }
    }
  2. Henrik Ziegenhain commented <span data-processor="relativetime" data-value="2026-07-31T05:37:48+00:00" > 07/31/26, 05:37 </span>

    Thanks – patch generally worked for me.
    Same is needed for CSP-Directive “source-src-elem”

  3. André Buchmann commented and changed status Under Review Resolved done 0 % 100 % <span data-processor="relativetime" data-value="2026-11-18T08:00:14+00:00" > 11/18/26, 08:00 </span>

    Applied in changeset commit:0d02b1ade49cc8e02288db4f45f075f124d94009.

  4. Gerrit Code Review pushed patch set 2 for 14.3 to change 97778 status Resolved Under Review <span data-processor="relativetime" data-value="2026-11-18T08:12:56+00:00" > 11/18/26, 08:12 </span>

  5. André Buchmann commented and changed status Under Review Resolved <span data-processor="relativetime" data-value="2026-11-18T08:25:13+00:00" > 11/18/26, 08:25 </span>

    Applied in changeset commit:f6b67dc13eb079ce1c65d8cd73e7f8779744fa54.