Skip to content

Commit 3939f4a

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

6 files changed

Lines changed: 109 additions & 99 deletions

File tree

‎src/js/_enqueues/admin/common.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ $('.contextual-help-tabs').on( 'click', 'a', function(e) {
674674
$('.contextual-help-tabs .active').removeClass('active');
675675
link.parent('li').addClass('active');
676676

677-
panel = $( link.attr('href') );
677+
panel = $( document ).find( link.attr('href') );
678678

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

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

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

10021002
// Strip all /path/../ out of the path.
10031003
while ( strpos( $path, '../' ) > 1 ) {
1004-
$path = preg_replace( '![^/]+/\.\./!', '', $path );
1004+
$path = preg_replace( '![^/]+/\.\./!', '', $path, -1, $segment_replacement_count );
1005+
if ( 0 === $segment_replacement_count ) {
1006+
break;
1007+
}
10051008
}
10061009

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

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ public function __construct() {
7777
'#https?://(www\.)?soundcloud\.com/.*#i' => array( 'https://soundcloud.com/oembed', true ),
7878
'#https?://(.+?\.)?slideshare\.net/.*#i' => array( 'https://www.slideshare.net/api/oembed/2', true ),
7979
'#https?://(open|play)\.spotify\.com/.*#i' => array( 'https://embed.spotify.com/oembed/', true ),
80-
'#https?://(.+\.)?imgur\.com/.*#i' => array( 'https://api.imgur.com/oembed', true ),
8180
'#https?://(www\.)?issuu\.com/.+/docs/.+#i' => array( 'https://issuu.com/oembed_wp', true ),
8281
'#https?://(www\.)?mixcloud\.com/.*#i' => array( 'https://app.mixcloud.com/oembed/', true ),
8382
'#https?://(www\.|embed\.)?ted\.com/talks/.*#i' => array( 'https://www.ted.com/services/v1/oembed.{format}', true ),
@@ -150,7 +149,6 @@ public function __construct() {
150149
* | Dailymotion | dai.ly | 3.6.0 |
151150
* | Flickr | flic.kr | 3.6.0 |
152151
* | Spotify | spotify.com | 3.6.0 |
153-
* | Imgur | imgur.com | 3.9.0 |
154152
* | Animoto | animoto.com | 4.0.0 |
155153
* | Animoto | video214.com | 4.0.0 |
156154
* | Issuu | issuu.com | 4.0.0 |
@@ -210,6 +208,7 @@ public function __construct() {
210208
* | Facebook | facebook.com | 4.7.0 | 5.5.2 |
211209
* | Meetup.com | meetup.com | 3.9.0 | 6.0.1 |
212210
* | Meetup.com | meetu.ps | 3.9.0 | 6.0.1 |
211+
* | Imgur | imgur.com | 3.9.0 | 7.1.3 |
213212
*
214213
* @see wp_oembed_add_provider()
215214
*

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

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3343,43 +3343,6 @@ public function get_posts() {
33433343
$this->posts = apply_filters_ref_array( 'posts_results', array( $this->posts, &$this ) );
33443344
}
33453345

3346-
if ( ! empty( $this->posts ) && $this->is_comment_feed && $this->is_singular ) {
3347-
/** This filter is documented in wp-includes/query.php */
3348-
$cjoin = apply_filters_ref_array( 'comment_feed_join', array( '', &$this ) );
3349-
3350-
/** This filter is documented in wp-includes/query.php */
3351-
$cwhere = apply_filters_ref_array( 'comment_feed_where', array( "WHERE comment_post_ID = '{$this->posts[0]->ID}' AND comment_approved = '1'", &$this ) );
3352-
3353-
/** This filter is documented in wp-includes/query.php */
3354-
$cgroupby = apply_filters_ref_array( 'comment_feed_groupby', array( '', &$this ) );
3355-
$cgroupby = ( ! empty( $cgroupby ) ) ? 'GROUP BY ' . $cgroupby : '';
3356-
3357-
/** This filter is documented in wp-includes/query.php */
3358-
$corderby = apply_filters_ref_array( 'comment_feed_orderby', array( 'comment_date_gmt DESC', &$this ) );
3359-
$corderby = ( ! empty( $corderby ) ) ? 'ORDER BY ' . $corderby : '';
3360-
3361-
/** This filter is documented in wp-includes/query.php */
3362-
$climits = apply_filters_ref_array( 'comment_feed_limits', array( 'LIMIT ' . get_option( 'posts_per_rss' ), &$this ) );
3363-
3364-
$comments_request = "SELECT {$wpdb->comments}.comment_ID FROM {$wpdb->comments} $cjoin $cwhere $cgroupby $corderby $climits";
3365-
3366-
$comment_key = md5( $comments_request );
3367-
$comment_last_changed = wp_cache_get_last_changed( 'comment' );
3368-
3369-
$comment_cache_key = "comment_feed:$comment_key:$comment_last_changed";
3370-
$comment_ids = wp_cache_get( $comment_cache_key, 'comment' );
3371-
if ( false === $comment_ids ) {
3372-
$comment_ids = $wpdb->get_col( $comments_request );
3373-
wp_cache_add( $comment_cache_key, $comment_ids, 'comment' );
3374-
}
3375-
_prime_comment_caches( $comment_ids, false );
3376-
3377-
// Convert to WP_Comment.
3378-
/** @var WP_Comment[] */
3379-
$this->comments = array_map( 'get_comment', $comment_ids );
3380-
$this->comment_count = count( $this->comments );
3381-
}
3382-
33833346
// Check post status to determine if post should be displayed.
33843347
if ( ! empty( $this->posts ) && ( $this->is_single || $this->is_page ) ) {
33853348
$status = get_post_status( $this->posts[0] );
@@ -3438,6 +3401,43 @@ public function get_posts() {
34383401
}
34393402
}
34403403

3404+
if ( ! empty( $this->posts ) && $this->is_comment_feed && $this->is_singular ) {
3405+
/** This filter is documented in wp-includes/query.php */
3406+
$cjoin = apply_filters_ref_array( 'comment_feed_join', array( '', &$this ) );
3407+
3408+
/** This filter is documented in wp-includes/query.php */
3409+
$cwhere = apply_filters_ref_array( 'comment_feed_where', array( "WHERE comment_post_ID = '{$this->posts[0]->ID}' AND comment_approved = '1'", &$this ) );
3410+
3411+
/** This filter is documented in wp-includes/query.php */
3412+
$cgroupby = apply_filters_ref_array( 'comment_feed_groupby', array( '', &$this ) );
3413+
$cgroupby = ( ! empty( $cgroupby ) ) ? 'GROUP BY ' . $cgroupby : '';
3414+
3415+
/** This filter is documented in wp-includes/query.php */
3416+
$corderby = apply_filters_ref_array( 'comment_feed_orderby', array( 'comment_date_gmt DESC', &$this ) );
3417+
$corderby = ( ! empty( $corderby ) ) ? 'ORDER BY ' . $corderby : '';
3418+
3419+
/** This filter is documented in wp-includes/query.php */
3420+
$climits = apply_filters_ref_array( 'comment_feed_limits', array( 'LIMIT ' . get_option( 'posts_per_rss' ), &$this ) );
3421+
3422+
$comments_request = "SELECT {$wpdb->comments}.comment_ID FROM {$wpdb->comments} $cjoin $cwhere $cgroupby $corderby $climits";
3423+
3424+
$comment_key = md5( $comments_request );
3425+
$comment_last_changed = wp_cache_get_last_changed( 'comment' );
3426+
3427+
$comment_cache_key = "comment_feed:$comment_key:$comment_last_changed";
3428+
$comment_ids = wp_cache_get( $comment_cache_key, 'comment' );
3429+
if ( false === $comment_ids ) {
3430+
$comment_ids = $wpdb->get_col( $comments_request );
3431+
wp_cache_add( $comment_cache_key, $comment_ids, 'comment' );
3432+
}
3433+
_prime_comment_caches( $comment_ids, false );
3434+
3435+
// Convert to WP_Comment.
3436+
/** @var WP_Comment[] */
3437+
$this->comments = array_map( 'get_comment', $comment_ids );
3438+
$this->comment_count = count( $this->comments );
3439+
}
3440+
34413441
// Put sticky posts at the top of the posts array.
34423442
$sticky_posts = get_option( 'sticky_posts' );
34433443
if ( $this->is_home && $page <= 1 && is_array( $sticky_posts ) && ! empty( $sticky_posts ) && ! $q['ignore_sticky_posts'] ) {

‎src/wp-includes/post.php‎

Lines changed: 64 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -5344,63 +5344,71 @@ function wp_transition_post_status( $new_status, $old_status, $post ) {
53445344
*/
53455345
do_action( 'transition_post_status', $new_status, $old_status, $post );
53465346

5347-
/**
5348-
* Fires when a post is transitioned from one status to another.
5349-
*
5350-
* The dynamic portions of the hook name, `$new_status` and `$old_status`,
5351-
* refer to the old and new post statuses, respectively.
5352-
*
5353-
* Possible hook names include:
5354-
*
5355-
* - `draft_to_publish`
5356-
* - `publish_to_trash`
5357-
* - `pending_to_draft`
5358-
*
5359-
* @since 2.3.0
5360-
*
5361-
* @param WP_Post $post Post object.
5362-
*/
5363-
do_action( "{$old_status}_to_{$new_status}", $post );
5347+
$new_status_object = get_post_status_object( $new_status );
5348+
$old_status_valid = get_post_status_object( $old_status ) || 'new' === $old_status;
5349+
$post_type_object = get_post_type_object( $post->post_type );
53645350

5365-
/**
5366-
* Fires when a post is transitioned from one status to another.
5367-
*
5368-
* The dynamic portions of the hook name, `$new_status` and `$post->post_type`,
5369-
* refer to the new post status and post type, respectively.
5370-
*
5371-
* Possible hook names include:
5372-
*
5373-
* - `draft_post`
5374-
* - `future_post`
5375-
* - `pending_post`
5376-
* - `private_post`
5377-
* - `publish_post`
5378-
* - `trash_post`
5379-
* - `draft_page`
5380-
* - `future_page`
5381-
* - `pending_page`
5382-
* - `private_page`
5383-
* - `publish_page`
5384-
* - `trash_page`
5385-
* - `publish_attachment`
5386-
* - `trash_attachment`
5387-
*
5388-
* Please note: When this action is hooked using a particular post status (like
5389-
* 'publish', as `publish_{$post->post_type}`), it will fire both when a post is
5390-
* first transitioned to that status from something else, as well as upon
5391-
* subsequent post updates (old and new status are both the same).
5392-
*
5393-
* Therefore, if you are looking to only fire a callback when a post is first
5394-
* transitioned to a status, use the {@see 'transition_post_status'} hook instead.
5395-
*
5396-
* @since 2.3.0
5397-
* @since 5.9.0 Added `$old_status` parameter.
5398-
*
5399-
* @param int $post_id Post ID.
5400-
* @param WP_Post $post Post object.
5401-
* @param string $old_status Old post status.
5402-
*/
5403-
do_action( "{$new_status}_{$post->post_type}", $post->ID, $post, $old_status );
5351+
if ( $new_status_object && $old_status_valid ) {
5352+
/**
5353+
* Fires when a post is transitioned from one status to another.
5354+
*
5355+
* The dynamic portions of the hook name, `$new_status` and `$old_status`,
5356+
* refer to the old and new post statuses, respectively.
5357+
*
5358+
* Possible hook names include:
5359+
*
5360+
* - `draft_to_publish`
5361+
* - `publish_to_trash`
5362+
* - `pending_to_draft`
5363+
*
5364+
* @since 2.3.0
5365+
*
5366+
* @param WP_Post $post Post object.
5367+
*/
5368+
do_action( "{$old_status}_to_{$new_status}", $post );
5369+
}
5370+
5371+
if ( $new_status_object && $post_type_object ) {
5372+
/**
5373+
* Fires when a post is transitioned from one status to another.
5374+
*
5375+
* The dynamic portions of the hook name, `$new_status` and `$post->post_type`,
5376+
* refer to the new post status and post type, respectively.
5377+
*
5378+
* Possible hook names include:
5379+
*
5380+
* - `draft_post`
5381+
* - `future_post`
5382+
* - `pending_post`
5383+
* - `private_post`
5384+
* - `publish_post`
5385+
* - `trash_post`
5386+
* - `draft_page`
5387+
* - `future_page`
5388+
* - `pending_page`
5389+
* - `private_page`
5390+
* - `publish_page`
5391+
* - `trash_page`
5392+
* - `publish_attachment`
5393+
* - `trash_attachment`
5394+
*
5395+
* Please note: When this action is hooked using a particular post status (like
5396+
* 'publish', as `publish_{$post->post_type}`), it will fire both when a post is
5397+
* first transitioned to that status from something else, as well as upon
5398+
* subsequent post updates (old and new status are both the same).
5399+
*
5400+
* Therefore, if you are looking to only fire a callback when a post is first
5401+
* transitioned to a status, use the {@see 'transition_post_status'} hook instead.
5402+
*
5403+
* @since 2.3.0
5404+
* @since 5.9.0 Added `$old_status` parameter.
5405+
*
5406+
* @param int $post_id Post ID.
5407+
* @param WP_Post $post Post object.
5408+
* @param string $old_status Old post status.
5409+
*/
5410+
do_action( "{$new_status}_{$post->post_type}", $post->ID, $post, $old_status );
5411+
}
54045412
}
54055413

54065414
/**

‎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
@@ -609,7 +609,7 @@ public function create_item_permissions_check( $request ) {
609609
);
610610
}
611611

612-
if ( ! empty( $request['sticky'] ) && ! current_user_can( $post_type->cap->edit_others_posts ) && ! current_user_can( $post_type->cap->publish_posts ) ) {
612+
if ( ! empty( $request['sticky'] ) && ( ! current_user_can( $post_type->cap->edit_others_posts ) || ! current_user_can( $post_type->cap->publish_posts ) ) ) {
613613
return new WP_Error(
614614
'rest_cannot_assign_sticky',
615615
__( 'Sorry, you are not allowed to make posts sticky.' ),
@@ -820,7 +820,7 @@ public function update_item_permissions_check( $request ) {
820820
);
821821
}
822822

823-
if ( ! empty( $request['sticky'] ) && ! current_user_can( $post_type->cap->edit_others_posts ) && ! current_user_can( $post_type->cap->publish_posts ) ) {
823+
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 ) ) ) {
824824
return new WP_Error(
825825
'rest_cannot_assign_sticky',
826826
__( 'Sorry, you are not allowed to make posts sticky.' ),

0 commit comments

Comments
 (0)