PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 5.7.2
Defender Security – Malware Scanner, Login Security & Firewall v5.7.2
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-prevent-php.php

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

112 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Prevents PHP execution in directories that should not execute PHP.
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 * Prevents PHP execution in directories that should not execute PHP.
15 */
16 class Prevent_PHP extends Abstract_Security_Tweaks {
17
18 /**
19 * Identifier for the security tweak.
20 *
21 * @var string
22 */
23 public string $slug = 'prevent-php-executed';
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 server on which to apply the configuration.
38 *
39 * @return bool|WP_Error
40 */
41 public function process( $current_server ) {
42 return Server::create( $current_server )->from( $this->slug )->process();
43 }
44
45 /**
46 * This is for un-do stuff that has be done in @process.
47 *
48 * @param string|null $current_server The server on which to apply the configuration.
49 *
50 * @return bool|WP_Error
51 */
52 public function revert( $current_server = null ) {
53 if ( is_null( $current_server ) ) {
54 $current_server = Server::get_current_server();
55 }
56
57 return Server::create( $current_server )->from( $this->slug )->revert();
58 }
59
60 /**
61 * Shield up.
62 *
63 * @return bool
64 */
65 public function shield_up() {
66 return true;
67 }
68
69 /**
70 * Retrieve the tweak's label.
71 *
72 * @return string
73 */
74 public function get_label(): string {
75 return esc_html__( 'Prevent PHP Execution', 'defender-security' );
76 }
77
78 /**
79 * Get the error reason.
80 *
81 * @return string
82 */
83 public function get_error_reason(): string {
84 return esc_html__( 'PHP execution is currently allowed in all directories.', 'defender-security' );
85 }
86
87 /**
88 * Return a summary data of this tweak.
89 *
90 * @return array
91 */
92 public function to_array(): array {
93 return array(
94 'slug' => $this->slug,
95 'title' => $this->get_label(),
96 'errorReason' => $this->get_error_reason(),
97 'successReason' => esc_html__( 'You\'ve disabled PHP execution, good stuff.', 'defender-security' ),
98 'misc' => array(
99 'active_server' => Server::get_current_server(),
100 'apache_rules' => Server::create( 'apache' )->from( $this->slug )->get_rules_for_instruction(),
101 'nginx_rules' => Server::create( 'nginx' )->from( $this->slug )->get_rules(),
102 'wp_content_dir' => WP_CONTENT_DIR,
103 ),
104 'bulk_description' => esc_html__(
105 'By default, a plugin/theme vulnerability could allow a PHP file to get uploaded into your site\'s directories and in turn execute harmful scripts that can wreak havoc on your website. We will disable PHP execution for you.',
106 'defender-security'
107 ),
108 'bulk_title' => esc_html__( 'PHP Execution', 'defender-security' ),
109 );
110 }
111 }
112