Skip to content

Send a denied Consent Mode update and notify add-ons when consent is withdrawn - #29

Merged
davidperezgar merged 4 commits into
mainfrom
fix/consent-withdrawal-cleanup
Dec 3, 2026
Merged

davidperezgar merged 4 commits into
mainfrom
fix/consent-withdrawal-cleanup

Conversation

@amulero

@amulero amulero commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Improve consent withdrawal and cookie cleanup, while providing generic extension points for add-ons such as FrontConsent PRO.

Base: main. It was stacked on #28, which is now merged; main has been merged into this branch to resolve a readme.md conflict, so the diff only shows this PR's changes.

Findings

Issue Status
Google Analytics may recreate tracking cookies during withdrawal Fixed here
Add-ons are not notified when consent is withdrawn Fixed here
Add-ons cannot customize tracking cookie cleanup Fixed here
A filter must not keep cookies on a full withdrawal Fixed here
A failing filter must not stop the cleanup Fixed here
A filter returning non-string patterns (e.g. [null]) must not block the banner (Codex review) Fixed here
PRO category cookie cleanup Separate PRO PR
PRO partial consent handling Separate PRO PR

Changes

Consent withdrawal

Send a Consent Mode update with all four supported signals set to denied before purging tracking cookies and reloading the page.

Add-on notification

Introduce the frcnCookieConsentWithdrawn document event so add-ons can react to consent withdrawal and clear their own stored consent.

Cookie cleanup extension

Introduce window.frcnCookieNoticeFilterPurgePatterns(patterns) so add-ons can narrow the list of cookies to purge.

  • Not applied on a full withdrawal: every tracking cookie is deleted.
  • If the filter throws or does not return an array of non-empty strings, every tracking cookie is deleted.
  • Existing behavior is preserved when no filter is registered.

FrontConsent Free remains binary and does not introduce consent categories.

Assets and documentation

  • Regenerated the minified JavaScript using npm run build.
  • Documented the new event and filter in readme.md.

Tests

  • CI checks run locally: composer validate, composer lint, composer phpstan, PHPUnit (135/135, before merging main; CI runs it again on this PR) and npm run test:js (49/49, also after merging main).
  • Eight new tests covering Consent Mode update order, the withdrawal event, cookie filtering, full withdrawal and filter failures.
  • Five of them fail without the implementation.
  • Manual browser testing on a local WooCommerce installation with WP Rocket and GTM4WP, with and without FrontConsent PRO active:
    • Consent withdrawal event dispatched.
    • Consent Mode updated before cookie cleanup.
    • Tracking cookies removed before page reload.
    • Removed cookies do not come back after reloading and navigating to another page.
    • Cookie banner displayed again after reload.

Scope

PRO-specific consent handling will be implemented in a separate PR in the PRO repository.

No version bump or changelog changes.

🤖 Generated with Claude Code

amulero and others added 2 commits November 24, 2026 13:42
…tion"

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…withdrawn

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@davidperezgar

Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T15:37:41.797755Z c32ec61 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c32ec615ed

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +81 to +82
if (Array.isArray(filtered)) {
patterns = filtered;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Validate each pattern returned by the browser filter

If an add-on returns an array containing a non-string value, such as [null], this accepts it and later matchesPurgePattern() throws on pattern.charAt(...). For an undecided visitor with any cookie, that exception escapes the initialization-time purge and prevents the consent banner from being revealed or wired, so a malformed optional filter can leave the visitor unable to provide consent. Filter the result to valid strings or fall back to the original patterns when any entry is invalid.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in e7faa52.

purgeTrackingCookies() now only uses the filter's result when it is an array of non-empty strings. Anything else (e.g. [null], numbers, empty strings) is ignored and the full purge list is used, the same fallback as when the filter throws, so matchesPurgePattern() can no longer throw and the page-load purge can't stop the banner from being shown and wired.

Regression test added in tests/js/cookie-notice-purge.test.js: a filter returning [null, '_gid'] on page load no longer throws, every tracking cookie is deleted and the banner's buttons are wired. It fails without the fix. JS tests 49/49, composer lint and composer phpstan clean; .min.js regenerated with npm run build.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Base automatically changed from fix/wp-rocket-delay-js to main November 25, 2026 12:01
@amulero
amulero marked this pull request as ready for review December 2, 2026 16:18
@amulero amulero closed this Dec 2, 2026
@amulero amulero reopened this Dec 2, 2026

@davidperezgar davidperezgar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revisado: la retirada del consentimiento manda el update denied antes del purge, el filtro se ignora en retirada total y valida lo que devuelve, y los tests cubren los casos.


Generated by Claude Code

@davidperezgar
davidperezgar merged commit e2af9d7 into main Dec 3, 2026
10 checks passed
@davidperezgar
davidperezgar deleted the fix/consent-withdrawal-cleanup branch December 3, 2026 07:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants