Skip to content

Commit

Permalink
Protect: Add IP block and allow list toggles (#38265)
Browse files Browse the repository at this point in the history
* Add individual controls for toggling the IP block and allow lists.

* Add block and allow list toggles

* Remove missed export

* Disable save when lists haven't changed

* Unify styling

* Add changelog entry

* Add handling for when WAF is disabled

* Fix tests

* Add changelog

* Optimize

* Remove is_enabled check that is no longer necessary

* Revert test changes

* Revert WAF changes

* changelog

* Remove WAF changelog

* Adjustments

* Remove block list disable useEffect and ensure consistency of lists in disabled state

---------

Co-authored-by: Nate Weller <[email protected]>
  • Loading branch information
dkmyta and nateweller authored Jul 17, 2024
1 parent e9e6046 commit 742a6b2
Show file tree
Hide file tree
Showing 5 changed files with 270 additions and 277 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: added

Adds dedicated WAF allow and block list toggles
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,19 @@ const FirewallSubheadingContent = ( { className, text = '', popover = false, chi
};

const FirewallSubheading = ( {
jetpackWafIpBlockListEnabled,
jetpackWafIpAllowListEnabled,
hasRequiredPlan,
automaticRulesAvailable,
jetpackWafIpList,
jetpackWafAutomaticRules,
bruteForceProtectionIsEnabled,
wafSupported,
} ) => {
const allRules = wafSupported && jetpackWafAutomaticRules && jetpackWafIpList;
const automaticRules = wafSupported && jetpackWafAutomaticRules && ! jetpackWafIpList;
const manualRules = wafSupported && ! jetpackWafAutomaticRules && jetpackWafIpList;
const noRules = wafSupported && ! jetpackWafAutomaticRules && ! jetpackWafIpList;
const allowOrBlockListEnabled = jetpackWafIpBlockListEnabled || jetpackWafIpAllowListEnabled;
const allRules = wafSupported && jetpackWafAutomaticRules && allowOrBlockListEnabled;
const automaticRules = wafSupported && jetpackWafAutomaticRules && ! allowOrBlockListEnabled;
const manualRules = wafSupported && ! jetpackWafAutomaticRules && allowOrBlockListEnabled;
const noRules = wafSupported && ! jetpackWafAutomaticRules && ! allowOrBlockListEnabled;

return (
<>
Expand Down Expand Up @@ -157,7 +159,8 @@ const FirewallHeader = ( {
hasRequiredPlan,
automaticRulesEnabled,
automaticRulesAvailable,
jetpackWafIpList,
jetpackWafIpBlockListEnabled,
jetpackWafIpAllowListEnabled,
jetpackWafAutomaticRules,
bruteForceProtectionIsEnabled,
wafSupported,
Expand Down Expand Up @@ -193,7 +196,8 @@ const FirewallHeader = ( {
) ) }
</H3>
<FirewallSubheading
jetpackWafIpList={ jetpackWafIpList }
jetpackWafIpBlockListEnabled={ jetpackWafIpBlockListEnabled }
jetpackWafIpAllowListEnabled={ jetpackWafIpAllowListEnabled }
jetpackWafAutomaticRules={ jetpackWafAutomaticRules }
bruteForceProtectionIsEnabled={ bruteForceProtectionIsEnabled }
hasRequiredPlan={ hasRequiredPlan }
Expand All @@ -217,7 +221,8 @@ const FirewallHeader = ( {
) ) }
</H3>
<FirewallSubheading
jetpackWafIpList={ jetpackWafIpList }
jetpackWafIpBlockListEnabled={ jetpackWafIpBlockListEnabled }
jetpackWafIpAllowListEnabled={ jetpackWafIpAllowListEnabled }
jetpackWafAutomaticRules={ jetpackWafAutomaticRules }
bruteForceProtectionIsEnabled={ bruteForceProtectionIsEnabled }
hasRequiredPlan={ hasRequiredPlan }
Expand Down Expand Up @@ -250,7 +255,8 @@ const ConnectedFirewallHeader = () => {
const {
config: {
jetpackWafAutomaticRules,
jetpackWafIpList,
jetpackWafIpBlockListEnabled,
jetpackWafIpAllowListEnabled,
standaloneMode,
automaticRulesAvailable,
bruteForceProtection,
Expand All @@ -269,7 +275,8 @@ const ConnectedFirewallHeader = () => {
hasRequiredPlan={ hasRequiredPlan }
automaticRulesEnabled={ jetpackWafAutomaticRules }
automaticRulesAvailable={ automaticRulesAvailable }
jetpackWafIpList={ jetpackWafIpList }
jetpackWafIpBlockListEnabled={ jetpackWafIpBlockListEnabled }
jetpackWafIpAllowListEnabled={ jetpackWafIpAllowListEnabled }
jetpackWafAutomaticRules={ jetpackWafAutomaticRules }
bruteForceProtectionIsEnabled={ bruteForceProtection }
wafSupported={ wafSupported }
Expand Down
29 changes: 23 additions & 6 deletions projects/plugins/protect/src/js/hooks/use-waf-data/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,32 @@ const useWafData = () => {
}, [ ensureModuleIsEnabled, refreshWaf, setWafIsUpdating, waf.config.jetpackWafAutomaticRules ] );

/**
* Toggle Manual Rules
* Toggle IP Allow List
*
* Flips the switch on the WAF IP list feature, and then refreshes the data.
* Flips the switch on the WAF IP allow list feature, and then refreshes the data.
*/
const toggleManualRules = useCallback( () => {
const toggleIpAllowList = useCallback( () => {
setWafIsUpdating( true );
return API.updateWaf( { jetpack_waf_ip_list: ! waf.config.jetpackWafIpList } )
return API.updateWaf( {
jetpack_waf_ip_allow_list_enabled: ! waf.config.jetpackWafIpAllowListEnabled,
} )
.then( refreshWaf )
.finally( () => setWafIsUpdating( false ) );
}, [ refreshWaf, setWafIsUpdating, waf.config.jetpackWafIpList ] );
}, [ refreshWaf, setWafIsUpdating, waf.config.jetpackWafIpAllowListEnabled ] );

/**
* Toggle IP Block List
*
* Flips the switch on the WAF IP block list feature, and then refreshes the data.
*/
const toggleIpBlockList = useCallback( () => {
setWafIsUpdating( true );
return API.updateWaf( {
jetpack_waf_ip_block_list_enabled: ! waf.config.jetpackWafIpBlockListEnabled,
} )
.then( refreshWaf )
.finally( () => setWafIsUpdating( false ) );
}, [ refreshWaf, setWafIsUpdating, waf.config.jetpackWafIpBlockListEnabled ] );

/**
* Toggle Brute Force Protection
Expand Down Expand Up @@ -152,7 +168,8 @@ const useWafData = () => {
refreshWaf,
toggleWaf,
toggleAutomaticRules,
toggleManualRules,
toggleIpAllowList,
toggleIpBlockList,
toggleBruteForceProtection,
toggleShareData,
toggleShareDebugData,
Expand Down
Loading

0 comments on commit 742a6b2

Please sign in to comment.