Skip to content

Commit 31e3b64

Browse files
Copilotskerbis
andauthored
fix(security): Add missing CSP nonce attributes to script tags in box_cssjs.php (#460)
* Initial plan * fix(security): Add missing nonce attributes to all script tags in box_cssjs.php Co-authored-by: skerbis <791247+skerbis@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: skerbis <791247+skerbis@users.noreply.github.com>
1 parent 647a7f8 commit 31e3b64

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

fragments/ConsentManager/box_cssjs.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
$googleConsentModeScriptFile = 'google_consent_mode_v2.js';
5555
}
5656
$googleConsentModeScriptUrl = $addon->getAssetsUrl($googleConsentModeScriptFile);
57-
$googleConsentModeOutput .= ' <script src="' . $googleConsentModeScriptUrl . '" defer></script>' . PHP_EOL;
57+
$googleConsentModeOutput .= ' <script nonce="' . rex_response::getNonce() . '" src="' . $googleConsentModeScriptUrl . '" defer></script>' . PHP_EOL;
5858

5959
// Debug-Script laden wenn Debug-Modus aktiviert UND User im Backend eingeloggt
6060
if (isset($consent_manager->domainInfo['google_consent_mode_debug'])
@@ -65,10 +65,10 @@
6565
// Nur für eingeloggte Backend-Benutzer
6666
if (rex_backend_login::hasSession() && null !== rex::getUser()) {
6767
$debugScriptUrl = $addon->getAssetsUrl('consent_debug.js');
68-
$googleConsentModeOutput .= ' <script src="' . $debugScriptUrl . '" defer></script>' . PHP_EOL;
68+
$googleConsentModeOutput .= ' <script nonce="' . rex_response::getNonce() . '" src="' . $debugScriptUrl . '" defer></script>' . PHP_EOL;
6969

7070
// Debug-Konfiguration für JavaScript verfügbar machen
71-
$googleConsentModeOutput .= ' <script>' . PHP_EOL;
71+
$googleConsentModeOutput .= ' <script nonce="' . rex_response::getNonce() . '">' . PHP_EOL;
7272
$googleConsentModeOutput .= ' window.consentManagerDebugConfig = ' . json_encode([
7373
'mode' => $consent_manager->domainInfo['google_consent_mode_enabled'],
7474
'auto_mapping' => 'auto' === $consent_manager->domainInfo['google_consent_mode_enabled'],
@@ -164,8 +164,8 @@
164164
'mode' => 'opt-in',
165165
];
166166

167-
$consentparams['outputjs'] .= ' <script>var consent_manager_parameters = ' . json_encode($jsConfig, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . ';</script>' . PHP_EOL;
168-
$consentparams['outputjs'] .= ' <script src="' . rex_url::frontendController($_params) . '" id="consent_manager_script" defer></script>' . PHP_EOL;
167+
$consentparams['outputjs'] .= ' <script nonce="' . rex_response::getNonce() . '">var consent_manager_parameters = ' . json_encode($jsConfig, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . ';</script>' . PHP_EOL;
168+
$consentparams['outputjs'] .= ' <script nonce="' . rex_response::getNonce() . '" src="' . rex_url::frontendController($_params) . '" id="consent_manager_script" defer></script>' . PHP_EOL;
169169

170170
// Ausgabe Google Consent Mode v2 (vor allem anderen)
171171
echo $googleConsentModeOutput;

0 commit comments

Comments
 (0)