Issue Bug Closed

#103149CSP prevents sitemap.xml inline CSS styles

Josef Glatz 02/19/24, 06:18 updated 12/02/25, 14:33

Description

Problem/Description

CSS Inline Styles in the auto generated sitemap.xml feature is blocked by Content Security Policy per default.

Affected: main, 13.0, 12.4

Acceptance Criteria

The styles should work without modifying CSP rules or the sitemap.xml template files.

—-

BTW: what about a dedicated redmine category named “Content Security Policy”?

Reviews 3

Files 1

History 1333

Show 78 earlier messages
  1. Timo Webler commented <span data-processor="relativetime" data-value="2024-02-22T10:46:54+00:00" > 02/22/24, 10:46 </span>

    Our current workaround:

    class PolicyMutatedEvent
    {
        protected string $sitemapPageType = '1533906435';
    
        public function __invoke(\TYPO3\CMS\Core\Security\ContentSecurityPolicy\Event\PolicyMutatedEvent $event): void
        {
            $request = $this->getRequest();
            if (
                !$event->scope->isFrontendSite() ||
                $request === null ||
                $request->getAttribute('frontend.controller')?->getPageArguments()->getPageType() !== $this->sitemapPageType
            ) {
                return;
            }
            $event->getCurrentPolicy()->set(
                Directive::StyleSrcElem,
                SourceKeyword::unsafeInline
            );
        }
    
        protected function getRequest(): ?ServerRequestInterface
        {
            return $GLOBALS['TYPO3_REQUEST'];
        }
    }
  2. Oliver Hader commented and changed status New Under Review <span data-processor="relativetime" data-value="2024-04-29T07:20:39+00:00" > 04/29/24, 07:20 </span>

    • How to reproduce?
    • What are the CSP headers being sent?
    • What are the CSP violations being issued?

    Besides that: Is it really relevant, that sitemap.xml supports styles when being shown in a browser? Or is it more like it should skip reports for sitemap.xml in case something is wrong there (but still block styles)?

  3. Timo Webler commented and changed attached clipboard-202404290938-exdlf.png <span data-processor="relativetime" data-value="2024-04-29T07:38:31+00:00" > 04/29/24, 07:38 </span>

    Oliver Hader wrote in #note-4:
    > * How to reproduce?

    csp.yaml:

    # Inherits default site-unspecific frontend policy mutations (enabled per default)
    inheritDefault: true
    mutations:
      - mode: set
        directive: 'default-src'
        sources: ["'none'"]
      - mode: set
        directive: 'manifest-src'
        sources: ["'self'"]
      - mode: set
        directive: 'img-src'
        sources: ["'self'", "data:"]
      - mode: set
        directive: 'style-src'
        sources: ["'self'", "'unsafe-inline'"]
      - mode: set
        directive: 'base-uri'
        sources: ["'self'"]
      - mode: set
        directive: 'form-action'
        sources: ["'self'"]
      - mode: set
        directive: 'media-src'
        sources: ["'self'"]
      - mode: set
        directive: 'connect-src'
        sources: ['self']
      - mode: set
        directive: 'script-src'
        sources: ["'nonce-proxy'", "'self'"]

    > * What are the CSP headers being sent?

    Content-Security-Policy: default-src 'none'; script-src 'nonce-JkAMWyZSCu6GhrHfwK6WLSPUIQC0vgunGZEmd-9RT1PpSpowF0zRfA' 'self' 'report-sample'; style-src-attr 'unsafe-inline' 'report-sample'; img-src 'self' data:; base-uri 'self'; frame-src 'self' *.youtube-nocookie.com *.youtube.com *.vimeo.com; style-src-elem 'self' 'nonce-JkAMWyZSCu6GhrHfwK6WLSPUIQC0vgunGZEmd-9RT1PpSpowF0zRfA' 'report-sample'; manifest-src 'self'; style-src 'self' 'unsafe-inline' 'report-sample'; form-action 'self'; media-src 'self'; connect-src self; report-uri https://exmaple.com

    > * What are the CSP violations being issued?

    clipboard-202404290938-exdlf.png

    > Besides that: Is it really relevant, that sitemap.xml supports styles when being shown in a browser? Or is it more like it should skip reports for sitemap.xml in case something is wrong there (but still block styles)?

    Not really relevant. But TYPO3 deliver a stylesheet for that view and than it should work. Maybe remove the stylesheets for sitemap.xml as alternative solution.

  4. Oliver Hader commented <span data-processor="relativetime" data-value="2024-04-30T20:01:42+00:00" > 04/30/24, 20:01 </span>

    Thanks for the feedback, I was able to reproduce the behavior…

    The resulting CSP violation looks like this:

    {
        "document-uri": "https://ip13.anyhost.it/?type=1533906435",
        "referrer": "",
        "violated-directive": "style-src-elem",
        "effective-directive": "style-src-elem",
        "original-policy": "default-src 'self'; script-src 'self' 'nonce-wdB5XPhMdnxXxfNpAsJGflt5UH0o_5-Z4ijHDwQLoQ-03gInUmWx_w' 'report-sample'; style-src-attr 'unsafe-inline' 'report-sample'; img-src 'self' data: *.ytimg.com *.vimeocdn.com; base-uri 'self'; frame-src 'self' *.youtube-nocookie.com *.youtube.com *.vimeo.com; style-src-elem 'self' 'nonce-wdB5XPhMdnxXxfNpAsJGflt5UH0o_5-Z4ijHDwQLoQ-03gInUmWx_w' 'report-sample'; report-uri https://ip13.anyhost.it/@http-reporting?csp=report&requestTime=1714503719476538",
        "disposition": "enforce",
        "blocked-uri": "inline",
        "line-number": 2,
        "source-file": "https://ip13.anyhost.it/",
        "status-code": 200,
        "script-sample": "body {\n                        font-fami"
    }

    script-sample gives an indication of what exactly caused the violation.

  1. Oliver Hader commented <span data-processor="relativetime" data-value="2024-04-30T20:13:06+00:00" > 04/30/24, 20:13 </span>

    The patch at https://review.typo3.org/c/Packages/TYPO3.CMS/+/84099 is providing those hashes for the XSLT styles.

    The hash value might be applied statically as well (sha256-d0ax6zoVJBeBpy4l3O2FJ6Y1L4SalCWw2x62uoJH15k=) – but I think this might be forgotten, in case the styles would be adjusted (even changing the formatting, whitespaces, etc. would require a new hash to be generated).

  2. Garvin Hicking commented <span data-processor="relativetime" data-value="2024-06-18T18:29:36+00:00" > 06/18/24, 18:29 </span>

    From dupe report #104125 a suggestion:

    “Maybe by adding a check if CSP is off in the frontend and only then inserting the xsl?”

    which has also been voiced here. The current patch seems to have stalled due to caching / performance implications.

    Personally I do also think the stylesheet isn’t that important to have, and we could just drop it when frontend CSP feature is active, instead of doing all this dynamic processing…?

  3. Oliver Hader commented and changed status Under Review Resolved done 0 % 100 % <span data-processor="relativetime" data-value="2024-10-29T13:30:08+00:00" > 10/29/24, 13:30 </span>

    Applied in changeset commit:937fbfe1365632c9965550fea0c33eb396bea106.