Make WordPress Core

Changeset 56862

Timestamp:
10/12/2023 02:48:17 PM (9 months ago)
Author:
davidbaumwald
Message:

Grouped backports to the 4.7 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 [56834], [56835], [56836], [56838], and [56840] to the 4.7 branch.
Props xknown, jorbin, joehoyle, timothyblynjacobs, peterwilsoncc, ehtis, tykoted, antpb, rmccue.

Location:
branches/4.7/src
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • branches/4.7/src/wp-admin/includes/ajax-actions.php

    r55784 r56862  
    30443044    $shortcode = wp_unslash( $_POST['shortcode'] );
    30453045
     3046
     3047
     3048
     3049
     3050
     3051
     3052
     3053
     3054
     3055
     3056
     3057
     3058
     3059
     3060
     3061
    30463062    if ( ! empty( $_POST['post_ID'] ) ) {
    30473063        $post = get_post( (int) $_POST['post_ID'] );
     
    30503066    // the embed shortcode requires a post
    30513067    if ( ! $post || ! current_user_can( 'edit_post', $post->ID ) ) {
    3052         if ( 'embed' === $shortcode ) {
     3068        if ( ) {
    30533069            wp_send_json_error();
    30543070        }
  • branches/4.7/src/wp-admin/includes/class-wp-comments-list-table.php

    r38672 r56862  
    495495        $this->user_can = current_user_can( 'edit_comment', $comment->comment_ID );
    496496
     497
     498
     499
     500
     501
     502
     503
     504
     505
     506
     507
     508
     509
    497510        echo "<tr id='comment-$comment->comment_ID' class='$the_comment_class'>";
    498511        $this->single_row_columns( $comment );
  • branches/4.7/src/wp-admin/includes/class-wp-list-table.php

    r38672 r56862  
    655655        $pending_phrase = sprintf( _n( '%s pending comment', '%s pending comments', $pending_comments ), $pending_comments_number );
    656656
    657         // No comments at all.
     657        $post_object   = get_post( $post_id );
     658        $edit_post_cap = $post_object ? 'edit_post' : 'edit_posts';
     659        if (
     660            current_user_can( $edit_post_cap, $post_id ) ||
     661            (
     662                empty( $post_object->post_password ) &&
     663                current_user_can( 'read_post', $post_id )
     664            )
     665        ) {
     666            // The user has access to the post and thus can see comments
     667        } else {
     668            return false;
     669        }
     670
    658671        if ( ! $approved_comments && ! $pending_comments ) {
    659672            printf( '<span aria-hidden="true">—</span><span class="screen-reader-text">%s</span>',
  • branches/4.7/src/wp-admin/includes/dashboard.php

    r39326 r56862  
    920920
    921921        echo '<ul id="the-comment-list" data-wp-lists="list:comment">';
    922         foreach ( $comments as $comment )
    923             _wp_dashboard_recent_comments_row( $comment );
     922        foreach ( $comments as $comment ) {
     923            $comment_post = get_post( $comment->comment_post_ID );
     924            if (
     925                current_user_can( 'edit_post', $comment->comment_post_ID ) ||
     926                (
     927                    empty( $comment_post->post_password ) &&
     928                    current_user_can( 'read_post', $comment->comment_post_ID )
     929                )
     930            ) {
     931                _wp_dashboard_recent_comments_row( $comment );
     932            }
     933        }
    924934        echo '</ul>';
    925935
  • branches/4.7/src/wp-includes/Requests/Hooks.php

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

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

    r38049 r56862  
    228228    }
    229229
     230
     231
     232
     233
    230234    /**
    231235     * Merge a request's data with the default data
  • branches/4.7/src/wp-includes/class-wp-theme.php

    r40326 r56862  
    532532
    533533    /**
     534
     535
     536
     537
     538
     539
     540
     541
     542
     543
     544
     545
     546
     547
     548
     549
     550
     551
     552
     553
     554
     555
    534556     * Adds theme data to cache.
    535557     *
     
    14971519        return strnatcasecmp( $a->display( 'Name', false, true ), $b->display( 'Name', false, true ) );
    14981520    }
     1521
     1522
     1523
     1524
     1525
     1526
     1527
     1528
     1529
     1530
     1531
     1532
    14991533}
  • branches/4.7/src/wp-includes/media.php

    r55784 r56862  
    16881688        }
    16891689    } elseif ( ! empty( $atts['exclude'] ) ) {
     1690
    16901691        $attachments = get_children( array( 'post_parent' => $id, 'exclude' => $atts['exclude'], 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $atts['order'], 'orderby' => $atts['orderby'] ) );
    16911692    } else {
     1693
    16921694        $attachments = get_children( array( 'post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $atts['order'], 'orderby' => $atts['orderby'] ) );
     1695
     1696
     1697
     1698
     1699
     1700
     1701
     1702
     1703
     1704
     1705
    16931706    }
    16941707
     
    19922005    }
    19932006
     2007
     2008
     2009
     2010
     2011
     2012
     2013
     2014
     2015
    19942016    if ( empty( $attachments ) ) {
    19952017        return '';
  • branches/4.7/src/wp-includes/rest-api.php

    r46495 r56862  
    726726
    727727    if ( ! $result ) {
     728
    728729        return new WP_Error( 'rest_cookie_invalid_nonce', __( 'Cookie nonce is invalid' ), array( 'status' => 403 ) );
    729730    }
  • branches/4.7/src/wp-includes/rest-api/class-wp-rest-server.php

    r40336 r56862  
    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         *
     
    312298         * header.
    313299         */
     300
    314301        if ( isset( $_GET['_method'] ) ) {
    315302            $request->set_method( $_GET['_method'] );
    316303        } elseif ( isset( $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] ) ) {
    317304            $request->set_method( $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] );
     305
    318306        }
    319307
     
    373361         */
    374362        $served = apply_filters( 'rest_pre_serve_request', false, $result, $request, $this );
     363
     364
     365
     366
     367
     368
     369
     370
     371
     372
     373
     374
     375
     376
     377
     378
     379
     380
    375381
    376382        if ( ! $served ) {
  • branches/4.7/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php

    r40426 r56862  
    260260
    261261        if ( ! empty( $prepared_args['search'] ) ) {
     262
     263
     264
    262265            $prepared_args['search'] = '*' . $prepared_args['search'] . '*';
    263266        }
  • branches/4.7/src/wp-includes/shortcodes.php

    r39351 r56862  
    186186
    187187/**
    188  * Search content for shortcodes and filter shortcodes through their hooks.
     188 * Returns a list of registered shortcode names found in the given content.
     189 *
     190 * Example usage:
     191 *
     192 *     get_shortcode_tags_in_content( '[audio src="file.mp3"][/audio] [foo] [gallery ids="1,2,3"]' );
     193 *     // array( 'audio', 'gallery' )
     194 *
     195 * @since 6.3.2
     196 *
     197 * @param string $content The content to check.
     198 * @return string[] An array of registered shortcode names found in the content.
     199 */
     200function get_shortcode_tags_in_content( $content ) {
     201    if ( false === strpos( $content, '[' ) ) {
     202        return array();
     203    }
     204
     205    preg_match_all( '/' . get_shortcode_regex() . '/', $content, $matches, PREG_SET_ORDER );
     206    if ( empty( $matches ) ) {
     207        return array();
     208    }
     209
     210    $tags = array();
     211    foreach ( $matches as $shortcode ) {
     212        $tags[] = $shortcode[2];
     213
     214        if ( ! empty( $shortcode[5] ) ) {
     215            $deep_tags = get_shortcode_tags_in_content( $shortcode[5] );
     216            if ( ! empty( $deep_tags ) ) {
     217                $tags = array_merge( $tags, $deep_tags );
     218            }
     219        }
     220    }
     221
     222    return $tags;
     223}
     224
     225/**
     226 * Searches content for shortcodes and filter shortcodes through their hooks.
    189227 *
    190228 * If there are no shortcode tags defined, then the content will be returned
Note: See TracChangeset for help on using the changeset viewer.