Skip to content

Commit

Permalink
WAF: Prevent unnecessary database updates to NEEDS_UPDATE_OPTION_NAME (
Browse files Browse the repository at this point in the history
…#34820)

* Use a boolean value for Waf_Initializer::NEEDS_UPDATE_OPTION_NAME and update call logic
* Remove default update option value, as it is set with a filter
  • Loading branch information
nateweller authored Jan 18, 2024
1 parent f771117 commit 6e1ac72
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
4 changes: 4 additions & 0 deletions projects/packages/waf/changelog/fix-waf-update-option
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Optimize how the web application firewall checks for updates on admin screens.
4 changes: 2 additions & 2 deletions projects/packages/waf/src/class-compatibility.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public static function filter_option_waf_ip_allow_list( $waf_allow_list ) {
$brute_force_allow_list = Jetpack_Options::get_raw_option( 'jetpack_protect_whitelist', false );
if ( false !== $brute_force_allow_list ) {
$waf_allow_list = self::merge_ip_allow_lists( $waf_allow_list, $brute_force_allow_list );
update_option( Waf_Initializer::NEEDS_UPDATE_OPTION_NAME, 1 );
update_option( Waf_Initializer::NEEDS_UPDATE_OPTION_NAME, true );
}

return $waf_allow_list;
Expand All @@ -213,7 +213,7 @@ public static function default_option_waf_ip_allow_list( $default, $option, $pas
$brute_force_allow_list = Jetpack_Options::get_raw_option( 'jetpack_protect_whitelist', false );
if ( false !== $brute_force_allow_list ) {
$waf_allow_list = self::merge_ip_allow_lists( $waf_allow_list, $brute_force_allow_list );
update_option( Waf_Initializer::NEEDS_UPDATE_OPTION_NAME, 1 );
update_option( Waf_Initializer::NEEDS_UPDATE_OPTION_NAME, true );
}

return $waf_allow_list;
Expand Down
5 changes: 3 additions & 2 deletions projects/packages/waf/src/class-waf-initializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public static function update_waf_after_plugin_upgrade( $upgrader, $hook_extra )
return;
}

update_option( self::NEEDS_UPDATE_OPTION_NAME, 1 );
update_option( self::NEEDS_UPDATE_OPTION_NAME, true );
}

/**
Expand Down Expand Up @@ -197,9 +197,10 @@ public static function check_for_updates() {
// just migrate the IP allow list used by brute force protection.
Waf_Compatibility::migrate_brute_force_protection_ip_allow_list();
}

update_option( self::NEEDS_UPDATE_OPTION_NAME, false );
}

update_option( self::NEEDS_UPDATE_OPTION_NAME, 0 );
return true;
}

Expand Down

0 comments on commit 6e1ac72

Please sign in to comment.