Skip to content

Fix. Settings. ct_prev_referer cookie breaks page caching. - #71

Merged
svfcode merged 2 commits into
devfrom
fix/ct_prev_referer-cookie-ttl
Aug 3, 2026
Merged

Fix. Settings. ct_prev_referer cookie breaks page caching.#71
svfcode merged 2 commits into
devfrom
fix/ct_prev_referer-cookie-ttl

Conversation

@svfcode

@svfcode svfcode commented Aug 3, 2026

Copy link
Copy Markdown
Member

Move prev_referer to JS so PHP does not Set-Cookie on every pageview; give ct_cookies_test a 7-day TTL instead of a session cookie.
@svfcode svfcode changed the title Fix: ct_prev_referer cookie breaks page caching Fix. Settings. ct_prev_referer cookie breaks page caching. Aug 3, 2026
@svfcode
svfcode requested a review from Copilot August 3, 2026 05:24

Copilot AI 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.

Pull request overview

This PR adjusts how CleanTalk’s “previous referrer” and cookie-test probe cookies are set/read to avoid PHP-driven Set-Cookie updates that can disrupt page caching, and bumps the extension version to 5.8.1.

Changes:

  • Set ct_prev_referer from JS (document.referrer) instead of PHP, and read it from the unprefixed cookie name in spam checks.
  • Change ct_cookies_test payload and set an explicit lifetime (7 days).
  • Bump extension version from 5.8.0 to 5.8.1 in composer metadata and ACP module info.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
cleantalk/antispam/styles/all/template/cleantalk.js Adds JS-managed ct_prev_referer cookie on pageview.
cleantalk/antispam/model/main_model.php Reads ct_prev_referer without phpBB prefix; revises cookie-test probe cookie behavior/lifetime.
cleantalk/antispam/composer.json Version bump to 5.8.1.
cleantalk/antispam/acp/main_info.php ACP module version bump to 5.8.1.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cleantalk/antispam/model/main_model.php
Comment thread cleantalk/antispam/styles/all/template/cleantalk.js
Only set ct_cookies_test when missing/invalid to avoid Set-Cookie on every hit; clear ct_prev_referer in JS when document.referrer is empty.

Copilot AI 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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

Suppressed comments (1)

cleantalk/antispam/model/main_model.php:308

  • Early-return validation for an existing ct_cookies_test cookie only checks check_value. If a client sends a malformed cookie that has the correct check_value but is missing cookies_names (or it’s not an array), set_cookie() will skip rewriting it, and test_cookie() will later do foreach ($cookie_test['cookies_names'] ...), triggering warnings / incorrect behavior. Validate the cookie structure (including cookies_names being an array) before returning early.
        if ( $this->request->is_set($cookie_key, \phpbb\request\request_interface::COOKIE) ) {
            $existing = json_decode(htmlspecialchars_decode($this->request->variable($cookie_key, '', false, \phpbb\request\request_interface::COOKIE)), true);
            if ( is_array($existing) && isset($existing['check_value']) && $existing['check_value'] === $expected ) {
                return;
            }

@svfcode
svfcode merged commit 6a88dd5 into dev Aug 3, 2026
3 checks passed
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