Make WordPress Core


Ignore:
Timestamp:
10/12/2023 02:34:12 PM (3 years ago)
Author:
davidbaumwald
Message:

Grouped backports to the 4.5 branch.

  • Comments: Prevent users who can not see a post from seeing comments on it.
  • Shortcodes: Restrict media shortcode ajax to certain type.
  • REST API: Ensure no-cache headers are sent when methods are overridden.
  • Prevent unintended behavior when certain objects are unserialized.

Merges [56834], [56835], [56836], and [56838] to the 4.5 branch.
Props xknown, jorbin, joehoyle, timothyblynjacobs, peterwilsoncc, ehtis, tykoted, antpb, rmccue.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/4.5/src/wp-includes/rest-api/class-wp-rest-server.php

    r37163 r56857  
    238238
    239239        /**
    240          * Send nocache headers on authenticated requests.
    241          *
    242          * @since 4.4.0
    243          *
    244          * @param bool $rest_send_nocache_headers Whether to send no-cache headers.
    245          */
    246         $send_no_cache_headers = apply_filters( 'rest_send_nocache_headers', is_user_logged_in() );
    247         if ( $send_no_cache_headers ) {
    248             foreach ( wp_get_nocache_headers() as $header => $header_value ) {
    249                 $this->send_header( $header, $header_value );
    250             }
    251         }
    252 
    253         /**
    254          * Filter whether the REST API is enabled.
     240         * Filters whether the REST API is enabled.
    255241         *
    256242         * @since 4.4.0
     
    315301         * header.
    316302         */
     303        $method_overridden = false;
    317304        if ( isset( $_GET['_method'] ) ) {
    318305            $request->set_method( $_GET['_method'] );
    319306        } elseif ( isset( $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] ) ) {
    320307            $request->set_method( $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] );
     308            $method_overridden = true;
    321309        }
    322310
     
    376364         */
    377365        $served = apply_filters( 'rest_pre_serve_request', false, $result, $request, $this );
     366
     367        /**
     368         * Filters whether to send nocache headers on a REST API request.
     369         *
     370         * @since 4.4.0
     371         * @since 6.x.x Moved the block to catch the filter added on rest_cookie_check_errors() from rest-api.php
     372         *
     373         * @param bool $rest_send_nocache_headers Whether to send no-cache headers.
     374         */
     375        $send_no_cache_headers = apply_filters( 'rest_send_nocache_headers', is_user_logged_in() );
     376
     377        // send no cache headers if the $send_no_cache_headers is true
     378        // OR if the HTTP_X_HTTP_METHOD_OVERRIDE is used but resulted a 4xx response code.
     379        if ( $send_no_cache_headers || ( true === $method_overridden && strpos( $code, '4' ) === 0 ) ) {
     380            foreach ( wp_get_nocache_headers() as $header => $header_value ) {
     381                $this->send_header( $header, $header_value );
     382            }
     383        }
    378384
    379385        if ( ! $served ) {
Note: See TracChangeset for help on using the changeset viewer.