PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 6.3.0
Defender Security – Malware Scanner, Login Security & Firewall v6.3.0
6.3.0 6.2.3 6.2.4 6.2.0 6.2.1 6.2.2 6.1.0 5.3.1 5.4.0 5.4.1 5.5.0 5.5.1 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.7.2 5.8.0 5.8.1 5.9.0 6.0.0 6.0.1 3.0.1 3.1.0 All 141 releases
← All changes | src/controller/class-firewall.php +172 -76 5.7.0 → 6.3.0 View file →
@@ -13,9 +13,8 @@
13 13 use WP_Defender\Traits\IP;
14 14 use Calotes\Component\Request;
15 15 use Calotes\Component\Response;
16 16 use Calotes\Helper\Array_Cache;
17 -use WP_Defender\Controller\Dashboard;
18 17 use WP_Defender\Component\Network_Cron_Manager;
19 18 use WP_Defender\Model\Setting\Antibot_Global_Firewall_Setting;
20 19 use WP_Defender\Component\Mail;
21 20 use WP_Defender\Traits\Formats;
@@ -27,9 +26,9 @@
27 26 use WP_Defender\Component\IP\Antibot_Global_Firewall as Antibot_Global_Firewall_Component;
28 27 use WP_Defender\Component\IP\Global_IP as Global_IP_Component;
29 28 use WP_Defender\Component\Blacklist_Lockout;
30 29 use WP_Defender\Component\Http\Remote_Address;
31 -use MaxMind\Db\Reader\InvalidDatabaseException;
30 +use WP_DEFENDER_VENDOR\MaxMind\Db\Reader\InvalidDatabaseException;
32 31 use WP_Defender\Model\Setting\Notfound_Lockout;
33 32 use WP_Defender\Model\Setting\Global_Ip_Lockout;
34 33 use WP_Defender\Model\Setting\User_Agent_Lockout;
35 34 use WP_Defender\Component\Config\Config_Hub_Helper;
@@ -97,9 +96,9 @@
97 96 */
98 97 public function __construct() {
99 98 $this->wpmudev = wd_di()->get( WPMUDEV::class );
100 99
101 - $title = esc_html__( 'Firewall', 'defender-security' );
100 + $title = esc_html__( 'Firewalls', 'defender-security' );
102 101 $this->register_page(
103 102 $this->get_title( $title ),
104 103 $this->slug,
105 104 array( $this, 'main_view' ),
@@ -202,25 +201,69 @@
202 201 return $default_text;
203 202 }
204 203
205 204 /**
206 - * This is for handling request from dashboard.
205 + * Sets up the preset firewall configuration.
207 206 *
208 - * @defender_route
209 - * @return Response
207 + * @param bool $state The feature state.
208 + *
209 + * @return void
210 210 */
211 - public function dashboard_activation() {
212 - $il = wd_di()->get( Login_Lockout_Model::class );
211 + public function preset_firewall( bool $state ) {
212 + // For every lockout.
213 + $ll = wd_di()->get( Login_Lockout_Model::class );
213 214 $nf = wd_di()->get( Notfound_Lockout::class );
214 215 $ua = wd_di()->get( User_Agent_Lockout::class );
215 216
216 - $il->enabled = true;
217 - $il->save();
218 - $nf->enabled = true;
217 + $ll->enabled = $state;
218 + $ll->save();
219 + $nf->enabled = $state;
219 220 $nf->save();
220 - $ua->enabled = true;
221 +
222 + $old_malicious_bot_enabled = $ua->malicious_bot_enabled;
223 + $old_fake_bots_enabled = $ua->fake_bots_enabled;
224 + $ua->enabled = $state;
225 + if ( $state ) {
226 + $ua->malicious_bot_enabled = true;
227 + $ua->fake_bots_enabled = true;
228 + } else {
229 + $ua->malicious_bot_enabled = false;
230 + $ua->fake_bots_enabled = false;
231 + }
221 232 $ua->save();
222 233
234 + if ( $state && ! $old_malicious_bot_enabled ) {
235 + wd_di()->get( Malicious_Bot::class )->rotate_hash();
236 + } elseif ( ! $state ) {
237 + if ( $old_malicious_bot_enabled ) {
238 + wd_di()->get( Malicious_Bot::class )->remove_data();
239 + }
240 + if ( $old_fake_bots_enabled ) {
241 + wd_di()->get( Fake_Bot_Detection::class )->remove_data();
242 + }
243 + }
244 +
245 + Config_Hub_Helper::set_clear_active_flag();
246 + }
247 +
248 + /**
249 + * Enable/disable lockout modules.
250 + *
251 + * @param Request $request The request object.
252 + *
253 + * @return Response
254 + * @defender_route
255 + */
256 + public function toggle_lockout_modules( Request $request ): Response {
257 + $data = $request->get_data(
258 + array(
259 + 'enabled' => array(
260 + 'type' => 'boolean',
261 + ),
262 + )
263 + );
264 + $this->preset_firewall( $data['enabled'] );
265 +
223 266 return new Response( true, $this->to_array() );
224 267 }
225 268
226 269 /**
@@ -249,9 +292,11 @@
249 292 $data['http_ip_header'],
250 293 Firewall_Service::custom_http_headers(),
251 294 true
252 295 )
253 - && ! empty( $data['trusted_proxy_preset'] )
296 + && isset( $data['trusted_proxy_preset'] )
297 + && is_string( $data['trusted_proxy_preset'] )
298 + && '' !== $data['trusted_proxy_preset']
254 299 && $data['trusted_proxy_preset'] !== $this->model->trusted_proxy_preset
255 300 ) {
256 301 $is_preset_update = true;
257 302 }
@@ -349,20 +394,56 @@
349 394 /**
350 395 * Enqueues scripts and styles for this page.
351 396 * Only enqueues assets if the page is active.
352 397 */
353 - public function enqueue_assets() {
398 + public function enqueue_assets(): void {
354 399 if ( ! $this->is_page_active() ) {
355 400 return;
356 401 }
357 402
403 + add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) );
358 404 wp_enqueue_media();
359 405
360 - wp_localize_script( 'def-iplockout', 'iplockout', $this->data_frontend() );
361 - wp_enqueue_script( 'def-iplockout' );
406 + $handle = 'defender-ui-firewalls';
407 + wp_enqueue_script(
408 + $handle,
409 + WP_DEFENDER_BASE_URL . 'assets/js/firewalls-ui.js',
410 + array( 'def-vue', 'def-manifest', 'def-core-ui', 'defender', 'wp-i18n' ),
411 + DEFENDER_VERSION,
412 + true
413 + );
414 + wp_set_script_translations( $handle, 'wpdef' );
415 +
416 + wp_localize_script(
417 + $handle,
418 + 'defenderUIData',
419 + array_merge(
420 + $this->get_shared_data(),
421 + $this->data_frontend()
422 + )
423 + );
424 +
425 + wp_enqueue_style(
426 + $handle,
427 + WP_DEFENDER_BASE_URL . 'assets/css/core-ui.css',
428 + array(),
429 + DEFENDER_VERSION
430 + );
431 +
362 432 $this->enqueue_main_assets();
433 + // Keep this action for backward compatibility with existing hooks.
434 + do_action( 'defender_ip_lockout_action_assets' );
435 + }
363 436
364 - do_action( 'defender_ip_lockout_action_assets' );
437 + /**
438 + * Add a Firewalls page marker class for scoped admin CSS overrides.
439 + *
440 + * @param string $classes Current admin body classes.
441 + *
442 + * @return string
443 + */
444 + public function admin_body_class( string $classes ): string {
445 + return trim( $classes . ' wdf-firewalls-react-page' );
365 446 }
366 447
367 448 /**
368 449 * Renders the preview of lockout screen.
@@ -447,13 +528,10 @@
447 528 'sanitize' => 'sanitize_text_field',
448 529 ),
449 530 )
450 531 );
451 - $maybe_email = $data['user_data'];
452 - if ( empty( $maybe_email ) ) {
453 - return new Response( false, array() );
454 - }
455 - $ips = $this->get_user_ip();
532 + $maybe_email = isset( $data['user_data'] ) ? $data['user_data'] : '';
533 + $ips = $this->get_user_ip();
456 534 // Check if at least one IP is blocked.
457 535 $blocked_ip = $this->service->get_blocked_ip( $ips );
458 536 // If nothing, just return.
459 537 if ( '' === $blocked_ip ) {
@@ -458,8 +536,17 @@
458 536 // If nothing, just return.
459 537 if ( '' === $blocked_ip ) {
460 538 return new Response( false, array() );
461 539 }
540 + // Count every verification attempt and stop before account lookup or side effects when the limit is reached.
541 + if ( $this->check_attempt_counter_by( $blocked_ip ) ) {
542 + return new Response( false, array() );
543 + }
544 +
545 + // Always return the same response for accepted attempts to avoid exposing account existence or role.
546 + if ( ! is_string( $maybe_email ) || '' === trim( $maybe_email ) ) {
547 + return new Response( true, array() );
548 + }
462 549 // Maybe is it a user email?
463 550 $user = get_user_by( 'email', $maybe_email );
464 551 if ( ! is_object( $user ) ) {
465 552 // Maybe is it a username?
@@ -464,21 +551,21 @@
464 551 if ( ! is_object( $user ) ) {
465 552 // Maybe is it a username?
466 553 $user = get_user_by( 'login', $maybe_email );
467 554 if ( ! is_object( $user ) ) {
468 - $this->check_attempt_counter_by( $blocked_ip );
469 -
470 - return new Response( false, array() );
555 + return new Response( true, array() );
471 556 }
472 557 }
473 558 // Send email only for admins.
474 559 if ( ! $this->is_admin( $user ) ) {
475 - // No need to count attempts for existed user but non-admin.
476 - return new Response( false, array() );
560 + return new Response( true, array() );
477 561 }
478 562 // Create Unlockout records.
479 563 $arr_uids = array();
480 564 foreach ( $ips as $ip ) {
565 + if ( Unlockout::has_pending_request( $ip, $user->user_email ) ) {
566 + continue;
567 + }
481 568 // Collect blocked IP's.
482 569 $created_id = wd_di()->get( Unlockout::class )->create( $ip, $user->user_email );
483 570 if ( $created_id ) {
484 571 $arr_uids[] = $created_id;
@@ -484,9 +571,11 @@
484 571 $arr_uids[] = $created_id;
485 572 }
486 573 }
487 574
488 - $this->send_unlock_email( $user->user_email, $user->user_login, $arr_uids );
575 + if ( array() !== $arr_uids ) {
576 + $this->send_unlock_email( $user->user_email, $user->user_login, $arr_uids );
577 + }
489 578
490 579 return new Response( true, array() );
491 580 }
492 581
@@ -526,9 +615,10 @@
526 615 $headers = wd_di()->get( Mail::class )->get_headers(
527 616 defender_noreply_email( 'wd_unlock_noreply_email' ),
528 617 Unlock_Me::SLUG_UNLOCK
529 618 );
530 - $subject = esc_html__( 'Request to Unblock IP Address', 'defender-security' );
619 + $subject = __( 'Request to Unblock IP Address', 'defender-security' );
620 + $subject = wp_specialchars_decode( $subject, ENT_QUOTES );
531 621
532 622 $content_body = $this->render_partial(
533 623 'email/unlockout',
534 624 array(
@@ -667,9 +757,9 @@
667 757 $params['action_send_again'] = add_query_arg( $args, admin_url( 'admin-ajax.php' ) );
668 758
669 759 $params['button_title'] = Unlock_Me::get_feature_title();
670 760 $button_disabled = false;
671 - if ( ! empty( $ips ) ) {
761 + if ( array() !== $ips ) {
672 762 // Get IP's.
673 763 $request_count = get_transient( $this->check_ip_by_remote_addr( $ips[0] ) );
674 764 $button_disabled = false !== $request_count && $request_count >= Unlock_Me::get_attempt_limit();
675 765 }
@@ -728,9 +818,9 @@
728 818 $service_ua->block_user_agent_or_ip( $user_agent, $ip, User_Agent_Component::REASON_BAD_POST );
729 819
730 820 return $service_ua->get_message();
731 821 }
732 - if ( ! empty( $user_agent )
822 + if ( '' !== trim( $user_agent )
733 823 /**
734 824 * Apply additional checks for user agent before determining if it is a bad user agent.
735 825 *
736 826 * @param bool $is_bad_user_agent The result of checking if the user agent is bad.
@@ -853,8 +943,10 @@
853 943 // Remove Fake Bot data.
854 944 wd_di()->get( Fake_Bot_Detection::class )->remove_data();
855 945 // Remove Firewall Logs data.
856 946 wd_di()->get( Firewall_Logs::class )->remove_data();
947 + // Remove WAF data.
948 + wd_di()->get( WAF::class )->remove_data();
857 949 // Clear Trusted Proxy data.
858 950 $trusted_proxy_preset = wd_di()->get( Trusted_Proxy_Preset::class );
859 951 foreach ( array_keys( Firewall_Service::trusted_proxy_presets() ) as $preset ) {
860 952 $trusted_proxy_preset->set_proxy_preset( $preset );
@@ -873,11 +965,11 @@
873 965 *
874 966 * @return array An array of data for the frontend.
875 967 */
876 968 public function data_frontend(): array {
877 - $summary_data = $this->get_summary();
878 969 $user_ip = $this->get_user_ip();
879 970 $http_ip_header_value = $this->get_user_ip_header();
971 + $summary_data = $this->get_summary();
880 972
881 973 $data = array(
882 974 'login' => array(
883 975 'month' => $summary_data['lockout_login_this_month'],
@@ -897,13 +989,8 @@
897 989 'month' => $summary_data['lockout_this_month'],
898 990 'day' => $summary_data['lockout_today'],
899 991 'last_lockout' => $summary_data['lockout_last'],
900 992 'settings' => $this->model->export(),
901 - 'login_lockout' => wd_di()->get( Login_Lockout_Model::class )->enabled,
902 - 'nf_lockout' => wd_di()->get( Notfound_Lockout::class )->enabled,
903 - 'report' => wd_di()->get( Firewall_Report::class )->to_string(),
904 - 'notification_lockout' => 'enabled' === wd_di()->get( Firewall_Notification::class )->status,
905 - 'ua_lockout' => wd_di()->get( User_Agent_Lockout::class )->enabled,
906 993 'user_ip' => implode( ', ', $user_ip ),
907 994 'user_ip_header' => $http_ip_header_value,
908 995 'trusted_proxy_presets' => Firewall_Service::trusted_proxy_presets(),
909 996 'global_ip' => wd_di()->get( \WP_Defender\Controller\Global_Ip::class )->data_frontend(),
@@ -908,8 +995,14 @@
908 995 'trusted_proxy_presets' => Firewall_Service::trusted_proxy_presets(),
909 996 'global_ip' => wd_di()->get( \WP_Defender\Controller\Global_Ip::class )->data_frontend(),
910 997 'hub_connector' => wd_di()->get( Hub_Connector::class )->data_frontend(),
911 998 'antibot' => wd_di()->get( Antibot_Global_Firewall::class )->data_frontend(),
999 + 'waf' => wd_di()->get( WAF::class )->data_frontend(),
1000 + 'loginLockout' => wd_di()->get( Login_Lockout::class )->data_frontend(),
1001 + 'nfLockout' => wd_di()->get( Nf_Lockout::class )->data_frontend(),
1002 + 'uaLockout' => wd_di()->get( UA_Lockout::class )->data_frontend(),
1003 + 'banning' => wd_di()->get( Blacklist::class )->data_frontend(),
1004 + 'logs' => wd_di()->get( Firewall_Logs::class )->data_frontend(),
912 1005 );
913 1006
914 1007 return array_merge( $data, $this->dump_routes_and_nonces() );
915 1008 }
@@ -944,59 +1037,55 @@
944 1037 *
945 1038 * @return array An array of strings.
946 1039 */
947 1040 public function export_strings(): array {
948 - $strings = array();
949 - $is_pro = $this->wpmudev->is_pro();
950 - $firewall_report = new Firewall_Report();
1041 + $strings = array();
951 1042 // Login lockout.
952 1043 $strings[] = Login_Lockout_Model::get_module_name() . ' '
953 - . Login_Lockout_Model::get_module_state( (bool) ( new Login_Lockout_Model() )->enabled );
1044 + . Login_Lockout_Model::get_module_state( ( new Login_Lockout_Model() )->enabled );
954 1045 // Notfound lockout.
955 1046 $strings[] = Notfound_Lockout::get_module_name() . ' '
956 - . Notfound_Lockout::get_module_state( (bool) ( new Notfound_Lockout() )->enabled );
1047 + . Notfound_Lockout::get_module_state( ( new Notfound_Lockout() )->enabled );
957 1048 // Global IP lockout.
958 1049 $strings[] = Global_Ip_Lockout::get_module_name() . ' '
959 - . Global_Ip_Lockout::get_module_state( (bool) ( new Global_Ip_Lockout() )->enabled );
1050 + . Global_Ip_Lockout::get_module_state( ( new Global_Ip_Lockout() )->enabled );
1051 + // AntiBot Global Firewall.
1052 + $strings[] = Antibot_Global_Firewall_Setting::get_module_name() . ' '
1053 + . Antibot_Global_Firewall_Setting::get_module_state( ( new Antibot_Global_Firewall_Setting() )->enabled );
960 1054 // UA lockout.
961 1055 $strings[] = User_Agent_Lockout::get_module_name() . ' '
962 - . User_Agent_Lockout::get_module_state( (bool) ( new User_Agent_Lockout() )->enabled );
1056 + . User_Agent_Lockout::get_module_state( ( new User_Agent_Lockout() )->enabled );
963 1057 // Notifications and reports.
964 1058 if ( 'enabled' === ( new Firewall_Notification() )->status ) {
965 1059 $strings[] = esc_html__( 'Email notifications active', 'defender-security' );
966 1060 }
967 - if ( $is_pro && 'enabled' === $firewall_report->status ) {
968 1061 $strings[] = sprintf(
969 - /* translators: %s: Frequency value. */
970 - esc_html__( 'Email reports sending %s', 'defender-security' ),
971 - $firewall_report->frequency
1062 + /* translators: %s: Html for Pro-tag. */
1063 + esc_html__( 'Email report inactive %s', 'defender-security' ),
1064 + '<span class="sui-tag sui-tag-pro">Pro</span>'
972 1065 );
973 - } elseif ( ! $is_pro ) {
974 1066 $strings[] = sprintf(
975 1067 /* translators: %s: Html for Pro-tag. */
976 - esc_html__( 'Email report inactive %s', 'defender-security' ),
1068 + esc_html__( 'Web Application Firewall (WAF) inactive %s', 'defender-security' ),
977 1069 '<span class="sui-tag sui-tag-pro">Pro</span>'
978 1070 );
979 - }
980 1071
981 1072 return $strings;
982 1073 }
983 1074
984 1075 /**
985 - * Generates configuration strings based on the provided configuration and
986 - * whether the product is a pro version.
1076 + * Generates configuration strings based on the provided configuration.
987 1077 *
988 1078 * @param array $config Configuration data.
989 - * @param bool $is_pro Indicates if the product is a pro version.
990 1079 *
991 1080 * @return array Returns an array of configuration strings.
992 1081 */
993 - public function config_strings( array $config, bool $is_pro ): array {
1082 + public function config_strings( array $config ): array {
994 1083 $strings = array();
995 1084 // Login lockout.
996 1085 if ( isset( $config['login_protection'] ) ) {
997 1086 $strings[] = Login_Lockout_Model::get_module_name() . ' '
998 - . Login_Lockout_Model::get_module_state( (bool) $config['login_protection'] );
1087 + . Login_Lockout_Model::get_module_state( (bool) $config['login_protection'] );
999 1088 }
1000 1089 // NF lockout.
1001 1090 if ( isset( $config['detect_404'] ) ) {
1002 1091 $strings[] = Notfound_Lockout::get_module_name() . ' '
@@ -1006,8 +1095,13 @@
1006 1095 if ( isset( $config['global_ip_list'] ) ) {
1007 1096 $strings[] = Global_Ip_Lockout::get_module_name() . ' '
1008 1097 . Global_Ip_Lockout::get_module_state( (bool) $config['global_ip_list'] );
1009 1098 }
1099 + // AntiBot Global Firewall.
1100 + if ( isset( $config['antibot'] ) ) {
1101 + $strings[] = Antibot_Global_Firewall_Setting::get_module_name() . ' '
1102 + . Antibot_Global_Firewall_Setting::get_module_state( (bool) $config['antibot'] );
1103 + }
1010 1104 // UA lockout.
1011 1105 if ( isset( $config['ua_banning_enabled'] ) ) {
1012 1106 $strings[] = User_Agent_Lockout::get_module_name() . ' '
1013 1107 . User_Agent_Lockout::get_module_state( (bool) $config['ua_banning_enabled'] );
@@ -1015,22 +1109,18 @@
1015 1109 // Notifications.
1016 1110 if ( isset( $config['notification'] ) && 'enabled' === $config['notification'] ) {
1017 1111 $strings[] = esc_html__( 'Email notifications active', 'defender-security' );
1018 1112 }
1019 - // Report.
1020 - if ( $is_pro && 'enabled' === $config['report'] ) {
1021 1113 $strings[] = sprintf(
1022 - /* translators: %s: Frequency value. */
1023 - esc_html__( 'Email reports sending %s', 'defender-security' ),
1024 - $config['report_frequency']
1114 + /* translators: %s: Html for Pro-tag. */
1115 + esc_html__( 'Email report inactive %s', 'defender-security' ),
1116 + '<span class="sui-tag sui-tag-pro">Pro</span>'
1025 1117 );
1026 - } elseif ( ! $is_pro ) {
1027 1118 $strings[] = sprintf(
1028 - /* translators: %s: Html for Pro-tag. */
1029 - esc_html__( 'Email report inactive %s', 'defender-security' ),
1119 + /* translators: %s: Html for Pro-tag. */
1120 + esc_html__( 'Web Application Firewall (WAF) inactive %s', 'defender-security' ),
1030 1121 '<span class="sui-tag sui-tag-pro">Pro</span>'
1031 1122 );
1032 - }
1033 1123
1034 1124 return $strings;
1035 1125 }
1036 1126
@@ -1068,9 +1158,9 @@
1068 1158 time() + 15
1069 1159 );
1070 1160
1071 1161 $clear = get_site_option( 'wpdef_clear_schedule_firewall_cleanup_temp_blocklist_ips', false );
1072 - if ( $clear ) {
1162 + if ( true === $clear ) {
1073 1163 wp_clear_scheduled_hook( 'firewall_cleanup_temp_blocklist_ips' );
1074 1164 }
1075 1165 }
1076 1166
@@ -1085,9 +1175,9 @@
1085 1175 $server = defender_get_data_from_request( null, 's' );
1086 1176 $current_url = set_url_scheme( 'http://' . $server['HTTP_HOST'] . $server['REQUEST_URI'] );
1087 1177 $current_query = wp_parse_url( $current_url, PHP_URL_QUERY );
1088 1178 $current_query = $current_query ?? '';
1089 - $referer_url = ! empty( $server['HTTP_REFERER'] ) ?
1179 + $referer_url = isset( $server['HTTP_REFERER'] ) && '' !== trim( $server['HTTP_REFERER'] ) ?
1090 1180 filter_var( $server['HTTP_REFERER'], FILTER_SANITIZE_URL ) :
1091 1181 '';
1092 1182 $referer_query = wp_parse_url( $referer_url, PHP_URL_QUERY );
1093 1183 $referer_query = $referer_query ?? '';
@@ -1096,12 +1186,12 @@
1096 1186 parse_str( $referer_query, $referer_queries );
1097 1187
1098 1188 if (
1099 1189 ( preg_match( '#^' . network_admin_url() . '#i', $current_url ) &&
1100 - ! empty( $current_queries['page'] ) && $this->slug === $current_queries['page']
1190 + isset( $current_queries['page'] ) && '' !== trim( $current_queries['page'] ) && $this->slug === $current_queries['page']
1101 1191 ) ||
1102 1192 ( preg_match( '#^' . network_admin_url() . '#i', $referer_url ) &&
1103 - ! empty( $referer_queries['page'] ) && $this->slug === $referer_queries['page']
1193 + isset( $referer_queries['page'] ) && '' !== trim( $referer_queries['page'] ) && $this->slug === $referer_queries['page']
1104 1194 )
1105 1195 ) {
1106 1196 // Add action hook here.
1107 1197 add_filter( 'upload_mimes', array( $this, 'extend_mime_types' ) );
@@ -1116,9 +1206,9 @@
1116 1206 *
1117 1207 * @return array
1118 1208 */
1119 1209 public function extend_mime_types( array $types ) {
1120 - if ( empty( $types['csv'] ) ) {
1210 + if ( ! isset( $types['csv'] ) || ! is_string( $types['csv'] ) || '' === trim( $types['csv'] ) ) {
1121 1211 $types['csv'] = 'text/csv';
1122 1212 }
1123 1213
1124 1214 return $types;
@@ -1131,9 +1221,12 @@
1131 1221 * @defender_route
1132 1222 * @since 3.3.0
1133 1223 */
1134 1224 public function empty_lockouts() {
1135 - if ( Lockout_Ip::truncate() ) {
1225 + $ip_deleted = Lockout_Ip::truncate();
1226 + $log_deleted = Lockout_Log::delete_lockout_records();
1227 +
1228 + if ( false !== $ip_deleted && false !== $log_deleted ) {
1136 1229 $this->log( 'Deleted lockout records successfully.', self::FIREWALL_LOG );
1137 1230
1138 1231 return new Response(
1139 1232 true,
@@ -1197,9 +1290,9 @@
1197 1290 */
1198 1291 public function print_emoji_script(): void {
1199 1292 $allowed_pages = array(
1200 1293 $this->slug,
1201 - wd_di()->get( Dashboard::class )->slug,
1294 + wd_di()->get( \WP_Defender\Controller\Dashboard::class )->slug,
1202 1295 );
1203 1296
1204 1297 if ( in_array( HTTP::get( 'page' ), $allowed_pages, true ) ) {
1205 1298 if ( ! function_exists( 'print_emoji_detection_script' ) ) {
@@ -1220,18 +1313,18 @@
1220 1313 public function maybe_lockout_gathered_ips(): void {
1221 1314 $msg = '';
1222 1315 $ips = $this->service->get_user_ip();
1223 1316
1224 - if ( ! empty( $ips ) && is_array( $ips ) ) {
1317 + if ( array() !== $ips ) {
1225 1318 foreach ( $ips as $ip ) {
1226 1319 $result = $this->maybe_lockout( $ip );
1227 - if ( empty( $msg ) && ! empty( $result ) ) {
1320 + if ( '' === $msg && is_string( $result ) && '' !== trim( $result ) ) {
1228 1321 $msg = $result;
1229 1322 }
1230 1323 }
1231 1324 }
1232 1325
1233 - if ( ! empty( $msg ) ) {
1326 + if ( '' !== $msg ) {
1234 1327 $this->actions_for_blocked( $msg, 0, 'blacklist', $ips );
1235 1328 }
1236 1329 }
1237 1330
@@ -1254,9 +1347,9 @@
1254 1347 public function handle_detect_ip_header(): void {
1255 1348 $nonce = defender_get_data_from_request( 'nonce', 'g' );
1256 1349 $nonce_ctx = Smart_Ip_Detection::get_nonce_context();
1257 1350
1258 - if ( empty( $nonce ) || get_transient( $nonce_ctx ) !== $nonce ) {
1351 + if ( ! is_string( $nonce ) || '' === trim( $nonce ) || get_transient( $nonce_ctx ) !== $nonce ) {
1259 1352 wp_send_json_error( __( 'Invalid nonce.', 'defender-security' ) );
1260 1353 }
1261 1354
1262 1355 delete_transient( $nonce_ctx );
@@ -1306,8 +1399,11 @@
1306 1399 'salt' => defender_get_data_from_request( 'salt', 'r' ),
1307 1400 'signature' => defender_get_data_from_request( 'signature', 'r' ),
1308 1401 'number' => defender_get_data_from_request( 'solution', 'r' ),
1309 1402 );
1403 +
1404 + // 'number' should be an integer.
1405 + $captcha_payload['number'] = is_numeric( $captcha_payload['number'] ) ? (int) $captcha_payload['number'] : null;
1310 1406
1311 1407 // Successful verification of captcha.
1312 1408 if ( '0' === $captcha_checkbox && wd_di()->get( Altcha_Handler::class )->verify_solution( $captcha_payload ) ) {
1313 1409 // Reset attempt data for all IPs in a batch.