Skip to content

Conversation

@LiamSarsfield
Copy link
Contributor

@LiamSarsfield LiamSarsfield commented Aug 28, 2025

Fixes HOG-297: Investigate usability of Block_Scanner within Verbum_Block_Utils

Proposed changes:

  • Optimize Verbum comment block filtering performance using hybrid Block_Scanner approach
  • Add Block_Scanner-based pre-filtering to detect disallowed blocks without expensive parse_blocks() processing
  • Fall back to existing parse_blocks() approach only when disallowed blocks are detected
  • Add block-delimiter package dependency to jetpack-mu-wpcom
  • Maintain 100% backward compatibility and identical filtering behavior

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

N/A

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

N/A

Testing instructions:

This needs to be tested in both Atomic and Simple.

  • Create, or use an existing Atomic/Simple (depending on which one you're testing) site.
  • Follow the instructions in this comment to ensure your Sandbox has the branch code.
  • For simple only: ensure your hosts file has said simple site's domain pointed to your sandbox IP.
  • Open the network tab on your dev console.
  • While network tab is opened, go to a post that you can comment on on your Simple site.
  • Comment a post with an image block (allowed block)
  • Verify the comment is posted successfully, and monitor your network tab for a POST request to /wp-comments-post.php
  • Right click the network request, and go copy -> copy as fetch
  • Paste the code into your browser, but do not execute it yet
  • Copy the following value %3C!--%20wp%3Alatest-posts%20%2F--%3E (which is encodeURIComponent())
  • Replace a portion of the fetch's second argument's body key to between comment= and &hc_post_as= to comment=%3C!--%20wp%3Alatest-posts%20%2F--%3E&hc_post_as=
  • Execute the code, if you sent it right, you should see the below payload's data
Screenshot 2025-09-01 at 15 42 05
  • Verify a comment has not been added with said latest posts block, as this is not allowed
  • Repeat the same steps for either Simple/Atomic if not done so already.

- Added the "automattic/block-delimiter" package to composer.json.
- Enhanced the Verbum_Block_Utils class to utilize Block_Scanner for faster detection of disallowed blocks, improving performance by avoiding unnecessary parsing in cases where all blocks are allowed. Introduced fallback methods for handling disallowed blocks when detected.
@github-actions
Copy link
Contributor

github-actions bot commented Aug 28, 2025

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 (WordPress.com Site Helper), and enable the update/verbum/allowed-blocks-checker-HOG-297 branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack-mu-wpcom-plugin update/verbum/allowed-blocks-checker-HOG-297

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 added [mu wpcom Feature] Verbum Comments Verbum, a better comment experience, app developed in the mu-wpcom plugin [Package] Jetpack mu wpcom WordPress.com Features [Status] In Progress labels Aug 28, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Aug 28, 2025

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 a "[Type]" label (Bug, Enhancement, Janitorial, Task).
  • ✅ 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!


Mu Wpcom plugin:

  • Next scheduled release: WordPress.com Simple releases happen semi-continuously (PCYsg-Jjm-p2)

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


Wpcomsh plugin:

  • Next scheduled release: Atomic deploys happen twice daily on weekdays (p9o2xV-2EN-p2)

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

@github-actions github-actions bot added the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label Aug 28, 2025
@LiamSarsfield LiamSarsfield added [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it and removed [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. labels Aug 28, 2025
@jp-launch-control
Copy link

jp-launch-control bot commented Aug 28, 2025

Code Coverage Summary

Coverage changed in 1 file.

File Coverage Δ% Δ Uncovered
projects/packages/jetpack-mu-wpcom/src/features/verbum-comments/assets/class-verbum-block-utils.php 70/80 (87.50%) -1.21% 3 ❤️‍🩹

Full summary · PHP report

@LiamSarsfield LiamSarsfield changed the title Update/verbum/allowed-blocks-checker-HOG-297 Verbum Comments: optimize block filtering performance with Block_Scanner pre-filtering Aug 28, 2025
- Updated the Verbum_Block_Utils class to return unslashed content for consistency across processing paths.
- Added validation for $allowedtags to prevent override warnings.
- Introduced comprehensive tests for handling malformed block delimiters, Unicode edge cases, block type spoofing, and resource limits to ensure robust security and consistent input validation.
- Introduced the "automattic/block-delimiter" package with its dependencies and autoload configurations.
- Updated the reference for "automattic/jetpack-mu-wpcom" to ensure compatibility with the new package.
@github-actions github-actions bot added the [Plugin] mu wpcom jetpack-mu-wpcom plugin label Aug 28, 2025
- Removed redundant comments and simplified the logic for returning unslashed content.
- Updated the method documentation for clarity.
- Enhanced the handling of innerHTML to ensure it is set correctly when not defined.
@LiamSarsfield LiamSarsfield requested review from a team, dilirity and kraftbj September 1, 2025 15:12
@LiamSarsfield LiamSarsfield marked this pull request as ready for review September 1, 2025 15:12
@dilirity dilirity added [Status] Needs Review This PR is ready for review. and removed [Status] In Progress labels Sep 4, 2025
dilirity
dilirity previously approved these changes Sep 4, 2025
Copy link
Member

@dilirity dilirity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work on this! I added some questions but they are in no way blockers, more like wonderings.

:shipit:

* @param string $content Unslashed content to scan.
* @return bool True if disallowed blocks found, false if all blocks are allowed.
*/
private static function has_disallowed_blocks_fast( $content ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: I think the fast part is not necessary. There's no slow equivalent :D

*/
private static function has_disallowed_blocks_fast( $content ) {
if ( ! class_exists( '\\Automattic\\Block_Scanner' ) ) {
return true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was going back and forth about the function returning true (has disallowed blocks) but I think it makes sense. This way we default back to always using parse blocks if we can't use the Block_Scanner.

Comment on lines +179 to +183
// Validate $allowedtags integrity - use local variable to avoid override warning
$validated_allowedtags = $allowedtags;
if ( ! is_array( $validated_allowedtags ) ) {
$validated_allowedtags = wp_kses_allowed_html( 'post' );
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to just make sure that we're working with correct data, right? Just making sure 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup! Correct, just an extra defensive measure.

…larity and performance. Updated method name from `has_disallowed_blocks_fast` to `has_disallowed_blocks` and adjusted documentation accordingly.
Copy link
Member

@dilirity dilirity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@LiamSarsfield LiamSarsfield merged commit 5194408 into trunk Sep 9, 2025
64 checks passed
@LiamSarsfield LiamSarsfield deleted the update/verbum/allowed-blocks-checker-HOG-297 branch September 9, 2025 13:01
@github-actions github-actions bot removed the [Status] Needs Review This PR is ready for review. label Sep 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[mu wpcom Feature] Verbum Comments Verbum, a better comment experience, app developed in the mu-wpcom plugin [Package] Jetpack mu wpcom WordPress.com Features [Plugin] mu wpcom jetpack-mu-wpcom plugin [Plugin] Wpcomsh [Tests] Includes Tests [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants