diff --git a/lib/CleantalkSP/Common/FSWatcher/Service.php b/lib/CleantalkSP/Common/FSWatcher/Service.php index b6bfcb25b..0f073707d 100755 --- a/lib/CleantalkSP/Common/FSWatcher/Service.php +++ b/lib/CleantalkSP/Common/FSWatcher/Service.php @@ -92,11 +92,7 @@ public static function attachJS($buffer, $file_to_get_md5 = null) */ public static function isRC() { - if (isset($_POST['fswatcher_token']) && $_POST['fswatcher_token'] == md5((string)filemtime(__FILE__))) { - return true; - } - - return false; + return static::validateFsWatcherToken(); } /** @@ -163,4 +159,22 @@ public static function getProcessingJournal() $storage = Controller::$storage; return $storage::getProcessingJournal(); } + + /** + * Generates token (aka nonce). + * The $salt must be used obligatorily + * + * @param $salt + * + * @return string + */ + public static function generateFsWatcherToken($salt = '') + { + return md5(filemtime(__FILE__) . $salt); + } + + public static function validateFsWatcherToken() + { + return isset($_POST['fswatcher_token']) && $_POST['fswatcher_token'] === static::generateFsWatcherToken(); + } } diff --git a/lib/CleantalkSP/Common/FSWatcher/View/View.php b/lib/CleantalkSP/Common/FSWatcher/View/View.php index 9a00658f2..6614d9c43 100755 --- a/lib/CleantalkSP/Common/FSWatcher/View/View.php +++ b/lib/CleantalkSP/Common/FSWatcher/View/View.php @@ -4,6 +4,7 @@ use CleantalkSP\Common\FSWatcher\Controller; use CleantalkSP\Common\FSWatcher\Logger; +use CleantalkSP\Common\FSWatcher\Service; class View { @@ -59,8 +60,7 @@ public static function renderSelectors(Phrases $phrases) $html .= ''; $html .= ''; diff --git a/lib/CleantalkSP/SpbctWP/FSWatcher/SpbctWpFSWService.php b/lib/CleantalkSP/SpbctWP/FSWatcher/SpbctWpFSWService.php index 4825f5f91..82aaf8f54 100644 --- a/lib/CleantalkSP/SpbctWP/FSWatcher/SpbctWpFSWService.php +++ b/lib/CleantalkSP/SpbctWP/FSWatcher/SpbctWpFSWService.php @@ -67,22 +67,18 @@ public static function setAllJournalsAsCompleted() $storage::setAllJournalsAsCompleted(); } - /** - * Is ajax call is in process - * - * @return bool - */ - public static function isRC() + public static function attachJS($buffer, $file_to_get_md5 = null) { - if (isset($_POST['fswatcher_token']) && $_POST['fswatcher_token'] == md5((string)filemtime(__FILE__))) { - return true; - } + return parent::attachJS($buffer, __FILE__); + } - return false; + public static function generateFsWatcherToken($salt = '') + { + return wp_create_nonce('spbc_secret_fs_watcher_token'); } - public static function attachJS($buffer, $file_to_get_md5 = null) + public static function validateFsWatcherToken() { - return parent::attachJS($buffer, __FILE__); + return isset($_POST['fswatcher_token']) && spbc_check_ajax_referer('spbc_secret_fs_watcher_token', 'fswatcher_token'); } } diff --git a/lib/CleantalkSP/SpbctWP/FSWatcher/View/View.php b/lib/CleantalkSP/SpbctWP/FSWatcher/View/View.php index 4607d1a49..dfd611da5 100644 --- a/lib/CleantalkSP/SpbctWP/FSWatcher/View/View.php +++ b/lib/CleantalkSP/SpbctWP/FSWatcher/View/View.php @@ -4,6 +4,7 @@ use CleantalkSP\SpbctWP\FSWatcher\SpbctWpFSWController; use CleantalkSP\Common\FSWatcher\View\Phrases; +use CleantalkSP\SpbctWP\FSWatcher\SpbctWpFSWService; class View extends \CleantalkSP\Common\FSWatcher\View\View { @@ -64,8 +65,7 @@ public static function renderSelectors(\CleantalkSP\Common\FSWatcher\View\Phrase $html .= ''; $html .= '