Skip to content

Validated profiler payload structure - #1214

Merged
pirate-bot merged 2 commits into
developmentfrom
bugfix/1204
Oct 30, 2026
Merged

pirate-bot merged 2 commits into
developmentfrom
bugfix/1204

Conversation

@girishpanchal30

Copy link
Copy Markdown
Contributor

All Submissions:

Changes proposed in this Pull Request:

Fixed PHP 8 TypeErrors in public optml/v1/optimizations endpoint by adding REST schemas for b, l[u], and m, allowing WordPress to validate incoming data before the handler runs. Missing background-selector data now defaults to an empty array, nested null URL lists are normalized to empty arrays to preserve profiles sent by the bundled profiler, and other invalid data types return a 400 rest_invalid_param response instead of causing an HTTP 500.

Closes #1204

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully ran tests with your changes locally?

@pirate-bot

pirate-bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

Plugin build for 2299a55 is ready 🛎️!

@girishpanchal30 girishpanchal30 changed the title fix: validate profiler payload structure Validated profiler payload structure Oct 29, 2026
@girishpanchal30
girishpanchal30 requested review from pirate-bot and removed request for pirate-bot October 29, 2026 11:14

@pirate-bot pirate-bot left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🟢 Approved

This approves the schema fix, and the notes ask you to check one new test and one helper the endpoint now reaches.

  • inc/rest.php:1006 — note A request without b now gets the default [] and reaches get_background_lazyload_selectors(). Before, it stopped at a fatal error first. That helper once failed with "Call to a member function get() on null" (#1020). Source shows it returns [] when settings are missing (inc/lazyload_replacer.php:118-121). Please confirm that settings are never missing on this route after the helper returns. If they are, the old fatal error is back.
Validation details
  • Files reviewed: 3/3 changed files. The history row "issue #1020: Call to a member function get() on null in lazyload_replacer.php:118" stayed unchecked.
  • The Test_Rest_Optimizations class passes at HEAD on WordPress 7.1.4 and PHP 8.3.36 cd /repo; set -o pipefail; timeout 280 vendor/bin/phpunit --do-not-cache-result --filter 'Test_Rest_Optimizations::' --t… (run R4, exit 0).
  • Payloads shaped like the bundled profiler's output return 200 and are stored cd /workspace/checks/C7 && sed -i 's/class C7_Payload_Shapes_Test/class C7PayloadTest/' C7PayloadTest.php && cd /repo &&… (run R13, exit 0).
  • PHPStan reports no errors in inc/rest.php cd /repo; timeout 110 vendor/bin/phpstan analyse --memory-limit=-1 --no-progress --error-format=raw 2>&1 | grep -c "rest… (run R6, exit 0).
  • The security pass found no new boundary effect. The HMAC, origin and count limits are unchanged.
Untested areas
  • The live profiler output was not captured in a browser. The payload shapes come from source and Git history.
  • The history row "issue #1020: Call to a member function get() on null in lazyload_replacer.php:118" stayed unchecked. A note covers it.

🤖 Automated review · run code-review-agent_6ae32cdfb81236.09378042.


🤖 Review agent — review posted ✅ on 23f42967 · approved · 0 findings · 32 min

Run code-review-agent_6ae32cdfb81236.09378042 · trail

Comment thread tests/test-rest-optimizations.php Resolved
@girishpanchal30

Copy link
Copy Markdown
Contributor Author

@pirate-bot

inc/rest.php:1006 — note A request without b now gets the default [] and reaches get_background_lazyload_selectors(). Before, it stopped at a fatal error first. That helper once failed with "Call to a member function get() on null" (#1020). Source shows it returns [] when settings are missing (inc/lazyload_replacer.php:118-121). Please confirm that settings are never missing on this route after the helper returns. If they are, the old fatal error is back.

Not a new exposure: every request from the bundled profiler already sends b, so it already reached get_background_lazyload_selectors() before this change. When settings are null, that helper returns [] instead of calling ->get() (inc/lazyload_replacer.php:118-121, added in 4f49a2d). With the default b = [] the loop that uses those selectors never runs, so the old "get() on null" fatal can't come back on this route.

@pirate-bot pirate-bot left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🟢 Approved

This approves the change because the only new commit removes the test that passed on the base code.

Validation details
  • Files reviewed: 3/3 changed files. Only tests/test-rest-optimizations.php changed since the last review.
  • The new commit deletes one test method. The remaining tests and their helpers are intact at HEAD.
  • Test_Rest_Optimizations passed on WordPress 7.1.4 and PHP 8.3.36. Source: run code-review-agent_6ae32cdfb81236.09378042, R4, not rerun.
  • PHPStan and the security pass found no issue in inc/rest.php. Source: the same run, not rerun. That file is unchanged since then.
Untested areas
  • The test suite was not rerun at HEAD. The only change is one deleted test method.

🤖 Automated review · run code-review-agent_6ae335db2d6658.32655223.


🤖 Review agent — review posted ✅ on 2299a551 · approved · 0 findings · 5 min

Run code-review-agent_6ae335db2d6658.32655223 · trail

@pirate-bot

Copy link
Copy Markdown
Collaborator

🎉 This PR is included in version 4.2.18 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@pirate-bot pirate-bot added the released Indicate that an issue has been resolved and released in a particular version of the product. label Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released Indicate that an issue has been resolved and released in a particular version of the product.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants