#107719Missing CSP nonce value on uncached pages with indexed_search
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
Related issues 1
History 610
-
Florian Schuhmann changed Related to #107613 <span data-processor="relativetime" data-value="2025-10-16T11:11:32+00:00" > 10/16/25, 11:11 </span>
-
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>
-
Oliver Hader changed status
NewAccepted <span data-processor="relativetime" data-value="2025-10-17T16:18:47+00:00" > 10/17/25, 16:18 </span> -
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 headerPageRenderer::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
ConsumableNonceinstance
The optimization
Thus, there are two approaches to fix this:$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 inNonceValueSubstitutionthis is actually correct – however, it’s fatal for the not incrementing the global nonce counter due having these two different instances ofConsumableNonceas mentioned earlier.- 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 sameConsumableNonceinstance
-
Gerrit Code Review pushed patch set 1 for main to change 91160 status
AcceptedUnder Review <span data-processor="relativetime" data-value="2025-10-19T09:08:32+00:00" > 10/19/25, 09:08 </span> -
Gerrit Code Review pushed patch set 2 for main to change 91160 <span data-processor="relativetime" data-value="2025-10-19T09:12:05+00:00" > 10/19/25, 09:12 </span>
-
Gerrit Code Review pushed patch set 3 for main to change 91160 <span data-processor="relativetime" data-value="2025-10-19T17:08:07+00:00" > 10/19/25, 17:08 </span>
-
Gerrit Code Review pushed patch set 1 for 13.4 to change 91167 <span data-processor="relativetime" data-value="2025-10-20T10:01:09+00:00" > 10/20/25, 10:01 </span>
-
Oliver Hader commented and changed status
Under ReviewResolved done0 %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.
-
Benni Mack changed status
ResolvedClosed <span data-processor="relativetime" data-value="2025-12-02T12:04:30+00:00" > 12/02/25, 12:04 </span>
I’m experiencing the same behavior even without the indexed_search plugin.
In my case NonceValueSubstitution::substituteNonce is called twice per uncached request.An uncached page no longer receives a nonce entry. I was able to trace this back to the change in #107613.
- Call
A cached request produces:$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$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