Skip to content

Commit

Permalink
Fix. Remote Calls. RC calling without token fixed. (#438)
Browse files Browse the repository at this point in the history
  • Loading branch information
Glomberg authored Nov 1, 2024
1 parent 74aafb4 commit 9a44273
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions lib/CleantalkSP/Common/RemoteCalls.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ class RemoteCalls
*/
protected $without_token;

protected static $allowedActionsWithoutToken = [
'post_api_key',
];

const COOLDOWN = 10;

/**
Expand All @@ -53,10 +57,20 @@ public static function checkWithoutToken()
{
global $spbc;

$rc_servers = [
'netserv3.cleantalk.org',
'netserv4.cleantalk.org',
];

return ! $spbc->key_is_ok &&
Request::get('spbc_remote_call_action') &&
in_array(Request::get('plugin_name'), array('security', 'spbc')) &&
strpos(IP::resolve(IP::get()), 'cleantalk.org') !== false;
in_array(IP::resolve(IP::get('remote_addr')), $rc_servers, true);
}

private static function isAllowedWithoutToken($rc)
{
return in_array($rc, self::$allowedActionsWithoutToken, true);
}

/**
Expand Down Expand Up @@ -87,9 +101,11 @@ public function process()
// Check API key
if (
($this->state->data['key_is_ok'] !== false) &&
(($token === strtolower(md5($this->state->api_key)) ||
$token === strtolower(hash('sha256', $this->state->api_key))) ||
$this->without_token)
(
( $token === strtolower(md5($this->state->api_key)) ||
$token === strtolower(hash('sha256', $this->state->api_key)) ) ||
( $this->without_token && self::isAllowedWithoutToken($action) )
)
) {
// Flag to let plugin know that Remote Call is running.
$this->state->rc_running = true;
Expand Down

0 comments on commit 9a44273

Please sign in to comment.