Skip to content

"Reject All" does not revoke previously granted consent #55

@codeuxius

Description

@codeuxius

Describe the bug

When clicking "Reject All", optional cookie categories that were previously accepted (or manually ticked) remain enabled. The button doesn't actually uncheck them before saving the consent settings.

To Reproduce

Prerequisites: Have at least one optional cookie category configured (e.g. analytics, marketing, performance).

  1. Clear all cookies for the site
  2. Open the cookie consent banner
  3. Click "Accept All" — optional categories are now enabled
  4. Re-open the cookie consent banner
  5. Click "Reject All"
  6. Check the cookie value — optional categories are still true

Expected behavior

Clicking "Reject All" should set all optional categories to false, leaving only strictly_necessary as true.

Additional context

The issue is in resources/js/scripts.js. The handleRejectOptionalCookies() function (lines 232-234) calls getConsentSettings(false, "strictly_necessary"):

// lines 232-234
function handleRejectOptionalCookies() {
    handleCookieConsent(getConsentSettings(false, "strictly_necessary"));
}

// lines 236-242
function getConsentSettings(acceptAll = false, requiredCategory = null) {
    const consent = {};
    document.querySelectorAll(".cookie-category").forEach((checkbox) => {
        consent[checkbox.id] = acceptAll || checkbox.id === requiredCategory || checkbox.checked;
    });
    return consent;
}

The problem is || checkbox.checked at the end of line 239. When rejecting:

  • acceptAll is false
  • checkbox.id === requiredCategory is false for optional categories (only true for strictly_necessary)
  • checkbox.checked is true (checkbox was ticked previously)

So false || false || true evaluates to true, and the optional category remains enabled.

A simple fix would be to uncheck all optional checkboxes before building the consent object:

function handleRejectOptionalCookies() {
    document.querySelectorAll(".cookie-category").forEach((checkbox) => {
        if (checkbox.id !== "strictly_necessary") {
            checkbox.checked = false;
        }
    });
    handleCookieConsent(getConsentSettings(false, "strictly_necessary"));
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions