PluginProbe
Patchstack – WordPress & Plugins Security / 2.3.4
Patchstack – WordPress & Plugins Security v2.3.4
2.3.7 trunk 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.16 2.1.17 2.1.18 2.1.19 2.1.2 2.1.20 2.1.21 2.1.22 2.1.23 2.1.24 2.1.25 2.1.3 2.1.4 2.1.5 2.1.6 All 49 releases
← All changes | includes/rules.php +18 -31 trunk2.3.4 View file →
@@ -32,22 +32,15 @@
32 32 if ( $this->get_option( 'patchstack_license_free', 0 ) == 1 ) {
33 33 return;
34 34 }
35 35
36 - // Check if server is supported and if htaccess modifications are disabled.
37 - if ( get_site_option( 'patchstack_disable_htaccess', 0 ) || ( defined( 'PS_DISABLE_HTACCESS' ) && PS_DISABLE_HTACCESS ) ) {
38 - return;
39 - }
40 -
41 36 $rules = $this->plugin->htaccess->get_firewall_rule_settings();
42 37 $settings = json_encode( $rules );
43 38 $results = $this->plugin->api->post_firewall_rule( [ 'settings' => $settings ] );
44 39
45 - // If no rules returned (empty, or a status code/null from a failed request),
46 - // we assume all settings are turned off. Guard against assigning to a string
47 - // offset, which is a fatal error on PHP 7.1+.
48 - if ( ! is_array( $results ) ) {
49 - $results = [ 'rules' => '' ];
40 + // If no rules returned, we assume all settings are turned off.
41 + if ( empty( $results ) ) {
42 + $results['rules'] = '';
50 43 }
51 44
52 45 // We have rules so apply it to the .htaccess file.
53 46 if ( isset( $results['rules'] ) ) {
@@ -114,31 +107,25 @@
114 107 // Update the counters.
115 108 update_option( 'patchstack_vpatches_present', $vPatchCount );
116 109 update_option( 'patchstack_non_vpatches_present', $ruleCount );
117 110
118 - // Separate the new firewall engine rules from the old ones. Only touch the
119 - // stored whitelists when the API actually returned them, otherwise a partial
120 - // response would wipe the existing whitelist rules.
121 - if ( isset( $results['whitelists'] ) && is_array( $results['whitelists'] ) ) {
122 - $newRules = [];
123 - $oldRules = [];
124 - foreach ( $results['whitelists'] as $rule ) {
125 - if ( isset( $rule['rule_v2'] ) ) {
126 - $rule['rules'] = $rule['rule_v2'];
127 - unset( $rule['rule_v2'] );
128 - $newRules[] = $rule;
129 - } else {
130 - $oldRules[] = $rule;
131 - }
111 + // Separate the new firewall engine rules from the old ones.
112 + $newRules = [];
113 + $oldRules = [];
114 + foreach ( $results['whitelists'] as $rule ) {
115 + if ( isset( $rule['rule_v2'] ) ) {
116 + $rule['rules'] = $rule['rule_v2'];
117 + unset( $rule['rule_v2'] );
118 + $newRules[] = $rule;
119 + } else {
120 + $oldRules[] = $rule;
132 121 }
122 + }
133 123
134 - // Update whitelist rules.
135 - update_option( 'patchstack_whitelist_rules', json_encode( $oldRules ), true );
136 - update_option( 'patchstack_whitelist_rules_v3', json_encode( $newRules ), true );
137 - }
124 + // Update whitelist rules.
125 + update_option( 'patchstack_whitelist_rules', json_encode( $oldRules ), true );
126 + update_option( 'patchstack_whitelist_rules_v3', json_encode( $newRules ), true );
138 127
139 128 // Update the whitelisted keys.
140 - if ( isset( $results['whitelist_keys'] ) ) {
141 - update_option( 'patchstack_whitelist_keys_rules', json_encode( $results['whitelist_keys'] ), true );
142 - }
129 + update_option( 'patchstack_whitelist_keys_rules', json_encode( $results['whitelist_keys'] ), true );
143 130 }
144 131 }