Make WordPress Core

Changeset 56876

Timestamp:
10/12/2023 03:04:07 PM (9 months ago)
Author:
davidbaumwald
Message:

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

Location:
branches/5.2
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • branches/5.2

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

    r55789 r56876  
    35113511    $shortcode = wp_unslash( $_POST['shortcode'] );
    35123512
     3513
     3514
     3515
     3516
     3517
     3518
     3519
     3520
     3521
     3522
     3523
     3524
     3525
     3526
     3527
     3528
    35133529    if ( ! empty( $_POST['post_ID'] ) ) {
    35143530        $post = get_post( (int) $_POST['post_ID'] );
     
    35173533    // the embed shortcode requires a post
    35183534    if ( ! $post || ! current_user_can( 'edit_post', $post->ID ) ) {
    3519         if ( 'embed' === $shortcode ) {
     3535        if ( ) {
    35203536            wp_send_json_error();
    35213537        }
  • branches/5.2/src/wp-admin/includes/class-wp-comments-list-table.php

    r44759 r56876  
    555555        $this->user_can = current_user_can( 'edit_comment', $comment->comment_ID );
    556556
     557
     558
     559
     560
     561
     562
     563
     564
     565
     566
     567
     568
     569
    557570        echo "<tr id='comment-$comment->comment_ID' class='$the_comment_class'>";
    558571        $this->single_row_columns( $comment );
  • branches/5.2/src/wp-admin/includes/class-wp-list-table.php

    r44574 r56876  
    666666        $pending_phrase       = sprintf( _n( '%s pending comment', '%s pending comments', $pending_comments ), $pending_comments_number );
    667667
    668         // No comments at all.
     668        $post_object   = get_post( $post_id );
     669        $edit_post_cap = $post_object ? 'edit_post' : 'edit_posts';
     670        if (
     671            current_user_can( $edit_post_cap, $post_id ) ||
     672            (
     673                empty( $post_object->post_password ) &&
     674                current_user_can( 'read_post', $post_id )
     675            )
     676        ) {
     677            // The user has access to the post and thus can see comments
     678        } else {
     679            return false;
     680        }
     681
    669682        if ( ! $approved_comments && ! $pending_comments ) {
    670683            printf(
  • branches/5.2/src/wp-admin/includes/dashboard.php

    r45510 r56876  
    946946        echo '<ul id="the-comment-list" data-wp-lists="list:comment">';
    947947        foreach ( $comments as $comment ) {
    948             _wp_dashboard_recent_comments_row( $comment );
     948            $comment_post = get_post( $comment->comment_post_ID );
     949            if (
     950                current_user_can( 'edit_post', $comment->comment_post_ID ) ||
     951                (
     952                    empty( $comment_post->post_password ) &&
     953                    current_user_can( 'read_post', $comment->comment_post_ID )
     954                )
     955            ) {
     956                _wp_dashboard_recent_comments_row( $comment );
     957            }
    949958        }
    950959        echo '</ul>';
  • branches/5.2/src/wp-includes/Requests/Hooks.php

    r38049 r56876  
    6666        return true;
    6767    }
     68
     69
     70
     71
    6872}
  • branches/5.2/src/wp-includes/Requests/IRI.php

    r38727 r56876  
    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.2/src/wp-includes/Requests/Session.php

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

    r44108 r56876  
    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.2/src/wp-includes/class-wp-theme.php

    r45080 r56876  
    632632
    633633    /**
     634
     635
     636
     637
     638
     639
     640
     641
     642
     643
     644
     645
     646
     647
     648
     649
     650
     651
     652
     653
     654
     655
    634656     * Adds theme data to cache.
    635657     *
     
    16091631        return strnatcasecmp( $a->name_translated, $b->name_translated );
    16101632    }
     1633
     1634
     1635
     1636
     1637
     1638
     1639
     1640
     1641
     1642
     1643
     1644
    16111645}
  • branches/5.2/src/wp-includes/media.php

    r55789 r56876  
    17481748        }
    17491749    } elseif ( ! empty( $atts['exclude'] ) ) {
    1750         $attachments = get_children(
     1750        $post_parent_id = $id;
     1751        $attachments    = get_children(
    17511752            array(
    17521753                'post_parent'    => $id,
     
    17601761        );
    17611762    } else {
    1762         $attachments = get_children(
     1763        $post_parent_id = $id;
     1764        $attachments    = get_children(
    17631765            array(
    17641766                'post_parent'    => $id,
     
    17701772            )
    17711773        );
     1774
     1775
     1776
     1777
     1778
     1779
     1780
     1781
     1782
     1783
     1784
    17721785    }
    17731786
     
    20792092    }
    20802093
     2094
     2095
     2096
     2097
     2098
     2099
     2100
     2101
     2102
    20812103    if ( empty( $attachments ) ) {
    20822104        return '';
  • branches/5.2/src/wp-includes/rest-api.php

    r46545 r56876  
    842842
    843843    if ( ! $result ) {
     844
    844845        return new WP_Error( 'rest_cookie_invalid_nonce', __( 'Cookie nonce is invalid' ), array( 'status' => 403 ) );
    845846    }
  • branches/5.2/src/wp-includes/rest-api/class-wp-rest-server.php

    r43582 r56876  
    240240
    241241        /**
    242          * Send nocache headers on authenticated requests.
    243          *
    244          * @since 4.4.0
    245          *
    246          * @param bool $rest_send_nocache_headers Whether to send no-cache headers.
    247          */
    248         $send_no_cache_headers = apply_filters( 'rest_send_nocache_headers', is_user_logged_in() );
    249         if ( $send_no_cache_headers ) {
    250             foreach ( wp_get_nocache_headers() as $header => $header_value ) {
    251                 if ( empty( $header_value ) ) {
    252                     $this->remove_header( $header );
    253                 } else {
    254                     $this->send_header( $header, $header_value );
    255                 }
    256             }
    257         }
    258 
    259         /**
    260242         * Filters whether the REST API is enabled.
    261243         *
     
    318300         * header.
    319301         */
     302
    320303        if ( isset( $_GET['_method'] ) ) {
    321304            $request->set_method( $_GET['_method'] );
    322305        } elseif ( isset( $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] ) ) {
    323306            $request->set_method( $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] );
     307
    324308        }
    325309
     
    379363         */
    380364        $served = apply_filters( 'rest_pre_serve_request', false, $result, $request, $this );
     365
     366
     367
     368
     369
     370
     371
     372
     373
     374
     375
     376
     377
     378
     379
     380
     381
     382
     383
     384
     385
     386
    381387
    382388        if ( ! $served ) {
  • branches/5.2/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php

    r45267 r56876  
    284284
    285285        if ( ! empty( $prepared_args['search'] ) ) {
     286
     287
     288
    286289            $prepared_args['search'] = '*' . $prepared_args['search'] . '*';
    287290        }
  • branches/5.2/src/wp-includes/shortcodes.php

    r43549 r56876  
    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 * If there are no shortcode tags defined, then the content will be returned
Note: See TracChangeset for help on using the changeset viewer.