Skip to content

Commit a5365a1

Browse files
committed
Security: Backport the WordPress 7.1.3 security fixes to the 5.0 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 5.0 branch. Props xknown, jeremyfelt, jorbin, peterwilsoncc, ehtis, westonruter, lancewillett, jonsurrell, marcs0h, rfaile313, johnbillion, vortfu. git-svn-id: https://develop.svn.wordpress.org/branches/5.0@64180 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 0a3b669 commit a5365a1

6 files changed

Lines changed: 72 additions & 62 deletions

File tree

‎src/wp-admin/js/common.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ $('.contextual-help-tabs').delegate('a', 'click', function(e) {
168168
$('.contextual-help-tabs .active').removeClass('active');
169169
link.parent('li').addClass('active');
170170

171-
panel = $( link.attr('href') );
171+
panel = $( document ).find( link.attr('href') );
172172

173173
// Panels
174174
$('.help-tab-content').not( panel ).removeClass('active').hide();

‎src/wp-includes/class-http.php‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,10 @@ public static function make_absolute_url( $maybe_relative_path, $url ) {
931931

932932
// Strip all /path/../ out of the path.
933933
while ( strpos( $path, '../' ) > 1 ) {
934-
$path = preg_replace( '![^/]+/\.\./!', '', $path );
934+
$path = preg_replace( '![^/]+/\.\./!', '', $path, -1, $segment_replacement_count );
935+
if ( 0 === $segment_replacement_count ) {
936+
break;
937+
}
935938
}
936939

937940
// Strip any final leading ../ from the path.

‎src/wp-includes/class-oembed.php‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ public function __construct() {
7878
'#https?://(.+?\.)?slideshare\.net/.*#i' => array( 'https://www.slideshare.net/api/oembed/2', true ),
7979
'#https?://(www\.)?instagr(\.am|am\.com)/p/.*#i' => array( 'https://api.instagram.com/oembed', true ),
8080
'#https?://(open|play)\.spotify\.com/.*#i' => array( 'https://embed.spotify.com/oembed/', true ),
81-
'#https?://(.+\.)?imgur\.com/.*#i' => array( 'https://api.imgur.com/oembed', true ),
8281
'#https?://(www\.)?meetu(\.ps|p\.com)/.*#i' => array( 'https://api.meetup.com/oembed', true ),
8382
'#https?://(www\.)?issuu\.com/.+/docs/.+#i' => array( 'https://issuu.com/oembed_wp', true ),
8483
'#https?://(www\.)?collegehumor\.com/video/.*#i' => array( 'https://www.collegehumor.com/oembed.{format}', true ),
@@ -164,7 +163,6 @@ public function __construct() {
164163
* | Dailymotion | dai.ly | Yes | 3.6.0 |
165164
* | Flickr | flic.kr | Yes | 3.6.0 |
166165
* | Spotify | spotify.com | Yes | 3.6.0 |
167-
* | Imgur | imgur.com | Yes | 3.9.0 |
168166
* | Meetup.com | meetup.com | Yes | 3.9.0 |
169167
* | Meetup.com | meetu.ps | Yes | 3.9.0 |
170168
* | Animoto | animoto.com | Yes | 4.0.0 |
@@ -211,6 +209,7 @@ public function __construct() {
211209
* | Rdio | rdio.com | Yes | 3.6.0 | 4.4.1 |
212210
* | Rdio | rd.io | Yes | 3.6.0 | 4.4.1 |
213211
* | Vine | vine.co | Yes | 4.1.0 | 4.9.0 |
212+
* | Imgur | imgur.com | Yes | 3.9.0 | 7.1.3 |
214213
*
215214
* @see wp_oembed_add_provider()
216215
*

‎src/wp-includes/class-wp-query.php‎

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2871,31 +2871,6 @@ public function get_posts() {
28712871
$this->posts = apply_filters_ref_array( 'posts_results', array( $this->posts, &$this ) );
28722872
}
28732873

2874-
if ( !empty($this->posts) && $this->is_comment_feed && $this->is_singular ) {
2875-
/** This filter is documented in wp-includes/query.php */
2876-
$cjoin = apply_filters_ref_array( 'comment_feed_join', array( '', &$this ) );
2877-
2878-
/** This filter is documented in wp-includes/query.php */
2879-
$cwhere = apply_filters_ref_array( 'comment_feed_where', array( "WHERE comment_post_ID = '{$this->posts[0]->ID}' AND comment_approved = '1'", &$this ) );
2880-
2881-
/** This filter is documented in wp-includes/query.php */
2882-
$cgroupby = apply_filters_ref_array( 'comment_feed_groupby', array( '', &$this ) );
2883-
$cgroupby = ( ! empty( $cgroupby ) ) ? 'GROUP BY ' . $cgroupby : '';
2884-
2885-
/** This filter is documented in wp-includes/query.php */
2886-
$corderby = apply_filters_ref_array( 'comment_feed_orderby', array( 'comment_date_gmt DESC', &$this ) );
2887-
$corderby = ( ! empty( $corderby ) ) ? 'ORDER BY ' . $corderby : '';
2888-
2889-
/** This filter is documented in wp-includes/query.php */
2890-
$climits = apply_filters_ref_array( 'comment_feed_limits', array( 'LIMIT ' . get_option('posts_per_rss'), &$this ) );
2891-
2892-
$comments_request = "SELECT {$wpdb->comments}.* FROM {$wpdb->comments} $cjoin $cwhere $cgroupby $corderby $climits";
2893-
$comments = $wpdb->get_results($comments_request);
2894-
// Convert to WP_Comment
2895-
$this->comments = array_map( 'get_comment', $comments );
2896-
$this->comment_count = count($this->comments);
2897-
}
2898-
28992874
// Check post status to determine if post should be displayed.
29002875
if ( !empty($this->posts) && ($this->is_single || $this->is_page) ) {
29012876
$status = get_post_status($this->posts[0]);
@@ -2944,6 +2919,31 @@ public function get_posts() {
29442919
}
29452920
}
29462921

2922+
if ( !empty($this->posts) && $this->is_comment_feed && $this->is_singular ) {
2923+
/** This filter is documented in wp-includes/query.php */
2924+
$cjoin = apply_filters_ref_array( 'comment_feed_join', array( '', &$this ) );
2925+
2926+
/** This filter is documented in wp-includes/query.php */
2927+
$cwhere = apply_filters_ref_array( 'comment_feed_where', array( "WHERE comment_post_ID = '{$this->posts[0]->ID}' AND comment_approved = '1'", &$this ) );
2928+
2929+
/** This filter is documented in wp-includes/query.php */
2930+
$cgroupby = apply_filters_ref_array( 'comment_feed_groupby', array( '', &$this ) );
2931+
$cgroupby = ( ! empty( $cgroupby ) ) ? 'GROUP BY ' . $cgroupby : '';
2932+
2933+
/** This filter is documented in wp-includes/query.php */
2934+
$corderby = apply_filters_ref_array( 'comment_feed_orderby', array( 'comment_date_gmt DESC', &$this ) );
2935+
$corderby = ( ! empty( $corderby ) ) ? 'ORDER BY ' . $corderby : '';
2936+
2937+
/** This filter is documented in wp-includes/query.php */
2938+
$climits = apply_filters_ref_array( 'comment_feed_limits', array( 'LIMIT ' . get_option('posts_per_rss'), &$this ) );
2939+
2940+
$comments_request = "SELECT {$wpdb->comments}.* FROM {$wpdb->comments} $cjoin $cwhere $cgroupby $corderby $climits";
2941+
$comments = $wpdb->get_results($comments_request);
2942+
// Convert to WP_Comment
2943+
$this->comments = array_map( 'get_comment', $comments );
2944+
$this->comment_count = count($this->comments);
2945+
}
2946+
29472947
// Put sticky posts at the top of the posts array
29482948
$sticky_posts = get_option('sticky_posts');
29492949
if ( $this->is_home && $page <= 1 && is_array($sticky_posts) && !empty($sticky_posts) && !$q['ignore_sticky_posts'] ) {

‎src/wp-includes/post.php‎

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4302,38 +4302,46 @@ function wp_transition_post_status( $new_status, $old_status, $post ) {
43024302
*/
43034303
do_action( 'transition_post_status', $new_status, $old_status, $post );
43044304

4305-
/**
4306-
* Fires when a post is transitioned from one status to another.
4307-
*
4308-
* The dynamic portions of the hook name, `$new_status` and `$old status`,
4309-
* refer to the old and new post statuses, respectively.
4310-
*
4311-
* @since 2.3.0
4312-
*
4313-
* @param WP_Post $post Post object.
4314-
*/
4315-
do_action( "{$old_status}_to_{$new_status}", $post );
4305+
$new_status_object = get_post_status_object( $new_status );
4306+
$old_status_valid = get_post_status_object( $old_status ) || 'new' === $old_status;
4307+
$post_type_object = get_post_type_object( $post->post_type );
43164308

4317-
/**
4318-
* Fires when a post is transitioned from one status to another.
4319-
*
4320-
* The dynamic portions of the hook name, `$new_status` and `$post->post_type`,
4321-
* refer to the new post status and post type, respectively.
4322-
*
4323-
* Please note: When this action is hooked using a particular post status (like
4324-
* 'publish', as `publish_{$post->post_type}`), it will fire both when a post is
4325-
* first transitioned to that status from something else, as well as upon
4326-
* subsequent post updates (old and new status are both the same).
4327-
*
4328-
* Therefore, if you are looking to only fire a callback when a post is first
4329-
* transitioned to a status, use the {@see 'transition_post_status'} hook instead.
4330-
*
4331-
* @since 2.3.0
4332-
*
4333-
* @param int $post_id Post ID.
4334-
* @param WP_Post $post Post object.
4335-
*/
4336-
do_action( "{$new_status}_{$post->post_type}", $post->ID, $post );
4309+
if ( $new_status_object && $old_status_valid ) {
4310+
/**
4311+
* Fires when a post is transitioned from one status to another.
4312+
*
4313+
* The dynamic portions of the hook name, `$new_status` and `$old status`,
4314+
* refer to the old and new post statuses, respectively.
4315+
*
4316+
* @since 2.3.0
4317+
*
4318+
* @param WP_Post $post Post object.
4319+
*/
4320+
do_action( "{$old_status}_to_{$new_status}", $post );
4321+
}
4322+
4323+
if ( $new_status_object && $post_type_object ) {
4324+
/**
4325+
* Fires when a post is transitioned from one status to another.
4326+
*
4327+
* The dynamic portions of the hook name, `$new_status` and `$post->post_type`,
4328+
* refer to the new post status and post type, respectively.
4329+
*
4330+
* Please note: When this action is hooked using a particular post status (like
4331+
* 'publish', as `publish_{$post->post_type}`), it will fire both when a post is
4332+
* first transitioned to that status from something else, as well as upon
4333+
* subsequent post updates (old and new status are both the same).
4334+
*
4335+
* Therefore, if you are looking to only fire a callback when a post is first
4336+
* transitioned to a status, use the {@see 'transition_post_status'} hook instead.
4337+
*
4338+
* @since 2.3.0
4339+
*
4340+
* @param int $post_id Post ID.
4341+
* @param WP_Post $post Post object.
4342+
*/
4343+
do_action( "{$new_status}_{$post->post_type}", $post->ID, $post );
4344+
}
43374345
}
43384346

43394347
//

‎src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ public function create_item_permissions_check( $request ) {
543543
return new WP_Error( 'rest_cannot_edit_others', __( 'Sorry, you are not allowed to create posts as this user.' ), array( 'status' => rest_authorization_required_code() ) );
544544
}
545545

546-
if ( ! empty( $request['sticky'] ) && ! current_user_can( $post_type->cap->edit_others_posts ) && ! current_user_can( $post_type->cap->publish_posts ) ) {
546+
if ( ! empty( $request['sticky'] ) && ( ! current_user_can( $post_type->cap->edit_others_posts ) || ! current_user_can( $post_type->cap->publish_posts ) ) ) {
547547
return new WP_Error( 'rest_cannot_assign_sticky', __( 'Sorry, you are not allowed to make posts sticky.' ), array( 'status' => rest_authorization_required_code() ) );
548548
}
549549

@@ -698,7 +698,7 @@ public function update_item_permissions_check( $request ) {
698698
return new WP_Error( 'rest_cannot_edit_others', __( 'Sorry, you are not allowed to update posts as this user.' ), array( 'status' => rest_authorization_required_code() ) );
699699
}
700700

701-
if ( ! empty( $request['sticky'] ) && ! current_user_can( $post_type->cap->edit_others_posts ) && ! current_user_can( $post_type->cap->publish_posts ) ) {
701+
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 ) ) ) {
702702
return new WP_Error( 'rest_cannot_assign_sticky', __( 'Sorry, you are not allowed to make posts sticky.' ), array( 'status' => rest_authorization_required_code() ) );
703703
}
704704

0 commit comments

Comments
 (0)