From 1dd90c443a81014fca8099f4623ba6cec7461a3c Mon Sep 17 00:00:00 2001 From: David Cook Date: Wed, 18 Feb 2026 01:11:35 +0000 Subject: [PATCH] Bug 38365: Only get the nonce in templates if CSP is enabled --- Koha/Template/Plugin/Koha.pm | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Koha/Template/Plugin/Koha.pm b/Koha/Template/Plugin/Koha.pm index f98a1392aaa..e32a9e79052 100644 --- a/Koha/Template/Plugin/Koha.pm +++ b/Koha/Template/Plugin/Koha.pm @@ -172,7 +172,12 @@ It should be cached by Koha::Middleware::ContentSecurityPolicy. =cut sub CSPNonce { - return Koha::ContentSecurityPolicy->new->get_nonce; + my $csp = Koha::ContentSecurityPolicy->new(); + my $nonce; + if ( $csp->is_enabled ) { + $nonce = $csp->get_nonce; + } + return $nonce; } 1; -- 2.39.5