Skip to content

Commit

Permalink
WAF: Handle undefined entrypoint constant (#39812)
Browse files Browse the repository at this point in the history
  • Loading branch information
nateweller authored Oct 17, 2024
1 parent 941e980 commit 8def970
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Firewall: improve backwards compatibility for sites running outdated bootstrap scripts via standalone mode.
12 changes: 11 additions & 1 deletion projects/packages/waf/src/class-waf-standalone-bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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 );
Expand All @@ -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
Expand Down

0 comments on commit 8def970

Please sign in to comment.