Make WordPress Core

Changeset 56841

Timestamp:
10/12/2023 01:13:02 PM (10 months ago)
Author:
audrasjb
Message:

REST API: Ensure no-cache headers are sent when methods are ovverriden.

Props tykoted, xknown, ehtis, timothyblynjacobs, peterwilsoncc, rmccue, jorbin.
Merges [56834] to the 6.3 branch.

Location:
branches/6.3
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/6.3

  • branches/6.3/src/wp-includes/rest-api.php

    r56192 r56841  
    10851085
    10861086    if ( ! $result ) {
     1087
    10871088        return new WP_Error( 'rest_cookie_invalid_nonce', __( 'Cookie check failed' ), array( 'status' => 403 ) );
    10881089    }
  • branches/6.3/src/wp-includes/rest-api/class-wp-rest-server.php

    r56193 r56841  
    324324
    325325        /**
    326          * Filters whether to send nocache headers on a REST API request.
    327          *
    328          * @since 4.4.0
    329          *
    330          * @param bool $rest_send_nocache_headers Whether to send no-cache headers.
    331          */
    332         $send_no_cache_headers = apply_filters( 'rest_send_nocache_headers', is_user_logged_in() );
    333         if ( $send_no_cache_headers ) {
    334             foreach ( wp_get_nocache_headers() as $header => $header_value ) {
    335                 if ( empty( $header_value ) ) {
    336                     $this->remove_header( $header );
    337                 } else {
    338                     $this->send_header( $header, $header_value );
    339                 }
    340             }
    341         }
    342 
    343         /**
    344326         * Filters whether the REST API is enabled.
    345327         *
     
    395377         * header.
    396378         */
     379
    397380        if ( isset( $_GET['_method'] ) ) {
    398381            $request->set_method( $_GET['_method'] );
    399382        } elseif ( isset( $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] ) ) {
    400383            $request->set_method( $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] );
     384
    401385        }
    402386
     
    498482         */
    499483        $served = apply_filters( 'rest_pre_serve_request', false, $result, $request, $this );
     484
     485
     486
     487
     488
     489
     490
     491
     492
     493
     494
     495
     496
     497
     498
     499
     500
     501
     502
     503
     504
     505
    500506
    501507        if ( ! $served ) {
Note: See TracChangeset for help on using the changeset viewer.