-
Notifications
You must be signed in to change notification settings - Fork 800
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WAF: Improve cross-compatibility of IP list options #38395
Conversation
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available. Once your PR is ready for review, check one last time that all required checks appearing at the bottom of this PR are passing or skipped. |
4f0663f
to
612992c
Compare
6c1a218
to
6778532
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good, one non-blocking suggestion to maintain consistency.
Had some initial issues testing - installed the branch via the beta tester on a JN site that had pre-existing legacy options set (manual rules enabled or disabled). Regardless of the existing settings, after installing the branch the manual rules show as on and toggling from either Jetpack or Protect does not work. The request succeeds and the payload looks correct jetpack_waf_ip_list: false
, but the response continues to include jetpack_waf_ip_list: true
, the toggle flips momentarily but returns to the on position.
Works great on a fresh JT install, even after downgrading and/or using an outdated version of the other plugin. Odd thing is, if I install the new version, modify settings, downgrade, modify settings, then upgrade again, it works as expected. I was under the impression that doing this would present the same issues as starting from and old version and upgrading, but perhaps because in this particular case the new options are already set from the new version being installed initially, vs in the other case, they did not exist when upgrading?
UPDATE: Although still worth a deeper look, I was unable to reproduce the issue on another installation with a similar setup, so its potentially just a one-off - I've provided you login creds privately so you can take a look at the problematic site.
Another thing I did notice though was on the first time enabling the manual rules setting using the branch, after hitting the toggle it was disabled for a noticeably longer time then any subsequent toggles - perhaps irrelevant or might have always been the case but thought it worthy of a note.
@@ -179,7 +179,7 @@ public static function get_config() { | |||
* @deprecated $next-version$ | |||
*/ | |||
// @phan-suppress-next-line PhanDeprecatedClassConstant -- Needed for backwards compatibility. | |||
Waf_Rules_Manager::IP_LISTS_ENABLED_OPTION_NAME => get_option( Waf_Rules_Manager::IP_LISTS_ENABLED_OPTION_NAME ), | |||
Waf_Rules_Manager::IP_LISTS_ENABLED_OPTION_NAME => get_option( Waf_Rules_Manager::IP_ALLOW_LIST_ENABLED_OPTION_NAME ) || get_option( Waf_Rules_Manager::IP_BLOCK_LIST_ENABLED_OPTION_NAME ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To maintain consistency with other related operations, should we use Jetpack_Options::get_raw_option()
here also?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting question! After double checking the logic, I don't think these should be changed.
I'm using get_option
here so that it uses the default value hooks for the block and allow list. This ensures that if the deprecated option was set, and the new options are not, they will base their value on the old one and still return an accurate value 👍
In the compatibility class, I used get_raw_option
to bypass those filters, in order to make those default value decisions based on the "true" value of the options in the database.
But at this point, in the runner class, we want those default values to be used 👍
Some notes from debugging on this particular test site:
|
… jetpack_waf_ip_allow_list_enabled and jetpack_waf_ip_block_list_enabled settings
6778532
to
5cb95bf
Compare
If you upgrade, make changes, and then downgrade - it would go back to using the deprecated option value, which is never modified or used directly by the upgraded version. Likewise, if you go back to the upgraded version, where you already had set values for the new options, it will always use those directly. So I am not sure if it would always keep the changes you made in the middle of that process, as when the latest values are available when running the updated code, it will always use those. I'm not too worried about the case where the updated version is installed, used, and then downgraded though. |
Made some minor adjustments, this is good for re-review @dkmyta 🙇 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we're solid here! I was not able to replicate the original issue - I think we can conclude that it was definitely an odd one-off that we do have handling for.
As we discussed, there is not much we can do about the edge case where one or the other plugin is using the legacy version and have a single IP list toggled in the upgraded version, but I agree that the following is a logical solution:
- Disabling manual rules in the legacy UI disables both lists in the upgraded UI
- Disabling both lists in the upgraded UI disables manual rules in the legacy UI
- Enabling any one list in the upgraded UI enables manual rules and access to both lists in the legacy UI (and updates to a disabled list re-enable it in the upgraded UI)
Proposed changes:
Jetpack_Options::get_raw_option()
in compatibility hooks, to use the unfiltered value from the database.'1'
or''
as option values to ensure related hooks fire (source).Other information:
Jetpack product discussion
N/A
Does this pull request change what data or activity we track or use?
No
Testing instructions: