[wp-trac] [WordPress Trac] #51547: Error checking in site health async cron tasks

WordPress Trac noreply at wordpress.org
Fri Oct 16 04:50:54 UTC 2020


#51547: Error checking in site health async cron tasks
--------------------------+-----------------------------
 Reporter:  dd32          |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Site Health   |    Version:  5.4
 Severity:  normal        |   Keywords:  needs-patch
  Focuses:                |
--------------------------+-----------------------------
 The following PHP Notice is generated by the Site Health cron tasks:

 {{{
 Notice: Undefined index: status in wp-admin/includes/class-wp-site-
 health.php on line 2594

 Call Stack:
 ...
     0.7033   53046672   3. WP_Hook->do_action() wp-includes/plugin.php:544
     0.7033   53046672   4. WP_Hook->apply_filters() wp-includes/class-wp-
 hook.php:311
     0.7033   53047800   5. WP_Site_Health->wp_cron_scheduled_check() wp-
 includes/class-wp-hook.php:287
 }}}

 The `$result` value that it's processing at the time contains:
 {{{
   array(3) {
     'code' =>
     string(13) "rest_no_route"
     'message' =>
     string(55) "No route was found matching the URL and request method."
     'data' =>
     array(1) {
       'status' =>
       int(404)
     }
 }}}

 It appears that it happens when the {{{wp-site-health/v1/tests/*}}} REST
 API endpoints are called from cron.

 There's two issues here:
  1. [https://core.trac.wordpress.org/browser/trunk/src/wp-admin/includes
 /class-wp-site-health.php?marks=2555-2562,2575,2581-2582#L2552 The code]
 assumes that the only error conditional is a `WP_Error` from a HTTP
 failure. A wp-json REST API error is not a WP_Error, it's a standard array
 response.
  2. The Admin Ajax and REST API callbacks as run from cron are not adding
 any form of authentication, and so, will never work. The nonce attached
 would be for an anonymous user and as none of these endpoints are
 available unauthenticated do not pass.

 I believe this is a followup to #47606 and it's prominence has only been
 noticed due to the changed in #48105 triggering these notices.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/51547>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list