PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 5.8.1
Defender Security – Malware Scanner, Login Security & Firewall v5.8.1
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
defender-security / src / component / security-tweaks / class-protect-information.php

class-protect-information.php in Defender Security – Malware Scanner, Login Security & Firewall 5.8.1, at src/component/security-tweaks/class-protect-information.php

120 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Manages the protection against information disclosure by configuring server settings.
4 *
5 * @package WP_Defender\Component\Security_Tweaks
6 */
7
8 namespace WP_Defender\Component\Security_Tweaks;
9
10 use WP_Error;
11 use WP_Defender\Component\Security_Tweaks\Servers\Server;
12
13 /**
14 * Class Protect_Information
15 */
16 class Protect_Information extends Abstract_Security_Tweaks {
17
18 /**
19 * Slug identifier for the component.
20 *
21 * @var string
22 */
23 public string $slug = 'protect-information';
24
25 /**
26 * Check whether the issue has been resolved or not.
27 *
28 * @return bool
29 */
30 public function check() {
31 return Server::create( Server::get_current_server() )->from( $this->slug )->check();
32 }
33
34 /**
35 * Here is the code for processing, if the return is true, we add it to resolve list, WP_Error if any error.
36 *
37 * @param string $current_server The current server software being used.
38 *
39 * @return bool|WP_Error
40 */
41 public function process( $current_server ) {
42 if ( 'apache' === $current_server || 'litespeed' === $current_server ) {
43 // Because the Prevent_PHP tweak uses the 'process' method too.
44 return Server::create( $current_server )->from( $this->slug )->process( false );
45 } else {
46
47 return Server::create( $current_server )->from( $this->slug )->process();
48 }
49 }
50
51 /**
52 * This is for un-do stuff that has been done in @process.
53 *
54 * @param string|null $current_server The current server software being used.
55 *
56 * @return bool|WP_Error
57 */
58 public function revert( $current_server = null ) {
59 if ( is_null( $current_server ) ) {
60 $current_server = Server::get_current_server();
61 }
62
63 return Server::create( $current_server )->from( $this->slug )->revert();
64 }
65
66 /**
67 * Shield up.
68 *
69 * @return bool
70 */
71 public function shield_up() {
72 return true;
73 }
74
75 /**
76 * Retrieve the tweak's label.
77 *
78 * @return string
79 */
80 public function get_label(): string {
81 return esc_html__( 'Prevent Information Disclosure', 'defender-security' );
82 }
83
84 /**
85 * Get the error reason.
86 *
87 * @return string
88 */
89 public function get_error_reason(): string {
90 return esc_html__( 'You don\'t have information disclosure protection active.', 'defender-security' );
91 }
92
93 /**
94 * Return a summary data of this tweak.
95 *
96 * @return array
97 */
98 public function to_array(): array {
99 return array(
100 'slug' => $this->slug,
101 'title' => $this->get_label(),
102 'errorReason' => $this->get_error_reason(),
103 'successReason' => esc_html__(
104 'You\'ve automatically enabled information disclosure protection.',
105 'defender-security'
106 ),
107 'misc' => array(
108 'active_server' => Server::get_current_server(),
109 'apache_rules' => Server::create( 'apache' )->from( $this->slug )->get_rules_for_instruction(),
110 'nginx_rules' => Server::create( 'nginx' )->from( $this->slug )->get_rules(),
111 ),
112 'blk_description' => esc_html__(
113 'Often servers are incorrectly configured, and can allow an attacker to get access to sensitive files like your config, .htaccess and backup files. We will automatically add an .htaccess file to your root folder to action this fix.',
114 'defender-security'
115 ),
116 'bulk_title' => esc_html__( 'Information Disclosure', 'defender-security' ),
117 );
118 }
119 }
120