Skip to content

Protect: Let the firewall and Account protection endpoints accept the wanted state - #53317

Merged
kraftbj merged 4 commits into
trunkfrom
dhaka-v1/jetpack-2948-add-pr
Oct 13, 2026
Merged

kraftbj merged 4 commits into
trunkfrom
dhaka-v1/jetpack-2948-add-pr

Conversation

@kraftbj

@kraftbj kraftbj commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Fixes JETPACK-2948

Proposed changes

  • POST jetpack-protect/v1/toggle-waf and POST jetpack-protect/v1/toggle-account-protection took no argument and inverted whatever the current state was. A stale page, a second tab, or a double submit did the opposite of what was asked. Both now accept an optional enabled boolean and set that state, so sending "on" twice leaves the feature on.
  • A request without enabled still flips, so a browser holding the previous script keeps working through an update.
  • The Protect UI sends the wanted state: the Account protection switch sends the value it was moved to, and the "Enable Firewall" button always sends on.
  • The firewall notice read "WAF module enabled." whichever way the request went. The request now always enables, so the notice is true.

No unit test here. The plugin has no PHP or JS test harness for its REST routes (tests/php is only a bootstrap), and standing one up for this felt out of proportion. Tested on a live site instead, steps below.

Related product discussion/links

Does this pull request change what data or activity we track or use?

No.

Testing instructions

On a connected site with the Protect plugin active (with or without the Jetpack plugin):

Account protection, stale page

  • Open Protect › Settings in two tabs, with Account protection on in both.
  • In the first tab, switch it off.
  • In the second tab (which still shows it on), switch it off.
  • Reload. It should be off. On trunk it comes back on.

Firewall, stale page

  • With the firewall module off, open Protect › Firewall in two tabs. Both show "Jetpack Firewall is currently disabled."
  • Click "Enable Firewall" in the first tab, then in the second.
  • The second tab should say "WAF module enabled." and the firewall should stay on. On trunk the second click turns it back off while still saying "WAF module enabled."

The endpoints directly (an application password works for auth)

  • POST /wp-json/jetpack-protect/v1/toggle-waf with {"enabled":true} twice: GET jetpack-protect/v1/waf reports isEnabled: true after each.
  • Same with {"enabled":false}: stays off.
  • With no body: flips, as before.
  • {"enabled":"banana"} returns a 400.
  • Repeat for toggle-account-protection and GET jetpack-protect/v1/account-protection.

toggle-waf and toggle-account-protection inverted whatever the current
state was, so a stale page or a double submit did the opposite of what
was asked. Both now take an optional `enabled` boolean and the Protect
UI sends it. A request without it still flips, so a cached copy of the
old script keeps working.

The firewall notice now reports the state that was requested.
@kraftbj kraftbj added [Status] Needs Review This PR is ready for review. Covered by non-unit tests Use to ignore the Code coverage requirement check when E2Es or other non-unit tests cover the code [Type] Bug labels Oct 7, 2026
@kraftbj kraftbj self-assigned this Oct 7, 2026
@github-actions github-actions Bot added the [Plugin] Protect A plugin with features to protect a site: brute force protection, security scanning, and a WAF. label Oct 7, 2026
@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

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 🤖


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!


Protect plugin:

No scheduled milestone found for this plugin.

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

@jp-launch-control

jp-launch-control Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Code Coverage Summary

Coverage changed in 1 file.

File Coverage Δ% Δ Uncovered
projects/plugins/protect/src/class-rest-controller.php 0/278 (0.00%) 0.00% 17 💔

Full summary · PHP report

Coverage check overridden by Covered by non-unit tests Use to ignore the Code coverage requirement check when E2Es or other non-unit tests cover the code .

The Protect UI can only turn the firewall on, so the mutation now always
sends enabled: true and keeps its single pair of notices. The two-way
notices were being merged by the production minifier, which failed the
i18n check.
@kraftbj
kraftbj requested a review from enejb October 7, 2026 18:15
@kraftbj
kraftbj merged commit 956e58c into trunk Oct 13, 2026
79 checks passed
@kraftbj
kraftbj deleted the dhaka-v1/jetpack-2948-add-pr branch October 13, 2026 18:13
@github-actions github-actions Bot added [Status] UI Changes Add this to PRs that change the UI so documentation can be updated. and removed [Status] Needs Review This PR is ready for review. labels Oct 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Covered by non-unit tests Use to ignore the Code coverage requirement check when E2Es or other non-unit tests cover the code [Plugin] Protect A plugin with features to protect a site: brute force protection, security scanning, and a WAF. [Status] UI Changes Add this to PRs that change the UI so documentation can be updated. [Type] Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant