| @@ -92,13 +92,10 @@ | ||
| 92 | 92 | $model->log = esc_html__( 'Locked out due to attempted login with banned user agent', 'defender-security' ); |
| 93 | 93 | break; |
| 94 | 94 | } |
| 95 | 95 | $model->save(); |
| 96 | - // The 'defender_notify' hook doesn't work, so send notify directly. | |
| 97 | - $module = wd_di()->get( Firewall_Notification::class ); | |
| 98 | - if ( $module->check_options( $model ) ) { | |
| 99 | - $module->send( $model ); | |
| 100 | - } | |
| 96 | + // Notify directly because the 'defender_notify' hook isn't registered yet at firewall-time. | |
| 97 | + wd_di()->get( Firewall_Notification::class )->notify_lockout( $model ); | |
| 101 | 98 | } |
| 102 | 99 | |
| 103 | 100 | /** |
| 104 | 101 | * Queue hooks when this class init. |
| @@ -126,9 +123,9 @@ | ||
| 126 | 123 | $allowlist = str_replace( '#', '\#', $this->model->get_lockout_list( 'allowlist' ) ); |
| 127 | 124 | $allowlist_regex_pattern = '#' . implode( '|', $allowlist ) . '#i'; |
| 128 | 125 | $allowlist_match = preg_match( $allowlist_regex_pattern, $user_agent ); |
| 129 | 126 | |
| 130 | - if ( count( $allowlist ) > 0 && ! empty( $allowlist_match ) ) { | |
| 127 | + if ( count( $allowlist ) > 0 && $allowlist_match > 0 ) { | |
| 131 | 128 | return false; |
| 132 | 129 | } |
| 133 | 130 | |
| 134 | 131 | $blocklist = str_replace( '#', '\#', $this->model->get_all_selected_blocklist_ua() ); |
| @@ -134,9 +131,9 @@ | ||
| 134 | 131 | $blocklist = str_replace( '#', '\#', $this->model->get_all_selected_blocklist_ua() ); |
| 135 | 132 | $blocklist_regex_pattern = '#' . implode( '|', $blocklist ) . '#i'; |
| 136 | 133 | $blocklist_match = preg_match( $blocklist_regex_pattern, $user_agent ); |
| 137 | 134 | |
| 138 | - if ( count( $blocklist ) > 0 && ! empty( $blocklist_match ) ) { | |
| 135 | + if ( count( $blocklist ) > 0 && $blocklist_match > 0 ) { | |
| 139 | 136 | return true; |
| 140 | 137 | } |
| 141 | 138 | |
| 142 | 139 | return false; |
| @@ -147,9 +144,9 @@ | ||
| 147 | 144 | * |
| 148 | 145 | * @return string The block message. |
| 149 | 146 | */ |
| 150 | 147 | public function get_message(): string { |
| 151 | - return ! empty( $this->model->message ) | |
| 148 | + return '' !== $this->model->message | |
| 152 | 149 | ? $this->model->message |
| 153 | 150 | : esc_html__( 'You have been blocked from accessing this website.', 'defender-security' ); |
| 154 | 151 | } |
| 155 | 152 | |
| @@ -188,9 +185,9 @@ | ||
| 188 | 185 | * @return string |
| 189 | 186 | */ |
| 190 | 187 | public function sanitize_user_agent(): string { |
| 191 | 188 | $user_agent = defender_get_data_from_request( 'HTTP_USER_AGENT', 's' ); |
| 192 | - if ( empty( $user_agent ) ) { | |
| 189 | + if ( '' === $user_agent ) { | |
| 193 | 190 | return ''; |
| 194 | 191 | } |
| 195 | 192 | |
| 196 | 193 | $user_agent = apply_filters( 'wd_current_user_agent', $user_agent ); |
| @@ -206,15 +203,15 @@ | ||
| 206 | 203 | * @param string $user_agent The user agent of the request. |
| 207 | 204 | * |
| 208 | 205 | * @return bool Returns true if the headers are considered bad, false otherwise. |
| 209 | 206 | */ |
| 210 | - public function is_bad_post( $user_agent ): bool { | |
| 207 | + public function is_bad_post( string $user_agent ): bool { | |
| 211 | 208 | $server = defender_get_data_from_request( null, 's' ); |
| 212 | 209 | |
| 213 | 210 | return true === $this->model->empty_headers |
| 214 | 211 | && 'POST' === $server['REQUEST_METHOD'] |
| 215 | - && empty( $user_agent ) | |
| 216 | - && empty( $server['HTTP_REFERER'] ); | |
| 212 | + && '' === $user_agent | |
| 213 | + && ( ! isset( $server['HTTP_REFERER'] ) || '' === $server['HTTP_REFERER'] ); | |
| 217 | 214 | } |
| 218 | 215 | |
| 219 | 216 | /** |
| 220 | 217 | * Verifies the format and usability of an import file for User Agent Lockout settings. |
| @@ -278,9 +275,9 @@ | ||
| 278 | 275 | } |
| 279 | 276 | |
| 280 | 277 | $user_agent_key = $this->model->get_access_status( $user_agent ); |
| 281 | 278 | |
| 282 | - if ( ! empty( $user_agent_key[0] ) ) { | |
| 279 | + if ( isset( $user_agent_key[0] ) && '' !== $user_agent_key[0] ) { | |
| 283 | 280 | $status_text = $this->lockout_ip_model->get_access_status_text( $user_agent_key[0] ); |
| 284 | 281 | } |
| 285 | 282 | |
| 286 | 283 | return $status_text; |
| @@ -305,8 +302,9 @@ | ||
| 305 | 302 | 'dotbot' => 'DotBot (Moz)', |
| 306 | 303 | 'mj12bot' => 'MJ12Bot (Majestic)', |
| 307 | 304 | 'ahrefsbot' => 'AhrefsBot', |
| 308 | 305 | 'semrushbot' => 'SEMrushBot', |
| 306 | + 'thinkbot' => 'Thinkbot', | |
| 309 | 307 | ), |
| 310 | 308 | ); |
| 311 | 309 | } |
| 312 | 310 | |
| @@ -346,13 +344,13 @@ | ||
| 346 | 344 | public static function get_script_presets(): array { |
| 347 | 345 | return array( |
| 348 | 346 | self::PYTHON_REQUESTS_KEY => array( |
| 349 | 347 | 'label' => 'Python Script', |
| 350 | - 'desc' => __( '( This will block all requests from python-requests/* agent )', 'defender-security' ), | |
| 348 | + 'desc' => __( '(blocks python-requests/* agent)', 'defender-security' ), | |
| 351 | 349 | ), |
| 352 | 350 | self::GO_HTTP_CLIENT_KEY => array( |
| 353 | - 'label' => 'Go Http Clients', | |
| 354 | - 'desc' => __( '( This will block all requests from Go-http-client/* agent )', 'defender-security' ), | |
| 351 | + 'label' => 'Go HTTP Clients', | |
| 352 | + 'desc' => __( '(blocks Go-http-client/* agent)', 'defender-security' ), | |
| 355 | 353 | ), |
| 356 | 354 | ); |
| 357 | 355 | } |
| 358 | 356 | |
| @@ -382,7 +380,7 @@ | ||
| 382 | 380 | unset( $arr_source[ $key ] ); |
| 383 | 381 | } |
| 384 | 382 | } |
| 385 | 383 | |
| 386 | - return ! empty( $arr_source ) ? array_values( $arr_source ) : array(); | |
| 384 | + return is_array( $arr_source ) && array() !== $arr_source ? array_values( $arr_source ) : array(); | |
| 387 | 385 | } |
| 388 | 386 | } |