From 8caec0eaca9378819dbfd6b4dcdd0bbfc9dc1873 Mon Sep 17 00:00:00 2001 From: AntonV1211 Date: Fri, 13 Feb 2026 15:06:25 +0700 Subject: [PATCH 1/6] Fix. Code. Check RC action --- RemoteCalls.php | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/RemoteCalls.php b/RemoteCalls.php index efb6dd3..01be1b3 100644 --- a/RemoteCalls.php +++ b/RemoteCalls.php @@ -57,11 +57,41 @@ public static function getVariable($name) */ public static function check() { - return - static::getVariable('spbc_remote_call_token') && - static::getVariable('spbc_remote_call_action') && - static::getVariable('plugin_name') && - in_array(static::getVariable('plugin_name'), array('antispam', 'anti-spam', 'apbct')); + if (Get::get('spbc_remote_call_action')) { + Get::get( 'spbc_remote_call_token' ) + ? self::checkWithToken() + : self::checkWithoutToken(); + } + return false; + + } + + public static function checkWithToken() + { + return in_array(Get::get('plugin_name'), array('antispam', 'anti-spam', 'apbct')); + } + + public static function checkWithoutToken() + { + global $apbct; + + $rc_servers = [ + 'netserv3.cleantalk.org', + 'netserv4.cleantalk.org', + ]; + // Resolve IP of the client making the request and verify hostname from it to be in the list of RC servers hostnames + $client_ip = Helper::ipGet('remote_addr'); + $verified_hostname = $client_ip ? Helper::ip__resolve($client_ip) : false; + $is_noc_request = ! $apbct->key_is_ok && + in_array(Get::get('plugin_name'), array('antispam', 'anti-spam', 'apbct')) && + $verified_hostname !== false && + in_array($verified_hostname, $rc_servers, true); + + // no token needs for this action, at least for now + // todo Probably we still need to validate this, consult with analytics team + $is_wp_nonce_request = $apbct->key_is_ok && Get::get('spbc_remote_call_action') === 'get_fresh_wpnonce'; + + return $is_wp_nonce_request || $is_noc_request; } /** From 6b438b57ee6106162a64792b2d9a241327970a46 Mon Sep 17 00:00:00 2001 From: AntonV1211 Date: Fri, 13 Feb 2026 15:37:38 +0700 Subject: [PATCH 2/6] Fix tests --- .gitignore | 1 + RemoteCalls.php | 5 ++--- tests/RemoteCalls/RemoteCallsTest.php | 4 ++-- tests/RemoteCalls/RemoteCallsTestWrongRequest.php | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index b0c31dd..7778af0 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ composer.lock package-lock.json /lib/ +/tests/.phpunit.result.cache diff --git a/RemoteCalls.php b/RemoteCalls.php index 01be1b3..3d49236 100644 --- a/RemoteCalls.php +++ b/RemoteCalls.php @@ -58,13 +58,12 @@ public static function getVariable($name) public static function check() { if (Get::get('spbc_remote_call_action')) { - Get::get( 'spbc_remote_call_token' ) + Get::get('spbc_remote_call_token') ? self::checkWithToken() : self::checkWithoutToken(); } return false; - - } + } public static function checkWithToken() { diff --git a/tests/RemoteCalls/RemoteCallsTest.php b/tests/RemoteCalls/RemoteCallsTest.php index f576cf4..083c96d 100644 --- a/tests/RemoteCalls/RemoteCallsTest.php +++ b/tests/RemoteCalls/RemoteCallsTest.php @@ -8,7 +8,7 @@ class RemoteCallsTest extends TestCase { - public function setUp() + public function setUp(): void { /** @var \Cleantalk\Common\StorageHandler\StorageHandler $storage_handler */ $storage_handler = $this->generateStorageHandlerMockObject(); @@ -44,7 +44,7 @@ private function generateStorageHandlerMockObject() return $mock; } - public function tearDown() + public function tearDown(): void { Request::resetInstance(); } diff --git a/tests/RemoteCalls/RemoteCallsTestWrongRequest.php b/tests/RemoteCalls/RemoteCallsTestWrongRequest.php index 7874d27..73b5f3c 100644 --- a/tests/RemoteCalls/RemoteCallsTestWrongRequest.php +++ b/tests/RemoteCalls/RemoteCallsTestWrongRequest.php @@ -9,7 +9,7 @@ class RemoteCallsTestWrongRequest extends TestCase { - public function setUp() + public function setUp(): void { /** @var \Cleantalk\Common\StorageHandler\StorageHandler $storage_handler */ $storage_handler = $this->generateStorageHandlerMockObject(); @@ -37,7 +37,7 @@ private function generateStorageHandlerMockObject() return $mock; } - public function tearDown() + public function tearDown(): void { Request::resetInstance(); } From 944d536ff51c76b30f850a7e8f6463a08231e2f8 Mon Sep 17 00:00:00 2001 From: AntonV1211 Date: Fri, 13 Feb 2026 16:15:41 +0700 Subject: [PATCH 3/6] Fix. Code. Editing the key receipt --- RemoteCalls.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/RemoteCalls.php b/RemoteCalls.php index 3d49236..8cc5b0a 100644 --- a/RemoteCalls.php +++ b/RemoteCalls.php @@ -57,8 +57,9 @@ public static function getVariable($name) */ public static function check() { - if (Get::get('spbc_remote_call_action')) { - Get::get('spbc_remote_call_token') + if ( + static::getVariable('spbc_remote_call_action')) { + static::getVariable('spbc_remote_call_token') ? self::checkWithToken() : self::checkWithoutToken(); } @@ -67,7 +68,7 @@ public static function check() public static function checkWithToken() { - return in_array(Get::get('plugin_name'), array('antispam', 'anti-spam', 'apbct')); + return in_array(static::getVariable('plugin_name'), array('antispam', 'anti-spam', 'apbct')); } public static function checkWithoutToken() @@ -82,13 +83,13 @@ public static function checkWithoutToken() $client_ip = Helper::ipGet('remote_addr'); $verified_hostname = $client_ip ? Helper::ip__resolve($client_ip) : false; $is_noc_request = ! $apbct->key_is_ok && - in_array(Get::get('plugin_name'), array('antispam', 'anti-spam', 'apbct')) && + in_array(static::getVariable('plugin_name'), array('antispam', 'anti-spam', 'apbct')) && $verified_hostname !== false && in_array($verified_hostname, $rc_servers, true); // no token needs for this action, at least for now // todo Probably we still need to validate this, consult with analytics team - $is_wp_nonce_request = $apbct->key_is_ok && Get::get('spbc_remote_call_action') === 'get_fresh_wpnonce'; + $is_wp_nonce_request = $apbct->key_is_ok && static::getVariable('spbc_remote_call_action') === 'get_fresh_wpnonce'; return $is_wp_nonce_request || $is_noc_request; } From b9294573528af0305d40a3773e0a2c7c2bf4ba8d Mon Sep 17 00:00:00 2001 From: AntonV1211 Date: Fri, 13 Feb 2026 16:30:59 +0700 Subject: [PATCH 4/6] Fix --- RemoteCalls.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/RemoteCalls.php b/RemoteCalls.php index 8cc5b0a..974415d 100644 --- a/RemoteCalls.php +++ b/RemoteCalls.php @@ -57,8 +57,7 @@ public static function getVariable($name) */ public static function check() { - if ( - static::getVariable('spbc_remote_call_action')) { + if (static::getVariable('spbc_remote_call_action')) { static::getVariable('spbc_remote_call_token') ? self::checkWithToken() : self::checkWithoutToken(); From 5e7214515363b51dff18c44312d4951a20ab4fd7 Mon Sep 17 00:00:00 2001 From: AntonV1211 Date: Fri, 13 Feb 2026 17:39:16 +0700 Subject: [PATCH 5/6] Fix naming --- RemoteCalls.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RemoteCalls.php b/RemoteCalls.php index 974415d..2099ea6 100644 --- a/RemoteCalls.php +++ b/RemoteCalls.php @@ -80,7 +80,7 @@ public static function checkWithoutToken() ]; // Resolve IP of the client making the request and verify hostname from it to be in the list of RC servers hostnames $client_ip = Helper::ipGet('remote_addr'); - $verified_hostname = $client_ip ? Helper::ip__resolve($client_ip) : false; + $verified_hostname = $client_ip ? Helper::ipResolve($client_ip) : false; $is_noc_request = ! $apbct->key_is_ok && in_array(static::getVariable('plugin_name'), array('antispam', 'anti-spam', 'apbct')) && $verified_hostname !== false && From 04b8ab730fae83005a6033b1c228cd458dfad0ef Mon Sep 17 00:00:00 2001 From: AntonV1211 Date: Mon, 16 Feb 2026 16:29:44 +0700 Subject: [PATCH 6/6] Fix. Code. Left the option to work only with a token --- RemoteCalls.php | 25 +------------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/RemoteCalls.php b/RemoteCalls.php index 2099ea6..084a673 100644 --- a/RemoteCalls.php +++ b/RemoteCalls.php @@ -60,7 +60,7 @@ public static function check() if (static::getVariable('spbc_remote_call_action')) { static::getVariable('spbc_remote_call_token') ? self::checkWithToken() - : self::checkWithoutToken(); + : false; } return false; } @@ -70,29 +70,6 @@ public static function checkWithToken() return in_array(static::getVariable('plugin_name'), array('antispam', 'anti-spam', 'apbct')); } - public static function checkWithoutToken() - { - global $apbct; - - $rc_servers = [ - 'netserv3.cleantalk.org', - 'netserv4.cleantalk.org', - ]; - // Resolve IP of the client making the request and verify hostname from it to be in the list of RC servers hostnames - $client_ip = Helper::ipGet('remote_addr'); - $verified_hostname = $client_ip ? Helper::ipResolve($client_ip) : false; - $is_noc_request = ! $apbct->key_is_ok && - in_array(static::getVariable('plugin_name'), array('antispam', 'anti-spam', 'apbct')) && - $verified_hostname !== false && - in_array($verified_hostname, $rc_servers, true); - - // no token needs for this action, at least for now - // todo Probably we still need to validate this, consult with analytics team - $is_wp_nonce_request = $apbct->key_is_ok && static::getVariable('spbc_remote_call_action') === 'get_fresh_wpnonce'; - - return $is_wp_nonce_request || $is_noc_request; - } - /** * Execute corresponding method of RemoteCalls if exists *