Index: src/wp-includes/rest-api/class-wp-rest-server.php
===================================================================
--- src/wp-includes/rest-api/class-wp-rest-server.php	(revision 37164)
+++ src/wp-includes/rest-api/class-wp-rest-server.php	(working copy)
@@ -871,6 +871,24 @@
 					}
 				}
 
+				/**
+				 * Call a filter before executing any REST API callbacks.
+				 *
+				 * Allows plugins to perform additional validation after a
+				 * request is initialized and matched to a registered route,
+				 * but before it is executed.
+				 *
+				 * Note that this filter will not be called for requests that
+				 * fail to authenticate or match to a registered route.
+				 *
+				 * @since ??
+				 *
+				 * @param WP_HTTP_Response $response Result to send to the client. Usually a WP_REST_Response.
+				 * @param WP_REST_Server   $handler  ResponseHandler instance (usually WP_REST_Server).
+				 * @param WP_REST_Request  $request  Request used to generate the response.
+				 */
+				$response = apply_filters( 'rest_request_before_callbacks', $response, $handler, $request );
+
 				if ( ! is_wp_error( $response ) ) {
 					// Check permission specified on the route.
 					if ( ! empty( $handler['permission_callback'] ) ) {
@@ -908,6 +926,28 @@
 					}
 				}
 
+				/**
+				 * Call a filter immediately after executing any REST API
+				 * callbacks.
+				 *
+				 * Allows plugins to perform any needed cleanup, for example,
+				 * to undo changes made during `rest_request_before_callbacks`.
+				 *
+				 * Note that this filter will not be called for requests that
+				 * fail to authenticate or match to a registered route.
+				 *
+				 * Note that an endpoint's `permission_callback` can still be
+				 * called after this filter - see the `rest_send_allow_header`
+				 * function.
+				 *
+				 * @since ??
+				 *
+				 * @param WP_HTTP_Response $response Result to send to the client. Usually a WP_REST_Response.
+				 * @param WP_REST_Server   $handler  ResponseHandler instance (usually WP_REST_Server).
+				 * @param WP_REST_Request  $request  Request used to generate the response.
+				 */
+				$response = apply_filters( 'rest_request_after_callbacks', $response, $handler, $request );
+
 				if ( is_wp_error( $response ) ) {
 					$response = $this->error_to_response( $response );
 				} else {
