From 34597eaa00acac362907abb5e098494f1c855df7 Mon Sep 17 00:00:00 2001 From: datorik Date: Fri, 31 Jul 2026 17:32:45 +0300 Subject: [PATCH 1/3] Code.Malware Scanner.File synchronization --- .../SpbctWP/Scanner/ScanRepository.php | 21 ++++++++++++++ lib/CleantalkSP/SpbctWP/Sync.php | 29 +++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/lib/CleantalkSP/SpbctWP/Scanner/ScanRepository.php b/lib/CleantalkSP/SpbctWP/Scanner/ScanRepository.php index 7e3428926..788f5699b 100644 --- a/lib/CleantalkSP/SpbctWP/Scanner/ScanRepository.php +++ b/lib/CleantalkSP/SpbctWP/Scanner/ScanRepository.php @@ -35,6 +35,27 @@ public static function getPendingQueueFiles() ); } + /** + * Get fast hashes of the files known to the cloud analysis + * @return array + */ + public static function getCloudAnalysisFilesFastHashes() + { + global $wpdb; + + $files = $wpdb->get_results( + 'SELECT fast_hash FROM ' . SPBC_TBL_SCAN_FILES . ' WHERE pscan_file_id IS NOT NULL', + ARRAY_A + ); + + $fast_hashes = array(); + foreach ( $files as $file ) { + $fast_hashes[] = $file['fast_hash']; + } + + return $fast_hashes; + } + /** * Get file info by fast_hash * @return array|null diff --git a/lib/CleantalkSP/SpbctWP/Sync.php b/lib/CleantalkSP/SpbctWP/Sync.php index 5bfb2268b..349b1bc40 100644 --- a/lib/CleantalkSP/SpbctWP/Sync.php +++ b/lib/CleantalkSP/SpbctWP/Sync.php @@ -3,6 +3,8 @@ namespace CleantalkSP\SpbctWP; use CleantalkSP\SpbctWP\AdjustToEnvironmentModule\AdjustToEnvironmentHandler; +use CleantalkSP\SpbctWP\Scanner\ScannerAjaxEndpoints; +use CleantalkSP\SpbctWP\Scanner\ScanRepository; use CleantalkSP\SpbctWP\Settings\FilesScanPathExclusion; class Sync @@ -17,6 +19,7 @@ class Sync 'settings_exclusions' => 'Handling exclusions...', 'adjust_env' => 'Adjusting environment...', 'vulnerability_check' => 'Running vulnerability check...', + 'analysis_log_update' => 'Updating cloud analysis verdicts...', 'finalize' => 'Sync end...', ); @@ -101,6 +104,7 @@ public static function run() self::stepSettingsExclusions(); self::stepAdjustEnv(); self::stepVulnerabilityCheck(); + self::stepAnalysisLogUpdate($account_is_ok); $out = array( 'success' => true, @@ -179,6 +183,9 @@ public static function runCurrentStep() case 'vulnerability_check': self::stepVulnerabilityCheck(); break; + case 'analysis_log_update': + self::stepAnalysisLogUpdate($account_is_ok); + break; case 'finalize': self::stepFinalize(); @@ -392,6 +399,28 @@ private static function stepVulnerabilityCheck() Cron::updateTask('check_vulnerabilities', 'spbc_security_check_vulnerabilities', 86400, time()); } + /** + * Pull actual cloud verdicts for the scan results files. + * The cloud verdict may be changed after the file processing is done, + * so the files with the final verdict have to be re-checked too. + * + * @param bool $account_is_ok + */ + private static function stepAnalysisLogUpdate($account_is_ok) + { + if ( ! $account_is_ok || ! is_main_site() ) { + return; + } + + $file_ids = ScanRepository::getCloudAnalysisFilesFastHashes(); + + if ( empty($file_ids) ) { + return; + } + + ScannerAjaxEndpoints::checkFilesAnalysisStatus(true, $file_ids); + } + private static function stepFinalize() { global $spbc; From 1ef34878b2d3fc873b14a4765178ec6528054ffa Mon Sep 17 00:00:00 2001 From: Aleksandr Banins Date: Fri, 7 Aug 2026 15:35:38 +0300 Subject: [PATCH 2/3] Show errors Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- lib/CleantalkSP/SpbctWP/Sync.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/CleantalkSP/SpbctWP/Sync.php b/lib/CleantalkSP/SpbctWP/Sync.php index 349b1bc40..38b27fef5 100644 --- a/lib/CleantalkSP/SpbctWP/Sync.php +++ b/lib/CleantalkSP/SpbctWP/Sync.php @@ -408,6 +408,8 @@ private static function stepVulnerabilityCheck() */ private static function stepAnalysisLogUpdate($account_is_ok) { + global $spbc; + if ( ! $account_is_ok || ! is_main_site() ) { return; } @@ -418,7 +420,13 @@ private static function stepAnalysisLogUpdate($account_is_ok) return; } - ScannerAjaxEndpoints::checkFilesAnalysisStatus(true, $file_ids); + $result = ScannerAjaxEndpoints::checkFilesAnalysisStatus(true, $file_ids); + + if ( ! empty($result['error']) ) { + $spbc->error_add('analysis_log_update', $result); + } else { + $spbc->error_delete('analysis_log_update'); + } } private static function stepFinalize() From 4781eb755b545c7de40a5bcc58c1729264eec412 Mon Sep 17 00:00:00 2001 From: Aleksandr Banins Date: Fri, 7 Aug 2026 15:37:07 +0300 Subject: [PATCH 3/3] Code optimization Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- lib/CleantalkSP/SpbctWP/Scanner/ScanRepository.php | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/lib/CleantalkSP/SpbctWP/Scanner/ScanRepository.php b/lib/CleantalkSP/SpbctWP/Scanner/ScanRepository.php index 788f5699b..de85655e4 100644 --- a/lib/CleantalkSP/SpbctWP/Scanner/ScanRepository.php +++ b/lib/CleantalkSP/SpbctWP/Scanner/ScanRepository.php @@ -43,17 +43,10 @@ public static function getCloudAnalysisFilesFastHashes() { global $wpdb; - $files = $wpdb->get_results( - 'SELECT fast_hash FROM ' . SPBC_TBL_SCAN_FILES . ' WHERE pscan_file_id IS NOT NULL', - ARRAY_A + return (array) $wpdb->get_col( + 'SELECT DISTINCT fast_hash FROM ' . SPBC_TBL_SCAN_FILES + . ' WHERE pscan_file_id IS NOT NULL AND fast_hash IS NOT NULL AND fast_hash <> ""' ); - - $fast_hashes = array(); - foreach ( $files as $file ) { - $fast_hashes[] = $file['fast_hash']; - } - - return $fast_hashes; } /**