WordPress.org

Make WordPress Core

Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#39830 closed defect (bug) (wontfix)

Unable to detect REST/rest_no_route

Reported by: szepe.viktor Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.7.2
Component: REST API Keywords:
Focuses: Cc:

Description

AFAIK dispatch() in WP_REST_Server replies rest_no_route with HTTP status code 404 on its own

There is no way to detect a HTTP/404 which is elemental for my WAF
https://github.com/szepeviktor/wordpress-fail2ban/blob/master/mu-plugin/wp-fail2ban-mu-instant.php#L138-L140

Please advise.

Change History (2)

#1 @rmccue
2 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

The REST API routing system is independent of template_redirect, since it's not part of the templating system. This is by design. rest_post_dispatch or rest_pre_serve_request can be used to catch errors from the API.

(It's also possible for 404 errors to be generated inside controllers, not just by the routing. For example, a request to a nonexistent post ID will throw a 404.)

#2 @szepe.viktor
2 years ago

Thank you for your guidance.

I've chosen rest_post_dispatch for status code inspection.

Note: See TracTickets for help on using tickets.