Nonce 

The nonce request attribute is related to Content Security Policy.

It is always available in backend context and only in frontend context, if the according feature is enabled.

One can retrieve the nonce like this:

// use TYPO3\CMS\Core\Security\ContentSecurityPolicy\ConsumableNonce

/** @var ConsumableNonce|null $nonce */
$nonceAttribute = $this->request->getAttribute('nonce');
if ($nonceAttribute instanceof ConsumableNonce) {
    $nonce->consumeInline(Directive::ScriptSrcElem); // inline script
    $nonce->consumeStatic(Directive::StyleSrcElem);  // static style
}
Copied!

Changed in version 13.4.20

Since TYPO3 v13.4.20 the ConsumableNonce class does not inherit from ConsumableString anymore.