Skip to content

Commit

Permalink
Fix. Code. Code style and psalm fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
Glomberg committed Nov 22, 2023
1 parent a0cbf23 commit fee8f5c
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 34 deletions.
8 changes: 4 additions & 4 deletions inc/spbc-scanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -1855,11 +1855,11 @@ function spbc_scanner_analysis_log_delete_from_log($direct_call = false)

if ( is_array($file_ids) ) {
// Validate if the ID is hash (SQL-clear)
$file_ids_clean = array_map( function($id) {
if ( \Cleantalk\ApbctWP\Validate::isHash($id) ) {
return $id;
$file_ids_clean = array_map(function ($_id) {
if ( \CleantalkSP\Common\Validate::isHash($_id) ) {
return $_id;
}
}, $file_ids );
}, $file_ids);
}

$output = array('error' => false);
Expand Down
47 changes: 26 additions & 21 deletions inc/spbc-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ function spbc_admin_add_page()
spbc_settings__register();
}

/**
* @return void
* @psalm-suppress ComplexFunction
* @ToDo The function need to be refactored and `psalm-suppress` removed
*/
function spbc_settings__register()
{
global $spbc, $wp_version;
Expand Down Expand Up @@ -2147,6 +2152,7 @@ function spbc_field_traffic_control_logs__prepare_data(&$table)
break;
case 'DENY_BY_BFP':
$status = '<span class="spbcRed">' . __('Blocked by BruteForce protection system', 'security-malware-firewall') . '</span>';
break;
// WAF
case 'DENY_BY_WAF_XSS':
$status = '<span class="spbcRed">' . __('Blocked by Web Application Firewall: XSS attack detected.', 'security-malware-firewall') . '</span>';
Expand Down Expand Up @@ -2363,15 +2369,13 @@ function spbc_field_scanner__prepare_data__files(&$table)

if ( !empty($row->status) ) {
if ( $row->status === 'DENIED_BY_CT' ) {
$cloud_status = '<span class="spbcRed">' . __('File hash', 'security-malware-firewall') . ':[' . esc_html($row->full_hash) . ']' . '</span>';
unset($row->actions['send']);
unset($row->actions['view_bad']);
}
}

if ( !empty($row->status) ) {
if ( $row->status === 'DENIED_BY_CT' ) {
$cloud_status = '<span class="spbcRed">' . __('File hash', 'security-malware-firewall') . ':[' . esc_html($row->full_hash) . ']' . '</span>';
unset($row->actions['send']);
unset($row->actions['view_bad']);
}
Expand Down Expand Up @@ -2454,11 +2458,10 @@ function spbc_field_scanner__prepare_data__files(&$table)
// collecting all kinds of code
$all_unique_weak_spots = array();
foreach ($weak_spots['DENIED_HASH'] as $_string => $weak_spot_in_string) {
$all_unique_weak_spots[] = $weak_spot_in_string[0];
$all_unique_weak_spots[] = $weak_spot_in_string[0];
}
$all_unique_weak_spots = array_unique($all_unique_weak_spots);
foreach ($all_unique_weak_spots as $weak_spot_in_string) {

$ws_string .= '<p style="margin: 0;"><span class="spbcRed"><i setting="hash_' . str_replace(' ', '_', $weak_spot_in_string) . '" class="spbc_long_description__show spbc-icon-help-circled"></i> Hash: </span>'
. 'denied';

Expand All @@ -2473,7 +2476,6 @@ function spbc_field_scanner__prepare_data__files(&$table)
}
$all_unique_weak_spots = array_unique($all_unique_weak_spots);
foreach ($all_unique_weak_spots as $weak_spot_in_string) {

$ws_string .= '<p style="margin: 0;"><span class="spbcRed"><i setting="danger_' . str_replace(' ', '_', $weak_spot_in_string) . '" class="spbc_long_description__show spbc-icon-help-circled"></i> Danger: </span>'
. (strlen($weak_spot_in_string) > 30
? substr($weak_spot_in_string, 0, 30) . '...'
Expand Down Expand Up @@ -5017,37 +5019,40 @@ function spbc_settings_field__secfw__get_ip__get_description()
{
$ip = IP::get();

return sprintf('Your detected IP address is %s',
'<a href="https://cleantalk.org/my-ip/'.$ip.'" target="_blank">'.$ip.'</a>'
return sprintf(
'Your detected IP address is %s',
'<a href="https://cleantalk.org/my-ip/' . $ip . '" target="_blank">' . $ip . '</a>'
);
}

function spbc_settings_field__secfw__get_ip__get_labels () {
function spbc_settings_field__secfw__get_ip__get_labels()
{
$available_header = array(
2 => array('slug' => 'remote_addr', 'name' => 'Remote Addr'),
3 => array('slug' => 'x_forwarded_for', 'name' => 'X-Forwarder-For'),
4 => array('slug' => 'x_real_ip', 'name' => 'X-Real-Ip'),
5 => array('slug' => 'incapsula', 'name' => 'Incap-Client-Ip'),
6 => array('slug' => 'ico_x_forwarded_for', 'name' => 'Ico-X-Forwarded-For'),
7 => array('slug' => 'stackpath', 'name' => 'X-Sp-Forwarded-Ip'),
8 => array('slug' => 'x_forwarded_by', 'name' => 'X-Client-Ip'),
9 => array('slug' => 'sucury', 'name' => 'X-Sucuri-Clientip'),
2 => array('slug' => 'remote_addr', 'name' => 'Remote Addr'),
3 => array('slug' => 'x_forwarded_for', 'name' => 'X-Forwarder-For'),
4 => array('slug' => 'x_real_ip', 'name' => 'X-Real-Ip'),
5 => array('slug' => 'incapsula', 'name' => 'Incap-Client-Ip'),
6 => array('slug' => 'ico_x_forwarded_for', 'name' => 'Ico-X-Forwarded-For'),
7 => array('slug' => 'stackpath', 'name' => 'X-Sp-Forwarded-Ip'),
8 => array('slug' => 'x_forwarded_by', 'name' => 'X-Client-Ip'),
9 => array('slug' => 'sucury', 'name' => 'X-Sucuri-Clientip'),
10 => array('slug' => 'ezoic', 'name' => 'X-Middleton-Ip'),
11 => array('slug' => 'gtranslate', 'name' => 'X-Gt-Viewer-Ip'),
12 => array('slug' => 'cloud_flare', 'name' => 'Cf-Connecting-Ip'),
13 => array('slug' => 'ovh', 'name' => 'Remote-Ip'),
);
$options = array();
$options[] = array('val' => 1, 'label' => __('Auto', 'security-malware-firewall'),);
$options = array();
$options[] = array('val' => 1, 'label' => __('Auto', 'security-malware-firewall'),);

foreach ( $available_header as $key => $header ) {
$ip = IP::get($header['slug'], [], true);
IP::get($header['slug'], [], true);
$option_value = $header['name'];
$option_value .= isset(IP::getInstance()->ips_stored[$header['slug']])
? ' ('. IP::getInstance()->ips_stored[$header['slug']] .')'
? ' (' . IP::getInstance()->ips_stored[$header['slug']] . ')'
: ' (not provided)';
$options[] = array('val' => $key, 'label' => $option_value);
$options[] = array('val' => $key, 'label' => $option_value);
}

return $options;
}

Expand Down
3 changes: 1 addition & 2 deletions lib/CleantalkSP/SpbctWP/Firewall/WafBlocker.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

class WafBlocker extends FirewallModule
{

public $module_name = 'WafBlocker';

protected $is_logged_in = false;
Expand Down Expand Up @@ -39,7 +38,7 @@ public function check()
md5_ip = \'' . $md5_ip . '\' AND
log_type = 2 AND
' . $rand . ';';
$result= $this->db->fetch($query, OBJECT);
$result = $this->db->fetch($query, OBJECT);

if ( isset($result->total_count) && $result->total_count > $this->waf_blocker_limit ) {
$results[] = new Result(
Expand Down
2 changes: 1 addition & 1 deletion lib/CleantalkSP/SpbctWP/Scanner/ScannerQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -1294,7 +1294,7 @@ public function signature_analysis($status = 'UNKNOWN,MODIFIED,OK,INFECTED', $of
if ( $weak_spots !== 'NULL' ) {
// Collect signatures triggered counts
if ( isset($result->weak_spots['SIGNATURES']) && is_array($result->weak_spots['SIGNATURES']) ) {
foreach($result->weak_spots['SIGNATURES'] as $signature_ids) {
foreach ( $result->weak_spots['SIGNATURES'] as $signature_ids ) {
$signature_idx = $spbc->data['scanner']['signatures_found'];
foreach ( $signature_ids as $signature_id ) {
$signature_idx[$signature_id] = ! empty($signature_idx[$signature_id])
Expand Down
1 change: 1 addition & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<file name="security-malware-firewall.php" />
<directory name="lib" />
<ignoreFiles allowMissingFiles="true">
<directory name="backups/" />
<directory name="lib/CleantalkSP/Fpdf/" />
<directory name="node_modules/" />
<directory name="lib/CleantalkSP/Common/Scanner/HeuristicAnalyser/tests/" />
Expand Down
11 changes: 5 additions & 6 deletions security-malware-firewall.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,11 @@ function spbc_change_author_name($link, $_author_id, $_author_nicename)
}

//Password-protected pages also uses wp-login page, we should not break it
if ( $spbc->settings['login_page_rename__enabled']) {
if (Get::get('action') === 'postpass') {
require ABSPATH . 'wp-includes/pluggable.php';
require ABSPATH . 'wp-login.php';
}
if ( $spbc->settings['login_page_rename__enabled'] ) {
if ( Get::get('action') === 'postpass' ) {
require ABSPATH . 'wp-includes/pluggable.php';
require ABSPATH . 'wp-login.php';
}

new RenameLoginPage(
$spbc->settings['login_page_rename__name'],
Expand Down Expand Up @@ -510,7 +510,6 @@ function spbc_firewall__check()
$firewall->loadFwModule($waf_blocker);
}
$firewall->loadFwModule(new WAF($waf_params));

}

//todo This rewrite could break permalinks, need to implement new logic
Expand Down
1 change: 1 addition & 0 deletions tests/.phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<exclude-pattern>tests/*</exclude-pattern>
<exclude-pattern>vendor/*</exclude-pattern>
<exclude-pattern>fw_files/*</exclude-pattern>
<exclude-pattern>backups/*</exclude-pattern>
<exclude-pattern>lib/CleantalkSP/Common/Scanner/HeuristicAnalyser/Vendors/*</exclude-pattern>
<arg name="exclude" value="PSR12.ControlStructures.ControlStructureSpacing"/>
<arg value="n"/>
Expand Down

0 comments on commit fee8f5c

Please sign in to comment.