Skip to content

Improve validation and permission checks for WP_HTTP_Polling_Sync_Server#11296

Open
chriszarate wants to merge 10 commits intoWordPress:trunkfrom
chriszarate:fix/http-polling-sync-server-validation
Open

Improve validation and permission checks for WP_HTTP_Polling_Sync_Server#11296
chriszarate wants to merge 10 commits intoWordPress:trunkfrom
chriszarate:fix/http-polling-sync-server-validation

Conversation

@chriszarate
Copy link
Copy Markdown

@chriszarate chriszarate commented Mar 19, 2026

Harden WP_HTTP_Polling_Sync_Server endpoints to add additional validation and permission checks.

Props @peterwilsoncc for contributions

Trac ticket: https://core.trac.wordpress.org/ticket/64890

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 19, 2026

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props czarate, westonruter.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions
Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@chriszarate chriszarate force-pushed the fix/http-polling-sync-server-validation branch 2 times, most recently from 8d50677 to 5c5e67b Compare March 25, 2026 14:29
@chriszarate chriszarate requested a review from westonruter March 25, 2026 14:29

// Handle single post type entities with a defined object ID.
if ( 'postType' === $entity_kind && is_numeric( $object_id ) ) {
if ( get_post_type( $object_id ) !== $entity_name ) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I noticed a type issue here:

Image

I've added 7fd0372 to improve this. With this change, $object_id is guaranteed to be int<1, max>|null.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Hardens the WP_HTTP_Polling_Sync_Server REST endpoint (/wp-sync/v1/updates) by tightening request validation limits and strengthening permission checks to better protect collaboration sync operations.

Changes:

  • Add route-level request body size validation plus schema constraints (maxItems for rooms, maxLength for update data).
  • Harden entity permission checks for object-scoped rooms (post type matching, term/comment checks).
  • Add PHPUnit coverage for new schema/route validation behavior (type/enum/required fields, maxItems/maxLength, oversized body).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
tests/phpunit/tests/rest-api/rest-sync-server.php Adds REST validation tests for schema enforcement and oversized body rejection.
src/wp-includes/collaboration/class-wp-http-polling-sync-server.php Introduces new size/limit constants, route-level validation callback, and tighter per-entity permission checks.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +56 to +62
/**
* Maximum size (in bytes) of a single update data string.
*
* @since 7.0.0
* @var int
*/
const MAX_UPDATE_DATA_SIZE = MB_IN_BYTES;
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

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

MAX_UPDATE_DATA_SIZE is documented as a size "in bytes", but it's currently enforced via the REST schema's maxLength (character count). If this is intended to limit the encoded string length, consider updating the docblock wording to avoid implying decoded byte size enforcement.

Copilot uses AI. Check for mistakes.
@chriszarate chriszarate force-pushed the fix/http-polling-sync-server-validation branch from ebab9ea to 9dd286b Compare March 28, 2026 00:26
chriszarate and others added 4 commits March 27, 2026 18:39
Add targeted REST tests for permission checks in
can_user_sync_entity_type() that previously lacked coverage:

- Malformed object ID (non-numeric string like "1abc") rejected
- Zero object ID rejected
- Post type mismatch (e.g. postType/page for a post) rejected
- Valid taxonomy term sync allowed
- Non-existent taxonomy term rejected
- Taxonomy term in wrong taxonomy rejected
- Valid comment sync allowed
- Non-existent comment rejected
- Non-existent post type collection rejected
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants