Issue Bug Closed

#107719Missing CSP nonce value on uncached pages with indexed_search

Sebastian Müller 10/16/25, 10:36 updated 12/02/25, 12:04

Description

Description:

When a page contains an indexed_search plugin (indexedsearch_pi2),
the first visit after flushing all caches does not have any nonce-values in the CSP header.
Later calls do have the proper csp headers.
The Problem occurs since the typo3 upgrade to 13.4.19. If you go back to 13.4.18, the problem does not occur.

Reproduction steps:

  • Have an TYPO3 13.4.19 and typo3/cms-indexed-search installed
  • Enable CSP (inheritDefault: true is enough)
  • add JS to your DefaultLayout so nonce-header will be added
<f:asset.script identifier="hello" useNonce="true">
    console.log('hello');
</f:asset.script>
  • View page, csp-header with nonce is added
  • Add indexed_search plugin indexedsearch_pi2 on page
  • Clear cache
  • view page => nonce is not added and therefor CSP error occurs

Reviews 2

History 610

  1. Florian Schuhmann commented and changed Is Regression 1 <span data-processor="relativetime" data-value="2025-10-16T11:14:19+00:00" > 10/16/25, 11:14 </span>

    I’m experiencing the same behavior even without the indexed_search plugin.
    An uncached page no longer receives a nonce entry. I was able to trace this back to the change in #107613.

    In my case NonceValueSubstitution::substituteNonce is called twice per uncached request.
    1. Call
      • $currentNonce->value = $context['nonce']@ is true ** @!str_contains($context['content'], $context['nonce'])@ is true # Call ** @$currentNonce->value = $context['nonce'] is true
      • !str_contains($context['content'], $context['nonce']) is false
    A cached request produces:
    1. Call
      • $currentNonce->value = $context['nonce']@ is false ** @!str_contains($context['content'], $context['nonce'])@ is false # Call ** @$currentNonce->value = $context['nonce'] is true
      • !str_contains($context['content'], $context['nonce']) is false
  2. Oliver Hader commented <span data-processor="relativetime" data-value="2025-10-19T08:26:21+00:00" > 10/19/25, 08:26 </span>

    Behind the scenes multiple things are happening here in a partially cached state (COA_INT/@USER_INT@):

    • $GLOBALS['TYPO3_REQUEST']->getAttribute('nonce') holds the nonce that is use for compiling the CSP header
    • PageRenderer::updateState() sets the cached nonce value (just the value, not the count) using data from a previously cached state
    • both nonce values are identical, but the counters are not and they are not sharing the same ConsumableNonce instance

    The optimization $currentNonce->value === $context['nonce'] now avoids that the nonce counter (of of the global request object) is incremented.
    For not substituting strings in the content in NonceValueSubstitution this is actually correct – however, it’s fatal for the not incrementing the global nonce counter due having these two different instances of ConsumableNonce as mentioned earlier.

    Thus, there are two approaches to fix this:
    • drop the $currentNonce->value === $context['nonce'] optimization (and possibly having string replace operations that were not necessary, but having the nonce counter increased)
    • rework the caching and PageRenderer::updateState() logic concerning using the same ConsumableNonce instance
  3. Gerrit Code Review pushed patch set 1 for main to change 91160 status Accepted Under Review <span data-processor="relativetime" data-value="2025-10-19T09:08:32+00:00" > 10/19/25, 09:08 </span>

  4. Oliver Hader commented and changed status Under Review Resolved done 0 % 100 % <span data-processor="relativetime" data-value="2025-10-23T11:30:08+00:00" > 10/23/25, 11:30 </span>

    Applied in changeset commit:9da26234439abca38a376ce174f08b7c9bff516b.