Make WordPress Core

Changeset 56878

Timestamp:
10/12/2023 03:06:49 PM (10 months ago)
Author:
davidbaumwald
Message:

Grouped backports to the 5.4 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.
  • REST API: Limit search_columns for users without list_users.
  • Prevent unintended behavior when certain objects are unserialized.

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

Location:
branches/5.4
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • branches/5.4

  • branches/5.4/src/wp-admin/includes/ajax-actions.php

    r55785 r56878  
    37403740    $shortcode = wp_unslash( $_POST['shortcode'] );
    37413741
     3742
     3743
     3744
     3745
     3746
     3747
     3748
     3749
     3750
     3751
     3752
     3753
     3754
     3755
     3756
     3757
    37423758    if ( ! empty( $_POST['post_ID'] ) ) {
    37433759        $post = get_post( (int) $_POST['post_ID'] );
     
    37463762    // The embed shortcode requires a post.
    37473763    if ( ! $post || ! current_user_can( 'edit_post', $post->ID ) ) {
    3748         if ( 'embed' === $shortcode ) {
     3764        if ( ) {
    37493765            wp_send_json_error();
    37503766        }
  • branches/5.4/src/wp-admin/includes/class-wp-comments-list-table.php

    r47234 r56878  
    562562        $this->user_can = current_user_can( 'edit_comment', $comment->comment_ID );
    563563
     564
     565
     566
     567
     568
     569
     570
     571
     572
     573
     574
     575
     576
    564577        echo "<tr id='comment-$comment->comment_ID' class='$the_comment_class'>";
    565578        $this->single_row_columns( $comment );
  • branches/5.4/src/wp-admin/includes/class-wp-list-table.php

    r47219 r56878  
    683683        );
    684684
    685         // No comments at all.
     685        $post_object   = get_post( $post_id );
     686        $edit_post_cap = $post_object ? 'edit_post' : 'edit_posts';
     687        if (
     688            current_user_can( $edit_post_cap, $post_id ) ||
     689            (
     690                empty( $post_object->post_password ) &&
     691                current_user_can( 'read_post', $post_id )
     692            )
     693        ) {
     694            // The user has access to the post and thus can see comments
     695        } else {
     696            return false;
     697        }
     698
    686699        if ( ! $approved_comments && ! $pending_comments ) {
    687700            printf(
  • branches/5.4/src/wp-admin/includes/dashboard.php

    r47415 r56878  
    10351035        echo '<ul id="the-comment-list" data-wp-lists="list:comment">';
    10361036        foreach ( $comments as $comment ) {
    1037             _wp_dashboard_recent_comments_row( $comment );
     1037            $comment_post = get_post( $comment->comment_post_ID );
     1038            if (
     1039                current_user_can( 'edit_post', $comment->comment_post_ID ) ||
     1040                (
     1041                    empty( $comment_post->post_password ) &&
     1042                    current_user_can( 'read_post', $comment->comment_post_ID )
     1043                )
     1044            ) {
     1045                _wp_dashboard_recent_comments_row( $comment );
     1046            }
    10381047        }
    10391048        echo '</ul>';
  • branches/5.4/src/wp-includes/Requests/Hooks.php

    r46586 r56878  
    6666        return true;
    6767    }
     68
     69
     70
     71
    6872}
  • branches/5.4/src/wp-includes/Requests/IRI.php

    r46586 r56878  
    704704    }
    705705
     706
     707
     708
     709
     710
     711
     712
     713
     714
     715
     716
     717
     718
     719
    706720    /**
    707721     * Set the entire IRI. Returns true on success, false on failure (if there
  • branches/5.4/src/wp-includes/Requests/Session.php

    r46586 r56878  
    228228    }
    229229
     230
     231
     232
     233
    230234    /**
    231235     * Merge a request's data with the default data
  • branches/5.4/src/wp-includes/class-wp-block-type-registry.php

    r46586 r56878  
    155155    }
    156156
     157
     158
     159
     160
     161
     162
     163
     164
     165
     166
     167
     168
     169
     170
    157171    /**
    158172     * Utility method to retrieve the main instance of the class.
  • branches/5.4/src/wp-includes/class-wp-theme.php

    r47397 r56878  
    677677
    678678    /**
     679
     680
     681
     682
     683
     684
     685
     686
     687
     688
     689
     690
     691
     692
     693
     694
     695
     696
     697
     698
     699
     700
    679701     * Adds theme data to cache.
    680702     *
     
    16681690        return strnatcasecmp( $a->name_translated, $b->name_translated );
    16691691    }
     1692
     1693
     1694
     1695
     1696
     1697
     1698
     1699
     1700
     1701
     1702
     1703
    16701704}
  • branches/5.4/src/wp-includes/media.php

    r55785 r56878  
    19311931        }
    19321932    } elseif ( ! empty( $atts['exclude'] ) ) {
    1933         $attachments = get_children(
     1933        $post_parent_id = $id;
     1934        $attachments    = get_children(
    19341935            array(
    19351936                'post_parent'    => $id,
     
    19431944        );
    19441945    } else {
    1945         $attachments = get_children(
     1946        $post_parent_id = $id;
     1947        $attachments    = get_children(
    19461948            array(
    19471949                'post_parent'    => $id,
     
    19531955            )
    19541956        );
     1957
     1958
     1959
     1960
     1961
     1962
     1963
     1964
     1965
     1966
     1967
    19551968    }
    19561969
     
    22732286    }
    22742287
     2288
     2289
     2290
     2291
     2292
     2293
     2294
     2295
     2296
    22752297    if ( empty( $attachments ) ) {
    22762298        return '';
  • branches/5.4/src/wp-includes/rest-api.php

    r47843 r56878  
    921921
    922922    if ( ! $result ) {
     923
    923924        return new WP_Error( 'rest_cookie_invalid_nonce', __( 'Cookie nonce is invalid' ), array( 'status' => 403 ) );
    924925    }
  • branches/5.4/src/wp-includes/rest-api/class-wp-rest-server.php

    r47351 r56878  
    248248
    249249        /**
    250          * Send nocache headers on authenticated requests.
    251          *
    252          * @since 4.4.0
    253          *
    254          * @param bool $rest_send_nocache_headers Whether to send no-cache headers.
    255          */
    256         $send_no_cache_headers = apply_filters( 'rest_send_nocache_headers', is_user_logged_in() );
    257         if ( $send_no_cache_headers ) {
    258             foreach ( wp_get_nocache_headers() as $header => $header_value ) {
    259                 if ( empty( $header_value ) ) {
    260                     $this->remove_header( $header );
    261                 } else {
    262                     $this->send_header( $header, $header_value );
    263                 }
    264             }
    265         }
    266 
    267         /**
    268250         * Filters whether the REST API is enabled.
    269251         *
     
    331313         * header.
    332314         */
     315
    333316        if ( isset( $_GET['_method'] ) ) {
    334317            $request->set_method( $_GET['_method'] );
    335318        } elseif ( isset( $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] ) ) {
    336319            $request->set_method( $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] );
     320
    337321        }
    338322
     
    392376         */
    393377        $served = apply_filters( 'rest_pre_serve_request', false, $result, $request, $this );
     378
     379
     380
     381
     382
     383
     384
     385
     386
     387
     388
     389
     390
     391
     392
     393
     394
     395
     396
     397
     398
     399
    394400
    395401        if ( ! $served ) {
  • branches/5.4/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php

    r47397 r56878  
    303303
    304304        if ( ! empty( $prepared_args['search'] ) ) {
     305
     306
     307
    305308            $prepared_args['search'] = '*' . $prepared_args['search'] . '*';
    306309        }
  • branches/5.4/src/wp-includes/shortcodes.php

    r47219 r56878  
    161161
    162162/**
    163  * Search content for shortcodes and filter shortcodes through their hooks.
     163 * Returns a list of registered shortcode names found in the given content.
     164 *
     165 * Example usage:
     166 *
     167 *     get_shortcode_tags_in_content( '[audio src="file.mp3"][/audio] [foo] [gallery ids="1,2,3"]' );
     168 *     // array( 'audio', 'gallery' )
     169 *
     170 * @since 6.3.2
     171 *
     172 * @param string $content The content to check.
     173 * @return string[] An array of registered shortcode names found in the content.
     174 */
     175function get_shortcode_tags_in_content( $content ) {
     176    if ( false === strpos( $content, '[' ) ) {
     177        return array();
     178    }
     179
     180    preg_match_all( '/' . get_shortcode_regex() . '/', $content, $matches, PREG_SET_ORDER );
     181    if ( empty( $matches ) ) {
     182        return array();
     183    }
     184
     185    $tags = array();
     186    foreach ( $matches as $shortcode ) {
     187        $tags[] = $shortcode[2];
     188
     189        if ( ! empty( $shortcode[5] ) ) {
     190            $deep_tags = get_shortcode_tags_in_content( $shortcode[5] );
     191            if ( ! empty( $deep_tags ) ) {
     192                $tags = array_merge( $tags, $deep_tags );
     193            }
     194        }
     195    }
     196
     197    return $tags;
     198}
     199
     200/**
     201 * Searches content for shortcodes and filter shortcodes through their hooks.
    164202 *
    165203 * This function is an alias for do_shortcode().
Note: See TracChangeset for help on using the changeset viewer.