Make WordPress Core

Changeset 64183


Ignore:
Timestamp:
10/06/2026 05:43:31 PM (5 weeks ago)
Author:
johnbillion
Message:

Security: Backport the WordPress 7.1.3 security fixes to the 4.7 branch.

  • REST API: Require both capabilities to change a post's sticky status.
  • Query: Prevent exposure of comments on unviewable posts.
  • Posts, Post Types: Fire dynamic status transition hooks only for registered statuses and post types.
  • Administration: Treat contextual help tab links as selectors.
  • Embeds: Remove support for Imgur oEmbeds.
  • HTTP: Improve relative path resolution in WP_Http::make_absolute_url().

Merges r64127, r64128, r64130, r64131, r64132, r64133 to the 4.7 branch.

Props xknown, jeremyfelt, jorbin, peterwilsoncc, ehtis, westonruter, lancewillett, jonsurrell, marcs0h, rfaile313, johnbillion, vortfu.

Location:
branches/4.7
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • branches/4.7

  • branches/4.7/src/wp-admin/js/common.js

    r40512 r64183  
    169169        link.parent('li').addClass('active');
    170170
    171         panel = $( link.attr('href') );
     171        panel = $( document ).find( link.attr('href') );
    172172
    173173        // Panels
  • branches/4.7/src/wp-includes/class-http.php

    r40690 r64183  
    945945                        // Strip all /path/../ out of the path.
    946946                        while ( strpos( $path, '../' ) > 1 ) {
    947                                 $path = preg_replace( '![^/]+/\.\./!', '', $path );
     947                                $path = preg_replace( '![^/]+/\.\./!', '', $path, -1, $segment_replacement_count );
     948                                if ( 0 === $segment_replacement_count ) {
     949                                        break;
     950                                }
    948951                        }
    949952
  • branches/4.7/src/wp-includes/class-oembed.php

    r38923 r64183  
    8484                        '#https?://(www\.)?instagr(\.am|am\.com)/p/.*#i'           => array( 'https://api.instagram.com/oembed',                          true  ),
    8585                        '#https?://(open|play)\.spotify\.com/.*#i'                 => array( 'https://embed.spotify.com/oembed/',                         true  ),
    86                         '#https?://(.+\.)?imgur\.com/.*#i'                         => array( 'http://api.imgur.com/oembed',                               true  ),
    8786                        '#https?://(www\.)?meetu(\.ps|p\.com)/.*#i'                => array( 'https://api.meetup.com/oembed',                             true  ),
    8887                        '#https?://(www\.)?issuu\.com/.+/docs/.+#i'                => array( 'https://issuu.com/oembed_wp',                               true  ),
    … …  
    156155                 * | Flickr       | flic.kr               |      Yes       | 3.6.0     |
    157156                 * | Spotify      | spotify.com           |      Yes       | 3.6.0     |
    158                  * | Imgur        | imgur.com             |      Yes       | 3.9.0     |
    159157                 * | Meetup.com   | meetup.com            |      Yes       | 3.9.0     |
    160158                 * | Meetup.com   | meetu.ps              |      Yes       | 3.9.0     |
    … …  
    193191                 * | Rdio         | rdio.com             |      Yes       | 3.6.0     | 4.4.1     |
    194192                 * | Rdio         | rd.io                |      Yes       | 3.6.0     | 4.4.1     |
     193                 * | Imgur        | imgur.com            |      Yes       | 3.9.0     | 7.1.3     |
    195194                 *
    196195                 * @see wp_oembed_add_provider()
  • branches/4.7/src/wp-includes/class-wp-query.php

    r54566 r64183  
    28872887                }
    28882888
    2889                 if ( !empty($this->posts) && $this->is_comment_feed && $this->is_singular ) {
    2890                         /** This filter is documented in wp-includes/query.php */
    2891                         $cjoin = apply_filters_ref_array( 'comment_feed_join', array( '', &$this ) );
    2892 
    2893                         /** This filter is documented in wp-includes/query.php */
    2894                         $cwhere = apply_filters_ref_array( 'comment_feed_where', array( "WHERE comment_post_ID = '{$this->posts[0]->ID}' AND comment_approved = '1'", &$this ) );
    2895 
    2896                         /** This filter is documented in wp-includes/query.php */
    2897                         $cgroupby = apply_filters_ref_array( 'comment_feed_groupby', array( '', &$this ) );
    2898                         $cgroupby = ( ! empty( $cgroupby ) ) ? 'GROUP BY ' . $cgroupby : '';
    2899 
    2900                         /** This filter is documented in wp-includes/query.php */
    2901                         $corderby = apply_filters_ref_array( 'comment_feed_orderby', array( 'comment_date_gmt DESC', &$this ) );
    2902                         $corderby = ( ! empty( $corderby ) ) ? 'ORDER BY ' . $corderby : '';
    2903 
    2904                         /** This filter is documented in wp-includes/query.php */
    2905                         $climits = apply_filters_ref_array( 'comment_feed_limits', array( 'LIMIT ' . get_option('posts_per_rss'), &$this ) );
    2906 
    2907                         $comments_request = "SELECT {$wpdb->comments}.* FROM {$wpdb->comments} $cjoin $cwhere $cgroupby $corderby $climits";
    2908                         $comments = $wpdb->get_results($comments_request);
    2909                         // Convert to WP_Comment
    2910                         $this->comments = array_map( 'get_comment', $comments );
    2911                         $this->comment_count = count($this->comments);
    2912                 }
    2913 
    29142889                // Check post status to determine if post should be displayed.
    29152890                if ( !empty($this->posts) && ($this->is_single || $this->is_page) ) {
    … …  
    29602935                }
    29612936
     2937                if ( !empty($this->posts) && $this->is_comment_feed && $this->is_singular ) {
     2938                        /** This filter is documented in wp-includes/query.php */
     2939                        $cjoin = apply_filters_ref_array( 'comment_feed_join', array( '', &$this ) );
     2940
     2941                        /** This filter is documented in wp-includes/query.php */
     2942                        $cwhere = apply_filters_ref_array( 'comment_feed_where', array( "WHERE comment_post_ID = '{$this->posts[0]->ID}' AND comment_approved = '1'", &$this ) );
     2943
     2944                        /** This filter is documented in wp-includes/query.php */
     2945                        $cgroupby = apply_filters_ref_array( 'comment_feed_groupby', array( '', &$this ) );
     2946                        $cgroupby = ( ! empty( $cgroupby ) ) ? 'GROUP BY ' . $cgroupby : '';
     2947
     2948                        /** This filter is documented in wp-includes/query.php */
     2949                        $corderby = apply_filters_ref_array( 'comment_feed_orderby', array( 'comment_date_gmt DESC', &$this ) );
     2950                        $corderby = ( ! empty( $corderby ) ) ? 'ORDER BY ' . $corderby : '';
     2951
     2952                        /** This filter is documented in wp-includes/query.php */
     2953                        $climits = apply_filters_ref_array( 'comment_feed_limits', array( 'LIMIT ' . get_option('posts_per_rss'), &$this ) );
     2954
     2955                        $comments_request = "SELECT {$wpdb->comments}.* FROM {$wpdb->comments} $cjoin $cwhere $cgroupby $corderby $climits";
     2956                        $comments = $wpdb->get_results($comments_request);
     2957                        // Convert to WP_Comment
     2958                        $this->comments = array_map( 'get_comment', $comments );
     2959                        $this->comment_count = count($this->comments);
     2960                }
     2961
    29622962                // Put sticky posts at the top of the posts array
    29632963                $sticky_posts = get_option('sticky_posts');
  • branches/4.7/src/wp-includes/post.php

    r54566 r64183  
    40614061        do_action( 'transition_post_status', $new_status, $old_status, $post );
    40624062
    4063         /**
    4064          * Fires when a post is transitioned from one status to another.
    4065          *
    4066          * The dynamic portions of the hook name, `$new_status` and `$old status`,
    4067          * refer to the old and new post statuses, respectively.
    4068          *
    4069          * @since 2.3.0
    4070          *
    4071          * @param WP_Post $post Post object.
    4072          */
    4073         do_action( "{$old_status}_to_{$new_status}", $post );
    4074 
    4075         /**
    4076          * Fires when a post is transitioned from one status to another.
    4077          *
    4078          * The dynamic portions of the hook name, `$new_status` and `$post->post_type`,
    4079          * refer to the new post status and post type, respectively.
    4080          *
    4081          * Please note: When this action is hooked using a particular post status (like
    4082          * 'publish', as `publish_{$post->post_type}`), it will fire both when a post is
    4083          * first transitioned to that status from something else, as well as upon
    4084          * subsequent post updates (old and new status are both the same).
    4085          *
    4086          * Therefore, if you are looking to only fire a callback when a post is first
    4087          * transitioned to a status, use the {@see 'transition_post_status'} hook instead.
    4088          *
    4089          * @since 2.3.0
    4090          *
    4091          * @param int     $post_id Post ID.
    4092          * @param WP_Post $post    Post object.
    4093          */
    4094         do_action( "{$new_status}_{$post->post_type}", $post->ID, $post );
     4063        $new_status_object = get_post_status_object( $new_status );
     4064        $old_status_valid  = get_post_status_object( $old_status ) || 'new' === $old_status;
     4065        $post_type_object  = get_post_type_object( $post->post_type );
     4066
     4067        if ( $new_status_object && $old_status_valid ) {
     4068                /**
     4069                 * Fires when a post is transitioned from one status to another.
     4070                 *
     4071                 * The dynamic portions of the hook name, `$new_status` and `$old status`,
     4072                 * refer to the old and new post statuses, respectively.
     4073                 *
     4074                 * @since 2.3.0
     4075                 *
     4076                 * @param WP_Post $post Post object.
     4077                 */
     4078                do_action( "{$old_status}_to_{$new_status}", $post );
     4079        }
     4080
     4081        if ( $new_status_object && $post_type_object ) {
     4082                /**
     4083                 * Fires when a post is transitioned from one status to another.
     4084                 *
     4085                 * The dynamic portions of the hook name, `$new_status` and `$post->post_type`,
     4086                 * refer to the new post status and post type, respectively.
     4087                 *
     4088                 * Please note: When this action is hooked using a particular post status (like
     4089                 * 'publish', as `publish_{$post->post_type}`), it will fire both when a post is
     4090                 * first transitioned to that status from something else, as well as upon
     4091                 * subsequent post updates (old and new status are both the same).
     4092                 *
     4093                 * Therefore, if you are looking to only fire a callback when a post is first
     4094                 * transitioned to a status, use the {@see 'transition_post_status'} hook instead.
     4095                 *
     4096                 * @since 2.3.0
     4097                 *
     4098                 * @param int     $post_id Post ID.
     4099                 * @param WP_Post $post    Post object.
     4100                 */
     4101                do_action( "{$new_status}_{$post->post_type}", $post->ID, $post );
     4102        }
    40954103}
    40964104
  • branches/4.7/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php

    r60839 r64183  
    549549                }
    550550
    551                 if ( ! empty( $request['sticky'] ) && ! current_user_can( $post_type->cap->edit_others_posts ) && ! current_user_can( $post_type->cap->publish_posts ) ) {
     551                if ( ! empty( $request['sticky'] ) && ( ! current_user_can( $post_type->cap->edit_others_posts ) || ! current_user_can( $post_type->cap->publish_posts ) ) ) {
    552552                        return new WP_Error( 'rest_cannot_assign_sticky', __( 'Sorry, you are not allowed to make posts sticky.' ), array( 'status' => rest_authorization_required_code() ) );
    553553                }
    … …  
    693693                }
    694694
    695                 if ( ! empty( $request['sticky'] ) && ! current_user_can( $post_type->cap->edit_others_posts ) && ! current_user_can( $post_type->cap->publish_posts ) ) {
     695                if ( isset( $request['sticky'] ) && is_sticky( $post->ID ) !== (bool) $request['sticky'] && ( ! current_user_can( $post_type->cap->edit_others_posts ) || ! current_user_can( $post_type->cap->publish_posts ) ) ) {
    696696                        return new WP_Error( 'rest_cannot_assign_sticky', __( 'Sorry, you are not allowed to make posts sticky.' ), array( 'status' => rest_authorization_required_code() ) );
    697697                }
Note: See TracChangeset for help on using the changeset viewer.