Make WordPress Core


Ignore:
Timestamp:
10/12/2023 04:07:43 PM (8 months ago)
Author:
joemcgill
Message:

Grouped backports to the 6.2 branch.

  • REST API: Limit search_columns for users without list_users.
  • Comments: Prevent users who can not see a post from seeing comments on it.
  • Application Passwords: Prevent the use of some pseudo protocols in application passwords.
  • Restrict media shortcode ajax to certain type
  • REST API: Ensure no-cache headers are sent when methods are overriden.
  • Prevent unintended behavior when certain objects are unserialized.

Merges [56833], [56834], [56835], [56836], [56837], and [56838] to the 6.2 branch.
Props xknown, jorbin, Vortfu, joehoyle, timothyblynjacobs, peterwilsoncc, ehtis, tykoted, martinkrcho, paulkevan, dd32, antpb, rmccue.

Location:
branches/6.2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/6.2

  • branches/6.2/src/wp-includes/rest-api/class-wp-rest-server.php

    r55361 r56895  
    360360
    361361        /**
    362          * Filters whether to send nocache headers on a REST API request.
    363          *
    364          * @since 4.4.0
    365          *
    366          * @param bool $rest_send_nocache_headers Whether to send no-cache headers.
    367          */
    368         $send_no_cache_headers = apply_filters( 'rest_send_nocache_headers', is_user_logged_in() );
    369         if ( $send_no_cache_headers ) {
    370             foreach ( wp_get_nocache_headers() as $header => $header_value ) {
    371                 if ( empty( $header_value ) ) {
    372                     $this->remove_header( $header );
    373                 } else {
    374                     $this->send_header( $header, $header_value );
    375                 }
    376             }
    377         }
    378 
    379         /**
    380362         * Filters whether the REST API is enabled.
    381363         *
     
    431413         * header.
    432414         */
     415        $method_overridden = false;
    433416        if ( isset( $_GET['_method'] ) ) {
    434417            $request->set_method( $_GET['_method'] );
    435418        } elseif ( isset( $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] ) ) {
    436419            $request->set_method( $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] );
     420            $method_overridden = true;
    437421        }
    438422
     
    493477         */
    494478        $served = apply_filters( 'rest_pre_serve_request', false, $result, $request, $this );
     479
     480        /**
     481         * Filters whether to send nocache headers on a REST API request.
     482         *
     483         * @since 4.4.0
     484         * @since 6.x.x Moved the block to catch the filter added on rest_cookie_check_errors() from rest-api.php
     485         *
     486         * @param bool $rest_send_nocache_headers Whether to send no-cache headers.
     487         */
     488        $send_no_cache_headers = apply_filters( 'rest_send_nocache_headers', is_user_logged_in() );
     489
     490        // send no cache headers if the $send_no_cache_headers is true
     491        // OR if the HTTP_X_HTTP_METHOD_OVERRIDE is used but resulted a 4xx response code.
     492        if ( $send_no_cache_headers || ( true === $method_overridden && strpos( $code, '4' ) === 0 ) ) {
     493            foreach ( wp_get_nocache_headers() as $header => $header_value ) {
     494                if ( empty( $header_value ) ) {
     495                    $this->remove_header( $header );
     496                } else {
     497                    $this->send_header( $header, $header_value );
     498                }
     499            }
     500        }
    495501
    496502        if ( ! $served ) {
Note: See TracChangeset for help on using the changeset viewer.