Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion inc/admin-bar.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ function spbc_admin__admin_bar__add_child_nodes($wp_admin_bar)
'title' => '<a>'
. '<span>' . __('Admins online:', 'security-malware-firewall') . '</span>'
. '&nbsp;<b class="spbc-admin_bar--user_counter">' . $spbc->counter__admins_online . '</b>'
. '<i class="spbc-icon-help-circled" title="' . __('Shows amount of currently logged in administrators. Updates every 10 seconds.', 'security-malware-firewall') . '"></i>'
. '<i class="spbc-icon-help-circled" title="' . __('Shows amount of currently logged in administrators. Updates every 15 seconds.', 'security-malware-firewall') . '"></i>'
. '</a>',
));

Expand Down
6 changes: 3 additions & 3 deletions inc/spbc-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ function spbc_admin_init()
add_filter('manage_users_columns', 'spbc_users_list_pass_check_column');
add_action('wp_ajax_spbc_check_pass_leak', [UsersPassCheckHandler::class, 'checkPassLeak']);
}

// Sync disallow file edit setting with FileEditorDisabler
FileEditorDisabler::syncDisallowFileEditBySettings($spbc->settings);
}

/**
Expand Down Expand Up @@ -975,9 +978,6 @@ function spbc_set_malware_scan_warns()

$triggers_has_dangerous = DBTriggerService::countTriggersStorage();

//// Sync disallow file edit setting with FileEditorDisabler
FileEditorDisabler::syncDisallowFileEditBySettings($spbc->settings, $critical_count);

$spbc->data['display_scanner_warnings'] = array(
'critical' => $critical_count,
'signatures' => $signatures_count,
Expand Down
12 changes: 11 additions & 1 deletion inc/spbc-auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,17 @@ function spbc_fix_error_messages($error_msg)

function spbc_is_user_logged_in()
{
return (bool) preg_grep("/wordpress_logged_in/", array_keys($_COOKIE));
if (function_exists('wp_validate_auth_cookie')) {
foreach ($_COOKIE as $name => $value) {
if (strpos($name, 'wordpress_logged_in_') === 0) {
$user_id = wp_validate_auth_cookie($value, 'logged_in');
if ($user_id) {
return true;
}
}
}
}
return false;
}

/**
Expand Down
6 changes: 4 additions & 2 deletions inc/spbc-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -3420,16 +3420,18 @@ function spbc_list_table__get_args_by_type($table_type)

switch ($table_type) {
case 'links':
$domain = Post::getString('domain');
$domain = esc_sql($domain);
$args = array(
'id' => 'spbc_tbl__scanner__outbound_links',
'sql' => array(
'table' => SPBC_TBL_SCAN_LINKS,
'get_array' => false,
'where' => ' WHERE domain = "' . Post::getString('domain') . '"',
'where' => ' WHERE domain = "' . $domain . '"',
),
'order_by' => array('domain' => 'asc'),
'html_before' =>
sprintf(__('Links for <b>%s</b> domain.', 'security-malware-firewall'), Post::getString('domain')) . ' '
sprintf(__('Links for <b>%s</b> domain.', 'security-malware-firewall'), esc_html($domain)) . ' '
. sprintf(__('%sSee all domains%s', 'security-malware-firewall'), '<a href="javascript://" onclick="spbcScannerSwitchTable(this, \'outbound_links\');">', '</a>')
. '<br /><br />',
'func_data_prepare' => 'spbc_field_scanner__prepare_data__links',
Expand Down
726 changes: 360 additions & 366 deletions js/public/spbct-react-bundle.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions lib/CleantalkSP/Common/DB.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ abstract public function fetchAll($query = false, $response_type = false);
*/
public function isTableExists($table_name)
{
$table_name = preg_replace('/[^a-zA-Z0-9_]/', '', (string) $table_name);
return (bool) $this->execute('SHOW TABLES LIKE "' . $table_name . '"');
}
}
35 changes: 29 additions & 6 deletions lib/CleantalkSP/Common/Helpers/IP.php
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,9 @@ public static function calculateMaskForIPs($ip, $mask_start, $mask_end)
*/
public static function resolve($ip)
{
if (!self::validate($ip)) {
// Validate IP first
$ip_version = self::validate($ip);
if (!$ip_version) {
return false;
}

Expand All @@ -554,20 +556,41 @@ public static function resolve($ip)
return false;
}

// Forward DNS lookup (A/AAAA records) - verify the hostname points back to the IP
$forward_ips = gethostbynamel($hostname);
// Forward DNS lookup - use dns_get_record() to support both IPv4 (A) and IPv6 (AAAA) records
$record_type = ($ip_version === 'v6') ? DNS_AAAA : DNS_A;
$ip_field = ($ip_version === 'v6') ? 'ipv6' : 'ip';

$records = @dns_get_record($hostname, $record_type);

// If forward lookup fails, we can't verify
if (!$forward_ips) {
if (empty($records)) {
return false;
}

// Extract IPs from DNS records
$forward_ips = array();
foreach ($records as $record) {
if (isset($record[$ip_field])) {
$forward_ips[] = $record[$ip_field];
}
}

if (empty($forward_ips)) {
return false;
}

// Check if the original IP is in the list of IPs the hostname resolves to
if (in_array($ip, $forward_ips, true)) {
if ($ip_version === 'v6') {
$normalized_ip = self::normalizeIPv6($ip);
foreach ($forward_ips as $forward_ip) {
if (self::normalizeIPv6($forward_ip) === $normalized_ip) {
return $hostname;
}
}
} elseif (in_array($ip, $forward_ips, true)) {
return $hostname;
}

// FCrDNS verification failed - possible PTR spoofing attempt
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@ protected function needToShow()
{
global $spbc, $pagenow;

$no_wpconfig_error = !defined('SPBC_WPCONFIG_ERROR') || !constant('SPBC_WPCONFIG_ERROR');
return (
isset($spbc->settings['misc_disable_file_editor']) &&
$spbc->settings['misc_disable_file_editor'] == 2 &&
$no_wpconfig_error &&
is_admin() &&
$pagenow === 'index.php' &&
current_user_can('administrator') &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ public function __construct(AdminBannersHandler $banners_handler)
protected function needToShow()
{
global $spbc;
$no_wpconfig_error = !defined('SPBC_WPCONFIG_ERROR') || !constant('SPBC_WPCONFIG_ERROR');

return (
isset($spbc->settings['misc_disable_file_editor']) &&
$spbc->settings['misc_disable_file_editor'] == 2 &&
$no_wpconfig_error &&
is_admin() &&
isset($_GET['page']) && $_GET['page'] === 'spbc' &&
current_user_can('administrator') &&
Expand Down

This file was deleted.

38 changes: 20 additions & 18 deletions lib/CleantalkSP/SpbctWP/AdminBannersModule/AdminBannersHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use CleantalkSP\SpbctWP\AdminBannersModule\AdminBanners\AdminBannerWrongKey;
use CleantalkSP\SpbctWP\AdminBannersModule\AdminBanners\AdminBannerEmptyKey;
use CleantalkSP\SpbctWP\AdminBannersModule\AdminBanners\AdminBannerCriticalFilesWarning;
use CleantalkSP\SpbctWP\AdminBannersModule\AdminBanners\AdminBannerWpConfigError;
use CleantalkSP\SpbctWP\AdminBannersModule\AdminBanners\AdminBannerFileEditorDashboard;
use CleantalkSP\SpbctWP\AdminBannersModule\AdminBanners\AdminBannerFileEditorSettings;
use CleantalkSP\SpbctWP\AdminBannersModule\AdminBanners\AdminBannerPassLeak;
Expand Down Expand Up @@ -68,7 +67,6 @@ public function __construct(State $spbc)
AdminBannerEmptyKey::class,
AdminBannerReview::class,
AdminBannerCriticalFilesWarning::class,
AdminBannerWpConfigError::class,
AdminBannerFileEditorDashboard::class,
AdminBannerFileEditorSettings::class,
AdminBannerPassLeak::class,
Expand Down Expand Up @@ -116,12 +114,25 @@ public function dismissBanner()
{
global $spbc;

// this code snipped need to handle closing banner by non-admin user
// `spbc_check_ajax_referer` pass requests only for admin user
// but password leaks banners will be closed by another user roles into admin page
// so we need to use `check_ajax_referer` instead of `spbc_check_ajax_referer` for this
// @ToDo `spbc_check_ajax_referer` have to be able to check nonce not for only admin users
if ( strpos(Post::getString('banner_id'), 'spbc_passleak') !== false ) {
$banner_id = Sanitize::cleanTextField(Post::getString('banner_id'));

if ( ! $banner_id || strpos($banner_id, 'spbc_') !== 0 ) {
wp_send_json_error(esc_html__('Wrong request.', 'security-malware-firewall'));
}

// Validate format: spbc_<banner_name>_<user_id> and extract user_id
if ( ! preg_match('/^spbc_\w+_(\d+)$/', $banner_id, $matches) ) {
wp_send_json_error(esc_html__('Wrong request.', 'security-malware-firewall'));
}

if ( !isset($matches[1]) || $matches[1] != $this->getUserId() ) {
wp_send_json_error(esc_html__('Wrong request.', 'security-malware-firewall'));
}

// Password leak banners can be closed by non-admin users (Author+),
// but only nonce + logged-in check is needed for those.
// All other banners require admin capabilities.
if ( strpos($banner_id, 'spbc_passleak') === 0 ) {
/** @psalm-suppress ForbiddenCode */
if (!check_ajax_referer('spbc_secret_nonce', 'security')) {
wp_send_json_error(esc_html__('Wrong request.', 'security-malware-firewall'));
Expand All @@ -130,16 +141,7 @@ public function dismissBanner()
spbc_check_ajax_referer('spbc_secret_nonce', 'security');
}

$banner_id = Post::getString('banner_id'); // validation is done next line

if ( ! $banner_id ) {
wp_send_json_error(esc_html__('Wrong request.', 'security-malware-firewall'));
}

$banner_id = Sanitize::cleanTextField($banner_id);
$current_date = current_time('Y-m-d');

if ( update_option($banner_id, $current_date) ) {
if ( update_option($banner_id, current_time('Y-m-d')) ) {
if ( strpos($banner_id, 'spbc_review') !== false ) {
$api_update = API::methodUserDataUpdate($spbc->data['user_token'], json_encode(['show_review' => 0]));
if ( isset($api_update['error']) ) {
Expand Down
3 changes: 2 additions & 1 deletion lib/CleantalkSP/SpbctWP/CleantalkSettingsTemplates.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,9 @@ public function resetOptions()
$spbc->data['current_settings_template_id'] = null;
$spbc->data['current_settings_template_name'] = null;
$spbc->save('data');
$spbc->save('settings');

return $spbc->save('settings');
return true;
}

public static function settingsTemplatesValidateApiResponse($template_id, $template_get_result)
Expand Down
4 changes: 0 additions & 4 deletions lib/CleantalkSP/SpbctWP/Deactivator.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,6 @@ public static function deactivation($network, $do_log_on_errors = false)
// Removing the role of an external technical specialist
remove_role('tech_freelancer');

// Deleting the block with the constant DISALLOW_FILE_EDIT from wp-config.php when deactivating
$file_editor_settings = ['misc_disable_file_editor' => 0];
\CleantalkSP\SpbctWP\FileEditorDisabler\FileEditorDisabler::syncDisallowFileEditBySettings($file_editor_settings);

return self::$deactivation_result;
}

Expand Down
Loading