Skip to content

Fix. SFW. User agents priority fixed. - #874

Merged
Glomberg merged 7 commits into
devfrom
Fix-SFW-User-agents-priority-fixed-#2-VI
Sep 1, 2026
Merged

Fix. SFW. User agents priority fixed.#874
Glomberg merged 7 commits into
devfrom
Fix-SFW-User-agents-priority-fixed-#2-VI

Conversation

@Glomberg

@Glomberg Glomberg commented Sep 1, 2026

Copy link
Copy Markdown
Member

@codecov

codecov Bot commented Sep 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 5.71429% with 33 lines in your changes missing coverage. Please review.
✅ Project coverage is 30.00%. Comparing base (4624eea) to head (db795ad).
⚠️ Report is 28 commits behind head on dev.

Files with missing lines Patch % Lines
lib/Cleantalk/Common/Firewall.php 0.00% 29 Missing ⚠️
lib/Cleantalk/ApbctWP/Firewall/AntiCrawler.php 50.00% 2 Missing ⚠️
lib/Cleantalk/Common/Firewall/FirewallModule.php 0.00% 2 Missing ⚠️

❌ Your patch check has failed because the patch coverage (5.71%) is below the target coverage (70.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@             Coverage Diff              @@
##                dev     #874      +/-   ##
============================================
+ Coverage     29.19%   30.00%   +0.81%     
- Complexity     6446     6539      +93     
============================================
  Files           287      289       +2     
  Lines         26054    26259     +205     
============================================
+ Hits           7607     7880     +273     
+ Misses        18447    18379      -68     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Pull request overview

This PR adjusts how SpamFireWall (SFW) and related firewall modules account for User-Agent (UA) blacklist/whitelist results when deciding priorities and when to short-circuit further module checks.

Changes:

  • Introduces UA match metadata (ua, ua_id, ua_status) at the Firewall level and passes it into loaded modules.
  • Adds a UA lookup against the UA blacklist table (APBCT_TBL_AC_UA_BL) and uses the result to influence whitelist short-circuiting in Firewall::run().
  • Modifies AntiCrawler UA-deny results to raise priority via is_personal and changes UA-blacklist handling to early-return.

Reviewed changes

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

File Description
lib/Cleantalk/Common/Firewall/FirewallModuleAbstract.php Adds shared user_agent_data storage to firewall modules.
lib/Cleantalk/Common/Firewall/FirewallModule.php Adds setter to inject user_agent_data into modules.
lib/Cleantalk/Common/Firewall.php Fetches UA status from UA BL table and uses it during module execution / whitelisting logic.
lib/Cleantalk/ApbctWP/Firewall/AntiCrawler.php Adjusts UA-check result priority and early-return behavior; updates result structure to optionally mark “personal”.
Suppressed comments (1)

lib/Cleantalk/ApbctWP/Firewall/AntiCrawler.php:303

  • This comment block is now misleading: the code sets early_return to true, so it no longer "continues to cookie check". It also contains typos (e.g., "HardCode", "dined") that make the intent harder to understand.
                // Blacklisted — record but continue to cookie check
                // HardCode - write AC dined by UA as personal: blacklisted user-agent may be only personally
                // `is_personal` makes priority bigger, but we don't have a personal flag in the AC module yet, so this fix is needed
                $is_personal = true;
                return array(
                    'entries'      => array($this->makeResult($current_ip, 'DENY_ANTICRAWLER_UA', $is_personal)),
                    'early_return' => true,
                );

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread lib/Cleantalk/Common/Firewall.php
Comment thread lib/Cleantalk/ApbctWP/Firewall/AntiCrawler.php
Comment thread lib/Cleantalk/Common/Firewall.php Outdated
Comment thread lib/Cleantalk/Common/Firewall.php Outdated
Comment thread lib/Cleantalk/Common/Firewall.php
Glomberg and others added 5 commits September 1, 2026 10:44
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

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

Pull request overview

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

Suppressed comments (2)

Previously missed (1) — in code that hasn't changed since the last review.

lib/Cleantalk/ApbctWP/Firewall/AntiCrawler.php:301

  • These comments are now inconsistent with the behavior (blacklisted UA triggers early_return => true, so it does not continue to the cookie check), and there’s a typo (“dined” -> “denied”). Also $is_personal can be inlined.
                // Blacklisted — record but continue to cookie check
                // HardCode - write AC dined by UA as personal: blacklisted user-agent may be only personally
                // `is_personal` makes priority bigger, but we don't have a personal flag in the AC module yet, so this fix is needed
                $is_personal = true;
                return array(

lib/Cleantalk/Common/Firewall.php:170

  • The whitelist early-exit condition will never trigger when no UA blacklist entry matched, because getUserAgentData() always sets ua_status (null when not found) and (int) null becomes 0. That means whitelisted/trusted requests can continue through other modules and still be blocked unintentionally.
            if (
                $this->isWhitelisted($results) &&
                ( ! isset($this->user_agent_data['ua_status']) || (int) $this->user_agent_data['ua_status'] !== 0 )
            ) {

@Glomberg
Glomberg merged commit 48d67e1 into dev Sep 1, 2026
9 of 10 checks passed
@Glomberg
Glomberg deleted the Fix-SFW-User-agents-priority-fixed-#2-VI branch September 1, 2026 08:22
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.

3 participants