From ef106e7c454df7a10d68ac0c8960c8288492beb0 Mon Sep 17 00:00:00 2001 From: Nate Weller Date: Sun, 6 Oct 2024 14:58:21 -0600 Subject: [PATCH 1/3] Add safe handling of potentially undefined class constants --- .../packages/waf/src/class-compatibility.php | 44 ++++++++++++++++++- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/projects/packages/waf/src/class-compatibility.php b/projects/packages/waf/src/class-compatibility.php index 8f3e6d5634a15..9e757cf4e8b0a 100644 --- a/projects/packages/waf/src/class-compatibility.php +++ b/projects/packages/waf/src/class-compatibility.php @@ -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' ) ) { + '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' ) ) { + 'jetpack_waf_ip_block_list_enabled'; + } + + return Waf_Rules_Manager::IP_BLOCK_LIST_ENABLED_OPTION_NAME; + } + /** * Add compatibilty hooks * @@ -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 ); } /** From 5c218eb2a03fd358fd90671b8f437f69070712de Mon Sep 17 00:00:00 2001 From: Nate Weller Date: Sun, 6 Oct 2024 14:59:20 -0600 Subject: [PATCH 2/3] changelog --- .../waf/changelog/fix-waf-autoloaded-runner-class-handling | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 projects/packages/waf/changelog/fix-waf-autoloaded-runner-class-handling diff --git a/projects/packages/waf/changelog/fix-waf-autoloaded-runner-class-handling b/projects/packages/waf/changelog/fix-waf-autoloaded-runner-class-handling new file mode 100644 index 0000000000000..d8d7bc0000aff --- /dev/null +++ b/projects/packages/waf/changelog/fix-waf-autoloaded-runner-class-handling @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Improve backwards compatibility for sites running in standalone mode. From a4677e96f7fb6a8a69e4ab5cb6dfd2e53ea76bb0 Mon Sep 17 00:00:00 2001 From: Nate Weller Date: Mon, 7 Oct 2024 09:57:54 -0600 Subject: [PATCH 3/3] Fix missing return statements --- projects/packages/waf/src/class-compatibility.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/packages/waf/src/class-compatibility.php b/projects/packages/waf/src/class-compatibility.php index 9e757cf4e8b0a..362543a391fb1 100644 --- a/projects/packages/waf/src/class-compatibility.php +++ b/projects/packages/waf/src/class-compatibility.php @@ -30,7 +30,7 @@ private static function get_ip_allow_list_enabled_option_name() { * @see peb6dq-2HL-p2 */ if ( ! defined( 'Waf_Rules_Manager::IP_ALLOW_LIST_ENABLED_OPTION_NAME' ) ) { - 'jetpack_waf_ip_allow_list_enabled'; + return 'jetpack_waf_ip_allow_list_enabled'; } return Waf_Rules_Manager::IP_ALLOW_LIST_ENABLED_OPTION_NAME; @@ -50,7 +50,7 @@ private static function get_ip_block_list_enabled_option_name() { * @see peb6dq-2HL-p2 */ if ( ! defined( 'Waf_Rules_Manager::IP_BLOCK_LIST_ENABLED_OPTION_NAME' ) ) { - 'jetpack_waf_ip_block_list_enabled'; + return 'jetpack_waf_ip_block_list_enabled'; } return Waf_Rules_Manager::IP_BLOCK_LIST_ENABLED_OPTION_NAME;