From 8def970e9b4c8481f580f899a41def360c539c9e Mon Sep 17 00:00:00 2001 From: Nate Weller Date: Thu, 17 Oct 2024 12:16:00 -0600 Subject: [PATCH] WAF: Handle undefined entrypoint constant (#39812) --- .../fix-waf-undefined-entrypoint-in-bootstrap | 4 ++++ .../waf/src/class-waf-standalone-bootstrap.php | 12 +++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 projects/packages/waf/changelog/fix-waf-undefined-entrypoint-in-bootstrap diff --git a/projects/packages/waf/changelog/fix-waf-undefined-entrypoint-in-bootstrap b/projects/packages/waf/changelog/fix-waf-undefined-entrypoint-in-bootstrap new file mode 100644 index 0000000000000..9c6e1ae4648d4 --- /dev/null +++ b/projects/packages/waf/changelog/fix-waf-undefined-entrypoint-in-bootstrap @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Firewall: improve backwards compatibility for sites running outdated bootstrap scripts via standalone mode. diff --git a/projects/packages/waf/src/class-waf-standalone-bootstrap.php b/projects/packages/waf/src/class-waf-standalone-bootstrap.php index a272b1492cf0a..61a930b2a948d 100644 --- a/projects/packages/waf/src/class-waf-standalone-bootstrap.php +++ b/projects/packages/waf/src/class-waf-standalone-bootstrap.php @@ -120,6 +120,15 @@ public function get_bootstrap_file_path() { return trailingslashit( JETPACK_WAF_DIR ) . 'bootstrap.php'; } + /** + * Gets the entrypoint file. + * + * @return string The entrypoint file. + */ + private function get_entrypoint() { + return defined( 'JETPACK_WAF_ENTRYPOINT' ) ? JETPACK_WAF_ENTRYPOINT : 'rules/rules.php'; + } + /** * Generates the bootstrap file. * @@ -141,6 +150,7 @@ public function generate() { $autoloader_file = $this->locate_autoloader_file(); $bootstrap_file = $this->get_bootstrap_file_path(); + $entrypoint = $this->get_entrypoint(); $mode_option = get_option( Waf_Runner::MODE_OPTION_NAME, false ); $share_data_option = get_option( Waf_Runner::SHARE_DATA_OPTION_NAME, false ); $share_debug_data_option = get_option( Waf_Runner::SHARE_DEBUG_DATA_OPTION_NAME, false ); @@ -154,7 +164,7 @@ public function generate() { . sprintf( "define( 'JETPACK_WAF_SHARE_DEBUG_DATA', %s );\n", var_export( $share_debug_data_option, true ) ) . sprintf( "define( 'JETPACK_WAF_DIR', %s );\n", var_export( JETPACK_WAF_DIR, true ) ) . sprintf( "define( 'JETPACK_WAF_WPCONFIG', %s );\n", var_export( JETPACK_WAF_WPCONFIG, true ) ) - . sprintf( "define( 'JETPACK_WAF_ENTRYPOINT', %s );\n", var_export( JETPACK_WAF_ENTRYPOINT, true ) ) + . sprintf( "define( 'JETPACK_WAF_ENTRYPOINT', %s );\n", var_export( $entrypoint, true ) ) . 'require_once ' . var_export( $autoloader_file, true ) . ";\n" . "Automattic\Jetpack\Waf\Waf_Runner::initialize();\n"; // phpcs:enable