Skip to content

Commit

Permalink
WAF: Handle cases where outdated Waf_Rules_Manager has been autoloade…
Browse files Browse the repository at this point in the history
…d in standalone mode (#39652)
  • Loading branch information
nateweller authored and gogdzl committed Oct 25, 2024
1 parent d49b3e7 commit 312d346
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Improve backwards compatibility for sites running in standalone mode.
44 changes: 42 additions & 2 deletions projects/packages/waf/src/class-compatibility.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,46 @@
*/
class Waf_Compatibility {

/**
* Returns the name for the IP allow list enabled/disabled option.
*
* @since $$next-version$$
*
* @return string
*/
private static function get_ip_allow_list_enabled_option_name() {
/**
* Patch: bootstrap script generated prior to 0.17.0 may have autoloaded Waf_Rules_Manager class during standalone mode execution.
*
* @see peb6dq-2HL-p2
*/
if ( ! defined( 'Waf_Rules_Manager::IP_ALLOW_LIST_ENABLED_OPTION_NAME' ) ) {
return 'jetpack_waf_ip_allow_list_enabled';
}

return Waf_Rules_Manager::IP_ALLOW_LIST_ENABLED_OPTION_NAME;
}

/**
* Returns the name for the IP block list enabled/disabled option.
*
* @since $$next-version$$
*
* @return string
*/
private static function get_ip_block_list_enabled_option_name() {
/**
* Patch: bootstrap script generated prior to 0.17.0 may have autoloaded Waf_Rules_Manager class during standalone mode execution.
*
* @see peb6dq-2HL-p2
*/
if ( ! defined( 'Waf_Rules_Manager::IP_BLOCK_LIST_ENABLED_OPTION_NAME' ) ) {
return 'jetpack_waf_ip_block_list_enabled';
}

return Waf_Rules_Manager::IP_BLOCK_LIST_ENABLED_OPTION_NAME;
}

/**
* Add compatibilty hooks
*
Expand All @@ -28,8 +68,8 @@ public static function add_compatibility_hooks() {
add_filter( 'default_option_' . Waf_Initializer::NEEDS_UPDATE_OPTION_NAME, __CLASS__ . '::default_option_waf_needs_update', 10, 3 );
add_filter( 'default_option_' . Waf_Rules_Manager::IP_ALLOW_LIST_OPTION_NAME, __CLASS__ . '::default_option_waf_ip_allow_list', 10, 3 );
add_filter( 'option_' . Waf_Rules_Manager::IP_ALLOW_LIST_OPTION_NAME, __CLASS__ . '::filter_option_waf_ip_allow_list', 10, 1 );
add_filter( 'default_option_' . Waf_Rules_Manager::IP_ALLOW_LIST_ENABLED_OPTION_NAME, __CLASS__ . '::default_option_waf_ip_allow_list_enabled', 10, 3 );
add_filter( 'default_option_' . Waf_Rules_Manager::IP_BLOCK_LIST_ENABLED_OPTION_NAME, __CLASS__ . '::default_option_waf_ip_block_list_enabled', 10, 3 );
add_filter( 'default_option_' . self::get_ip_allow_list_enabled_option_name(), __CLASS__ . '::default_option_waf_ip_allow_list_enabled', 10, 3 );
add_filter( 'default_option_' . self::get_ip_block_list_enabled_option_name(), __CLASS__ . '::default_option_waf_ip_block_list_enabled', 10, 3 );
}

/**
Expand Down

0 comments on commit 312d346

Please sign in to comment.