Skip to content

Commit 40a807d

Browse files
committed
Merge branch 'dev' into fix
2 parents adb80cf + 8607739 commit 40a807d

7 files changed

Lines changed: 84 additions & 23 deletions

File tree

composer.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@
2727
"vendor/bin/phpcs --config-set installed_paths vendor/phpcompatibility/php-compatibility",
2828
"vendor/bin/phpcs --standard=tests/.phpcs.xml",
2929
"vendor/bin/psalm --no-cache --config=psalm.xml"
30-
],
31-
"just_phpunit": [
32-
"vendor/bin/phpunit --configuration tests/phpunit.xml --debug"
33-
],
34-
"just_psalm": [
35-
"vendor/bin/psalm --no-cache --config=psalm.xml --debug"
3630
]
3731
},
3832
"config": {

inc/spbc-admin.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,24 +228,25 @@ function spbct_get_tab_data()
228228
switch ($tab_name) {
229229
case 'critical_updates':
230230
wp_send_json(VulnerabilityAlarmView::getTabCriticalUpdatesData());
231-
break;
231+
// no break
232232
case 'fswatcher':
233233
wp_send_json(\CleantalkSP\SpbctWP\FSWatcher\View\View::getReactData($data));
234-
break;
234+
// no break
235235
case 'traffic_control':
236236
wp_send_json(FirewallView::getReactData($data));
237-
break;
237+
// no break
238238
case 'settings_general':
239239
wp_send_json(SettingsGeneralReact::getReactData());
240-
break;
240+
// no break
241241
case 'security_certified':
242242
PscCertifiedPluginsController::ajaxRenderTab();
243243
break;
244244
case 'spbct_settings_overview':
245245
wp_send_json(spbc_field_options_overview_traffic_light());
246-
break;
246+
// no break
247247
default:
248248
wp_send_json_error('Unknown tab');
249+
// no break
249250
}
250251
}
251252

inc/spbc-settings.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3027,7 +3027,6 @@ function spbc_debug_users_pass_check_run()
30273027

30283028
if ($total > 0 && $checked === 0) {
30293029
wp_send_json_error('pwnedpasswords.com API unavailable or no pass hashes in table');
3030-
return;
30313030
}
30323031

30333032
wp_send_json_success(array(

lib/CleantalkSP/SpbctWP/RemoteCalls.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,6 @@ public static function action__scanner__check_dir() // phpcs:ignore PSR1.Methods
370370
$file_infos = Get::getArray('file_infos');
371371
if ( ! is_array($file_infos) || ! $file_infos ) {
372372
wp_send_json(array('error' => 'INVALID_FILE_INFOS'));
373-
return;
374373
}
375374

376375
$results = array();

lib/CleantalkSP/SpbctWP/Variables/AltSessions.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,22 +134,19 @@ public static function setFromRemote($request = null)
134134
'success' => false,
135135
'error' => 'AltSessions: No cookies data provided.'
136136
]);
137-
die();
138137
}
139138

140139
if (empty($nonce)) {
141140
wp_send_json([
142141
'success' => false,
143142
'error' => 'AltSessions: No nonce provided.'
144143
]);
145-
die();
146144
}
147145
if (!wp_verify_nonce($nonce, $action)) {
148146
wp_send_json([
149147
'success' => false,
150148
'error' => 'AltSessions: Nonce verification failed. Please reload the page and try again.'
151149
]);
152-
die();
153150
}
154151

155152
// Remove double slashes
@@ -163,7 +160,6 @@ public static function setFromRemote($request = null)
163160
'success' => false,
164161
'error' => 'AltSessions: Internal JSON error: ' . json_last_error_msg()
165162
]);
166-
die();
167163
}
168164

169165
// Convert array of arrays to object
@@ -218,7 +214,6 @@ public static function setFromRemote($request = null)
218214
'success' => false,
219215
'error' => 'AltSessions: Internal JSON error: ' . json_last_error_msg()
220216
]);
221-
die();
222217
}
223218

224219
// Merge with old values if needed (not implemented here, but can be added)

lib/CleantalkSP/SpbctWP/VulnerabilityAlarm/PscCertifiedPluginsCache.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,34 @@ public static function getInstalledPlugins()
303303
return ['plugins' => $plugins, 'badges' => $badges];
304304
}
305305

306+
/**
307+
* Slug to PSC certificate ID map of the cached certified plugins.
308+
*
309+
* @param array<int, string> $slugs Restrict the map to these slugs, all the cached rows if empty.
310+
*
311+
* @return array<string, string>
312+
*/
313+
public static function getCertificatesMap($slugs = array())
314+
{
315+
$rows = PscCertifiedPluginsCacheRepository::getRowsBySlugs($slugs);
316+
317+
$certificates = [];
318+
319+
foreach ($rows as $row) {
320+
$slug = sanitize_title((string) ($row['slug'] ?? ''));
321+
$badge = self::decodeBadge((string) ($row['badge_data'] ?? ''));
322+
323+
$certificate = (string) ($badge['psc'] ?? '');
324+
325+
if (empty($slug) || empty($certificate) || isset($certificates[$slug])) {
326+
continue;
327+
}
328+
329+
$certificates[$slug] = $certificate;
330+
}
331+
return $certificates;
332+
}
333+
306334
/**
307335
* @return int
308336
*/

lib/CleantalkSP/SpbctWP/VulnerabilityAlarm/VulnerabilityAlarmView.php

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace CleantalkSP\SpbctWP\VulnerabilityAlarm;
44

5+
use CleantalkSP\SpbctWP\LinkConstructor;
56
use CleantalkSP\SpbctWP\VulnerabilityAlarm\Dto\ItemReport;
67
use CleantalkSP\SpbctWP\VulnerabilityAlarm\Dto\PluginReport;
78
use CleantalkSP\SpbctWP\UsersPassCheckModule\UsersPassCheckHandler;
@@ -338,6 +339,37 @@ private static function getPscModules()
338339
return VulnerabilityAlarm::getPSCSafePluginsOnly();
339340
}
340341

342+
/**
343+
* Direct link to the research site report.
344+
*
345+
* The report page of the exact certificate is available by its ID (PSC-2024-26398, CVE-2024-1234).
346+
* If the certificate ID is unknown, the link leads to the list of all the module reports.
347+
*
348+
* @param string $module_slug
349+
* @param string $certificate_id PSC or CVE identifier
350+
* @param string $module_id Research ID of the module report, used as an anchor of the fallback link
351+
*
352+
* @return string
353+
*/
354+
private static function getResearchReportUrl($module_slug = '', $certificate_id = '', $module_id = '')
355+
{
356+
if ( empty($module_slug) ) {
357+
return LinkConstructor::buildSimpleLink(static::RESEARCH_SITE_URL, 'reports/');
358+
}
359+
360+
if ( ! empty($certificate_id) ) {
361+
return LinkConstructor::buildSimpleLink(
362+
static::RESEARCH_SITE_URL,
363+
'reports/search/' . $module_slug . '/' . $certificate_id
364+
);
365+
}
366+
367+
return LinkConstructor::buildSimpleLink(
368+
static::RESEARCH_SITE_URL,
369+
'reports/app/' . $module_slug . (! empty($module_id) ? '#' . $module_id : '')
370+
);
371+
}
372+
341373
public static function getCountOfCurrnetlyVulnerableModules()
342374
{
343375
return count(static::getVulnerablePluginsStatic()) + count(static::getVulnerableThemesStatic());
@@ -460,7 +492,11 @@ public static function getTabCriticalUpdatesData()
460492
'version_from' => !empty($plugin->rs_app_version_min) ? $plugin->rs_app_version_min : '0.0',
461493
'version_to' => !empty($plugin->rs_app_version_max) ? $plugin->rs_app_version_max : 'unknown',
462494
'cve' => !empty($plugin->CVE) ? $plugin->CVE : 'CVE-' . $plugin->id,
463-
'cve_url' => 'https://research.cleantalk.org/reports/app/' . $plugin->slug . '#' . $plugin->id,
495+
'cve_url' => static::getResearchReportUrl(
496+
$plugin->slug,
497+
!empty($plugin->CVE) ? $plugin->CVE : '',
498+
$plugin->id
499+
),
464500
'recommendation' => !empty($plugin->rs_app_version_max) ? 'update' : 'delete',
465501
];
466502
}
@@ -474,26 +510,35 @@ public static function getTabCriticalUpdatesData()
474510
'version_from' => !empty($theme->rs_app_version_min) ? $theme->rs_app_version_min : '0.0',
475511
'version_to' => !empty($theme->rs_app_version_max) ? $theme->rs_app_version_max : 'unknown',
476512
'cve' => !empty($theme->CVE) ? $theme->CVE : 'CVE-' . $theme->id,
477-
'cve_url' => 'https://research.cleantalk.org/reports/app/' . $theme->slug . '#' . $theme->id,
513+
'cve_url' => static::getResearchReportUrl(
514+
$theme->slug,
515+
!empty($theme->CVE) ? $theme->CVE : '',
516+
$theme->id
517+
),
478518
'recommendation' => !empty($theme->rs_app_version_max) ? 'update' : 'delete',
479519
];
480520
}
481521

482522
// PSC
483523
$psc_modules = static::getPscModules();
484-
$psc = array_map(function ($module) {
524+
$psc_certificates = ! empty($psc_modules)
525+
? PscCertifiedPluginsCache::getCertificatesMap(array_column($psc_modules, 'slug'))
526+
: array();
527+
$psc = array_map(function ($module) use ($psc_certificates) {
528+
$certificate = isset($psc_certificates[$module['slug']]) ? $psc_certificates[$module['slug']] : '';
529+
485530
return [
486531
'type' => !empty($module['type']) ? $module['type'] : 'plugin',
487532
'name' => $module['slug'],
488533
'version' => $module['version'],
489534
'psc' => $module['psc'],
490-
'psc_url' => 'https://research.cleantalk.org/reports/app/' . $module['slug'],
535+
'psc_url' => static::getResearchReportUrl($module['slug'], $certificate),
491536
];
492537
}, $psc_modules);
493538

494539
// Legend
495540
$legend = [
496-
'db_link' => 'https://research.cleantalk.org/reports/',
541+
'db_link' => static::getResearchReportUrl(),
497542
];
498543

499544
return [

0 commit comments

Comments
 (0)