Skip to content

WAF: Store the request behind each block and show it on the Protect dashboard - #53441

Closed
enejb wants to merge 2 commits into
add/protect-dashboard-firewallfrom
add/waf-blocklog-request-details
Closed

enejb wants to merge 2 commits into
add/protect-dashboard-firewallfrom
add/waf-blocklog-request-details

Conversation

@enejb

@enejb enejb commented Oct 9, 2026

Copy link
Copy Markdown
Member

Part of JETPACK-2882

Proposed changes

  • Stacked on Protect Dashboard: Add the Firewall section #53193. Review that first; this PR's diff is only the two commits on top.
  • The blocklog table only stored the rule ID and reason, so the Firewall card's "Recently blocked requests" could say why something was blocked but not what was blocked. This stores the request behind each block and shows it.
  • WAF: the jetpack_waf_blocklog table gets three nullable columns: method, request_uri (up to 2048 bytes) and user_agent (up to 512 bytes). The IP address is not stored.
  • Existing tables are upgraded once on admin_init (Waf_Blocklog_Manager::maybe_upgrade_blocklog_table(), tracked by jetpack_waf_blocklog_schema_version), only while the firewall is on.
  • The firewall writes the log row before it sends the 403, so the writer must never throw. If the 6-column insert fails (a table that hasn't been upgraded yet, including mysqli throwing on PHP 8.1+), it falls back to the original 3-column insert. The request is still blocked and logged.
  • Waf_Blocklog_Manager::get_recent_blocks() returns method, uri and userAgent (null for older rows).
  • Protect dashboard: each recently blocked request shows METHOD /uri and the user agent under its label. Rows logged before the upgrade look as they did.

Related product discussion/links

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

The firewall now keeps the method, URL and user agent of blocked requests in the site's own database, alongside the rule and reason it already kept. It's capped at the same 100 rows and isn't sent anywhere. The "Share data with Jetpack" log file already contained these fields; nothing about what's shared changes.

Testing instructions

  • Set up a site as in Protect Dashboard: Add the Firewall section #53193's testing instructions, running this branch, with the firewall on.
  • Visit any wp-admin page once. wp db query "DESCRIBE wp_jetpack_waf_blocklog" now lists method, request_uri and user_agent, and wp option get jetpack_waf_blocklog_schema_version is 2.
  • Go to Jetpack > Protect and click "Test firewall". The new "Firewall test" row under "Recently blocked requests" shows GET /?jetpack_waf_test=… and your browser's user agent. Rows from before the upgrade show only the label and time.
  • Old-table fallback: wp db query "ALTER TABLE wp_jetpack_waf_blocklog DROP COLUMN method, DROP COLUMN request_uri, DROP COLUMN user_agent" and wp option update jetpack_waf_blocklog_schema_version 1. Without visiting wp-admin, add your IP to the block list (wp option update jetpack_waf_ip_block_list <ip>) and request the home page: it's still a 403, a row is still logged, and there are no PHP errors. Then visit wp-admin and the columns come back.

@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack), and enable the add/waf-blocklog-request-details branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack add/waf-blocklog-request-details

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions

github-actions Bot commented Oct 9, 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!


Jetpack 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

Copy link
Copy Markdown

Code Coverage Summary

No summary data is available for parent commit f0610ab, so cannot calculate coverage changes. 😴

If that commit is a feature branch rather than a trunk commit, this is expected. Otherwise, this should be updated once coverage for f0610ab is available.

Full summary · PHP report · JS report

@enejb

enejb commented Oct 9, 2026

Copy link
Copy Markdown
Member Author

Closing this for now. It changes the schema of the shared jetpack_waf_blocklog table and would store request URIs and user agents for every site with the firewall on. Today the WAF keeps those fields only in the opt-in share-data log, so whether the database log should keep them is a decision for the WAF owners. The dashboard in #53193 works without it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant