diff --git a/module/VuFindTheme/src/VuFindTheme/View/Helper/ConcatTrait.php b/module/VuFindTheme/src/VuFindTheme/View/Helper/ConcatTrait.php index 3566adf1a77c0ddde09159b22c43be3f289aa0fe..ed9621575e08c0a4694846ec265f005ff76884b5 100644 --- a/module/VuFindTheme/src/VuFindTheme/View/Helper/ConcatTrait.php +++ b/module/VuFindTheme/src/VuFindTheme/View/Helper/ConcatTrait.php @@ -87,6 +87,20 @@ trait ConcatTrait */ abstract protected function getMinifier(); + /** + * Add a content security policy nonce to the item + * + * @param stdClass $item Item + * + * @return void + * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + protected function addNonce($item) + { + // Default implementation does nothing + } + /** * Set the file path of the link object * @@ -364,7 +378,7 @@ trait ConcatTrait // files, which are stored in a theme-independent cache). $path = $this->getConcatenatedFilePath($group); $item = $this->setResourceFilePath($group['items'][0], $path); - $item->attributes['nonce'] = $this->cspNonce; + $this->addNonce($item); $output[] = parent::itemToString( $item, $indent, $escapeStart, $escapeEnd ); diff --git a/module/VuFindTheme/src/VuFindTheme/View/Helper/HeadLink.php b/module/VuFindTheme/src/VuFindTheme/View/Helper/HeadLink.php index 8cca8d6c3d2c6b96b127166eea3035ad741eedbb..b0fec024d8359f302655186896208a53b569b368 100644 --- a/module/VuFindTheme/src/VuFindTheme/View/Helper/HeadLink.php +++ b/module/VuFindTheme/src/VuFindTheme/View/Helper/HeadLink.php @@ -105,7 +105,7 @@ class HeadLink extends \Laminas\View\Helper\HeadLink $url .= filemtime($details['path']); $item->href = $url; } - $item->attributes['nonce'] = $this->cspNonce; + $this->addNonce($item); return parent::itemToString($item); } diff --git a/module/VuFindTheme/src/VuFindTheme/View/Helper/HeadScript.php b/module/VuFindTheme/src/VuFindTheme/View/Helper/HeadScript.php index 3dc99a74f18141f5f19261ea2f074db722a4e984..1c29964243f6db87799e3c660c7d7561a1df4749 100644 --- a/module/VuFindTheme/src/VuFindTheme/View/Helper/HeadScript.php +++ b/module/VuFindTheme/src/VuFindTheme/View/Helper/HeadScript.php @@ -113,7 +113,7 @@ class HeadScript extends \Laminas\View\Helper\HeadScript } } - $item->attributes['nonce'] = $this->cspNonce; + $this->addNonce($item); return parent::itemToString($item, $indent, $escapeStart, $escapeEnd); } @@ -216,4 +216,16 @@ class HeadScript extends \Laminas\View\Helper\HeadScript } return $data; } + + /** + * Add a nonce to the item + * + * @param stdClass $item Item + * + * @return void + */ + protected function addNonce($item) + { + $item->attributes['nonce'] = $this->cspNonce; + } }