← All changes
|
jetpack_vendor/automattic/jetpack-waf/src/class-compatibility.php
+47
-4
13.7.2
→
16.3-beta
View file →
| @@ -16,8 +16,48 @@ | ||
| 16 | 16 | */ |
| 17 | 17 | class Waf_Compatibility { |
| 18 | 18 | |
| 19 | 19 | /** |
| 20 | + * Returns the name for the IP allow list enabled/disabled option. | |
| 21 | + * | |
| 22 | + * @since 0.22.0 | |
| 23 | + * | |
| 24 | + * @return string | |
| 25 | + */ | |
| 26 | + private static function get_ip_allow_list_enabled_option_name() { | |
| 27 | + /** | |
| 28 | + * Patch: bootstrap script generated prior to 0.17.0 may have autoloaded Waf_Rules_Manager class during standalone mode execution. | |
| 29 | + * | |
| 30 | + * @see peb6dq-2HL-p2 | |
| 31 | + */ | |
| 32 | + if ( ! defined( 'Waf_Rules_Manager::IP_ALLOW_LIST_ENABLED_OPTION_NAME' ) ) { | |
| 33 | + return 'jetpack_waf_ip_allow_list_enabled'; | |
| 34 | + } | |
| 35 | + | |
| 36 | + return Waf_Rules_Manager::IP_ALLOW_LIST_ENABLED_OPTION_NAME; | |
| 37 | + } | |
| 38 | + | |
| 39 | + /** | |
| 40 | + * Returns the name for the IP block list enabled/disabled option. | |
| 41 | + * | |
| 42 | + * @since 0.22.0 | |
| 43 | + * | |
| 44 | + * @return string | |
| 45 | + */ | |
| 46 | + private static function get_ip_block_list_enabled_option_name() { | |
| 47 | + /** | |
| 48 | + * Patch: bootstrap script generated prior to 0.17.0 may have autoloaded Waf_Rules_Manager class during standalone mode execution. | |
| 49 | + * | |
| 50 | + * @see peb6dq-2HL-p2 | |
| 51 | + */ | |
| 52 | + if ( ! defined( 'Waf_Rules_Manager::IP_BLOCK_LIST_ENABLED_OPTION_NAME' ) ) { | |
| 53 | + return 'jetpack_waf_ip_block_list_enabled'; | |
| 54 | + } | |
| 55 | + | |
| 56 | + return Waf_Rules_Manager::IP_BLOCK_LIST_ENABLED_OPTION_NAME; | |
| 57 | + } | |
| 58 | + | |
| 59 | + /** | |
| 20 | 60 | * Add compatibilty hooks |
| 21 | 61 | * |
| 22 | 62 | * @since 0.8.0 |
| 23 | 63 | * |
| @@ -27,10 +67,10 @@ | ||
| 27 | 67 | add_filter( 'default_option_' . Waf_Rules_Manager::AUTOMATIC_RULES_ENABLED_OPTION_NAME, __CLASS__ . '::default_option_waf_automatic_rules', 10, 3 ); |
| 28 | 68 | add_filter( 'default_option_' . Waf_Initializer::NEEDS_UPDATE_OPTION_NAME, __CLASS__ . '::default_option_waf_needs_update', 10, 3 ); |
| 29 | 69 | add_filter( 'default_option_' . Waf_Rules_Manager::IP_ALLOW_LIST_OPTION_NAME, __CLASS__ . '::default_option_waf_ip_allow_list', 10, 3 ); |
| 30 | 70 | add_filter( 'option_' . Waf_Rules_Manager::IP_ALLOW_LIST_OPTION_NAME, __CLASS__ . '::filter_option_waf_ip_allow_list', 10, 1 ); |
| 31 | - add_filter( 'default_option_' . Waf_Rules_Manager::IP_ALLOW_LIST_ENABLED_OPTION_NAME, __CLASS__ . '::default_option_waf_ip_allow_list_enabled', 10, 3 ); | |
| 32 | - add_filter( 'default_option_' . Waf_Rules_Manager::IP_BLOCK_LIST_ENABLED_OPTION_NAME, __CLASS__ . '::default_option_waf_ip_block_list_enabled', 10, 3 ); | |
| 71 | + add_filter( 'default_option_' . self::get_ip_allow_list_enabled_option_name(), __CLASS__ . '::default_option_waf_ip_allow_list_enabled', 10, 3 ); | |
| 72 | + add_filter( 'default_option_' . self::get_ip_block_list_enabled_option_name(), __CLASS__ . '::default_option_waf_ip_block_list_enabled', 10, 3 ); | |
| 33 | 73 | } |
| 34 | 74 | |
| 35 | 75 | /** |
| 36 | 76 | * Run compatibility migrations. |
| @@ -114,8 +154,11 @@ | ||
| 114 | 154 | * @return string The merged IP allow list. |
| 115 | 155 | */ |
| 116 | 156 | public static function merge_ip_allow_lists( $waf_allow_list, $brute_force_allow_list ) { |
| 117 | 157 | |
| 158 | + // Drop malformed entries. | |
| 159 | + $brute_force_allow_list = is_array( $brute_force_allow_list ) ? array_filter( $brute_force_allow_list, 'is_object' ) : array(); | |
| 160 | + | |
| 118 | 161 | if ( empty( $brute_force_allow_list ) ) { |
| 119 | 162 | return $waf_allow_list; |
| 120 | 163 | } |
| 121 | 164 | |
| @@ -234,9 +277,9 @@ | ||
| 234 | 277 | |
| 235 | 278 | /** |
| 236 | 279 | * Default the allow list enabled option to the value of the generic IP lists enabled option it replaced. |
| 237 | 280 | * |
| 238 | - * @since $next-version$ | |
| 281 | + * @since 0.17.0 | |
| 239 | 282 | * |
| 240 | 283 | * @param mixed $default The default value to return if the option does not exist in the database. |
| 241 | 284 | * @param string $option Option name. |
| 242 | 285 | * @param bool $passed_default Was get_option() passed a default value. |
| @@ -267,9 +310,9 @@ | ||
| 267 | 310 | |
| 268 | 311 | /** |
| 269 | 312 | * Default the block list enabled option to the value of the generic IP lists enabled option it replaced. |
| 270 | 313 | * |
| 271 | - * @since $next-version$ | |
| 314 | + * @since 0.17.0 | |
| 272 | 315 | * |
| 273 | 316 | * @param mixed $default The default value to return if the option does not exist in the database. |
| 274 | 317 | * @param string $option Option name. |
| 275 | 318 | * @param bool $passed_default Was get_option() passed a default value. |