Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix. Remote Calls. RC calling without token fixed. #438

Merged
merged 1 commit into from
Nov 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading