Make WordPress Core


Ignore:
Timestamp:
10/12/2023 02:43:19 PM (17 months ago)
Author:
davidbaumwald
Message:

Grouped backports to the 4.6 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.6 branch.
Props xknown, jorbin, joehoyle, timothyblynjacobs, peterwilsoncc, ehtis, tykoted, antpb, rmccue.

File:
1 edited

Legend:

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

    r38037 r56859  
    244244
    245245        /**
    246          * Send nocache headers on authenticated requests.
    247          *
    248          * @since 4.4.0
    249          *
    250          * @param bool $rest_send_nocache_headers Whether to send no-cache headers.
    251          */
    252         $send_no_cache_headers = apply_filters( 'rest_send_nocache_headers', is_user_logged_in() );
    253         if ( $send_no_cache_headers ) {
    254             foreach ( wp_get_nocache_headers() as $header => $header_value ) {
    255                 $this->send_header( $header, $header_value );
    256             }
    257         }
    258 
    259         /**
    260246         * Filters whether the REST API is enabled.
    261247         *
     
    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.