Skip to content

Commit 1c42613

Browse files
fix: encode consent cookie value; always show details on openConsentPreferences
- encodeURIComponent/decodeURIComponent in setCookie/getCookie so JSON characters (quotes, commas) don't violate RFC 6265 cookie-value rules - showCustomizeOptions() now always sets display=block instead of toggling; clicking the footer 'Cookie Preferences' link while banner is open would previously hide the details panel instead of reliably showing it
1 parent e769ef7 commit 1c42613

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

EssentialCSharp.Web/wwwroot/js/consent-manager.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ class ConsentManager {
180180
showCustomizeOptions() {
181181
const details = document.getElementById('consent-details');
182182
if (details) {
183-
details.style.display = details.style.display === 'none' ? 'block' : 'none';
183+
details.style.display = 'block';
184184

185185
// Load current preferences into checkboxes
186186
document.getElementById('consent-analytics').checked =
@@ -394,7 +394,7 @@ class ConsentManager {
394394
const expires = new Date();
395395
expires.setTime(expires.getTime() + (days * 24 * 60 * 60 * 1000));
396396
const secure = window.location.protocol === 'https:' ? ';Secure' : '';
397-
document.cookie = `${name}=${value};expires=${expires.toUTCString()};path=/;SameSite=Lax${secure}`;
397+
document.cookie = `${name}=${encodeURIComponent(value)};expires=${expires.toUTCString()};path=/;SameSite=Lax${secure}`;
398398
}
399399

400400
deleteCookie(name) {
@@ -408,7 +408,7 @@ class ConsentManager {
408408
for (let i = 0; i < ca.length; i++) {
409409
let c = ca[i];
410410
while (c.charAt(0) === ' ') c = c.substring(1, c.length);
411-
if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);
411+
if (c.indexOf(nameEQ) === 0) return decodeURIComponent(c.substring(nameEQ.length, c.length));
412412
}
413413
return null;
414414
}

0 commit comments

Comments
 (0)