Skip to content

Commit c0b5d80

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

6 files changed

Lines changed: 72 additions & 62 deletions

File tree

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

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

341-
panel = $( link.attr('href') );
341+
panel = $( document ).find( link.attr('href') );
342342

343343
// Panels
344344
$('.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
@@ -974,7 +974,10 @@ public static function make_absolute_url( $maybe_relative_path, $url ) {
974974

975975
// Strip all /path/../ out of the path.
976976
while ( strpos( $path, '../' ) > 1 ) {
977-
$path = preg_replace( '![^/]+/\.\./!', '', $path );
977+
$path = preg_replace( '![^/]+/\.\./!', '', $path, -1, $segment_replacement_count );
978+
if ( 0 === $segment_replacement_count ) {
979+
break;
980+
}
978981
}
979982

980983
// 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
@@ -75,7 +75,6 @@ public function __construct() {
7575
'#https?://(.+?\.)?slideshare\.net/.*#i' => array( 'https://www.slideshare.net/api/oembed/2', true ),
7676
'#https?://(www\.)?instagr(\.am|am\.com)/(p|tv)/.*#i' => array( 'https://api.instagram.com/oembed', true ),
7777
'#https?://(open|play)\.spotify\.com/.*#i' => array( 'https://embed.spotify.com/oembed/', true ),
78-
'#https?://(.+\.)?imgur\.com/.*#i' => array( 'https://api.imgur.com/oembed', true ),
7978
'#https?://(www\.)?meetu(\.ps|p\.com)/.*#i' => array( 'https://api.meetup.com/oembed', true ),
8079
'#https?://(www\.)?issuu\.com/.+/docs/.+#i' => array( 'https://issuu.com/oembed_wp', true ),
8180
'#https?://(www\.)?mixcloud\.com/.*#i' => array( 'https://www.mixcloud.com/oembed', true ),
@@ -158,7 +157,6 @@ public function __construct() {
158157
* | Dailymotion | dai.ly | 3.6.0 |
159158
* | Flickr | flic.kr | 3.6.0 |
160159
* | Spotify | spotify.com | 3.6.0 |
161-
* | Imgur | imgur.com | 3.9.0 |
162160
* | Meetup.com | meetup.com | 3.9.0 |
163161
* | Meetup.com | meetu.ps | 3.9.0 |
164162
* | Animoto | animoto.com | 4.0.0 |
@@ -210,6 +208,7 @@ public function __construct() {
210208
* | Photobucket | photobucket.com | 2.9.0 | 5.1.0 |
211209
* | Funny or Die | funnyordie.com | 3.0.0 | 5.1.0 |
212210
* | CollegeHumor | collegehumor.com | 4.0.0 | 5.3.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: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3045,31 +3045,6 @@ public function get_posts() {
30453045
$this->posts = apply_filters_ref_array( 'posts_results', array( $this->posts, &$this ) );
30463046
}
30473047

3048-
if ( ! empty( $this->posts ) && $this->is_comment_feed && $this->is_singular ) {
3049-
/** This filter is documented in wp-includes/query.php */
3050-
$cjoin = apply_filters_ref_array( 'comment_feed_join', array( '', &$this ) );
3051-
3052-
/** This filter is documented in wp-includes/query.php */
3053-
$cwhere = apply_filters_ref_array( 'comment_feed_where', array( "WHERE comment_post_ID = '{$this->posts[0]->ID}' AND comment_approved = '1'", &$this ) );
3054-
3055-
/** This filter is documented in wp-includes/query.php */
3056-
$cgroupby = apply_filters_ref_array( 'comment_feed_groupby', array( '', &$this ) );
3057-
$cgroupby = ( ! empty( $cgroupby ) ) ? 'GROUP BY ' . $cgroupby : '';
3058-
3059-
/** This filter is documented in wp-includes/query.php */
3060-
$corderby = apply_filters_ref_array( 'comment_feed_orderby', array( 'comment_date_gmt DESC', &$this ) );
3061-
$corderby = ( ! empty( $corderby ) ) ? 'ORDER BY ' . $corderby : '';
3062-
3063-
/** This filter is documented in wp-includes/query.php */
3064-
$climits = apply_filters_ref_array( 'comment_feed_limits', array( 'LIMIT ' . get_option( 'posts_per_rss' ), &$this ) );
3065-
3066-
$comments_request = "SELECT {$wpdb->comments}.* FROM {$wpdb->comments} $cjoin $cwhere $cgroupby $corderby $climits";
3067-
$comments = $wpdb->get_results( $comments_request );
3068-
// Convert to WP_Comment
3069-
$this->comments = array_map( 'get_comment', $comments );
3070-
$this->comment_count = count( $this->comments );
3071-
}
3072-
30733048
// Check post status to determine if post should be displayed.
30743049
if ( ! empty( $this->posts ) && ( $this->is_single || $this->is_page ) ) {
30753050
$status = get_post_status( $this->posts[0] );
@@ -3120,6 +3095,31 @@ public function get_posts() {
31203095
}
31213096
}
31223097

3098+
if ( ! empty( $this->posts ) && $this->is_comment_feed && $this->is_singular ) {
3099+
/** This filter is documented in wp-includes/query.php */
3100+
$cjoin = apply_filters_ref_array( 'comment_feed_join', array( '', &$this ) );
3101+
3102+
/** This filter is documented in wp-includes/query.php */
3103+
$cwhere = apply_filters_ref_array( 'comment_feed_where', array( "WHERE comment_post_ID = '{$this->posts[0]->ID}' AND comment_approved = '1'", &$this ) );
3104+
3105+
/** This filter is documented in wp-includes/query.php */
3106+
$cgroupby = apply_filters_ref_array( 'comment_feed_groupby', array( '', &$this ) );
3107+
$cgroupby = ( ! empty( $cgroupby ) ) ? 'GROUP BY ' . $cgroupby : '';
3108+
3109+
/** This filter is documented in wp-includes/query.php */
3110+
$corderby = apply_filters_ref_array( 'comment_feed_orderby', array( 'comment_date_gmt DESC', &$this ) );
3111+
$corderby = ( ! empty( $corderby ) ) ? 'ORDER BY ' . $corderby : '';
3112+
3113+
/** This filter is documented in wp-includes/query.php */
3114+
$climits = apply_filters_ref_array( 'comment_feed_limits', array( 'LIMIT ' . get_option( 'posts_per_rss' ), &$this ) );
3115+
3116+
$comments_request = "SELECT {$wpdb->comments}.* FROM {$wpdb->comments} $cjoin $cwhere $cgroupby $corderby $climits";
3117+
$comments = $wpdb->get_results( $comments_request );
3118+
// Convert to WP_Comment
3119+
$this->comments = array_map( 'get_comment', $comments );
3120+
$this->comment_count = count( $this->comments );
3121+
}
3122+
31233123
// Put sticky posts at the top of the posts array
31243124
$sticky_posts = get_option( 'sticky_posts' );
31253125
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
@@ -4722,38 +4722,46 @@ function wp_transition_post_status( $new_status, $old_status, $post ) {
47224722
*/
47234723
do_action( 'transition_post_status', $new_status, $old_status, $post );
47244724

4725-
/**
4726-
* Fires when a post is transitioned from one status to another.
4727-
*
4728-
* The dynamic portions of the hook name, `$new_status` and `$old status`,
4729-
* refer to the old and new post statuses, respectively.
4730-
*
4731-
* @since 2.3.0
4732-
*
4733-
* @param WP_Post $post Post object.
4734-
*/
4735-
do_action( "{$old_status}_to_{$new_status}", $post );
4725+
$new_status_object = get_post_status_object( $new_status );
4726+
$old_status_valid = get_post_status_object( $old_status ) || 'new' === $old_status;
4727+
$post_type_object = get_post_type_object( $post->post_type );
47364728

4737-
/**
4738-
* Fires when a post is transitioned from one status to another.
4739-
*
4740-
* The dynamic portions of the hook name, `$new_status` and `$post->post_type`,
4741-
* refer to the new post status and post type, respectively.
4742-
*
4743-
* Please note: When this action is hooked using a particular post status (like
4744-
* 'publish', as `publish_{$post->post_type}`), it will fire both when a post is
4745-
* first transitioned to that status from something else, as well as upon
4746-
* subsequent post updates (old and new status are both the same).
4747-
*
4748-
* Therefore, if you are looking to only fire a callback when a post is first
4749-
* transitioned to a status, use the {@see 'transition_post_status'} hook instead.
4750-
*
4751-
* @since 2.3.0
4752-
*
4753-
* @param int $post_id Post ID.
4754-
* @param WP_Post $post Post object.
4755-
*/
4756-
do_action( "{$new_status}_{$post->post_type}", $post->ID, $post );
4729+
if ( $new_status_object && $old_status_valid ) {
4730+
/**
4731+
* Fires when a post is transitioned from one status to another.
4732+
*
4733+
* The dynamic portions of the hook name, `$new_status` and `$old status`,
4734+
* refer to the old and new post statuses, respectively.
4735+
*
4736+
* @since 2.3.0
4737+
*
4738+
* @param WP_Post $post Post object.
4739+
*/
4740+
do_action( "{$old_status}_to_{$new_status}", $post );
4741+
}
4742+
4743+
if ( $new_status_object && $post_type_object ) {
4744+
/**
4745+
* Fires when a post is transitioned from one status to another.
4746+
*
4747+
* The dynamic portions of the hook name, `$new_status` and `$post->post_type`,
4748+
* refer to the new post status and post type, respectively.
4749+
*
4750+
* Please note: When this action is hooked using a particular post status (like
4751+
* 'publish', as `publish_{$post->post_type}`), it will fire both when a post is
4752+
* first transitioned to that status from something else, as well as upon
4753+
* subsequent post updates (old and new status are both the same).
4754+
*
4755+
* Therefore, if you are looking to only fire a callback when a post is first
4756+
* transitioned to a status, use the {@see 'transition_post_status'} hook instead.
4757+
*
4758+
* @since 2.3.0
4759+
*
4760+
* @param int $post_id Post ID.
4761+
* @param WP_Post $post Post object.
4762+
*/
4763+
do_action( "{$new_status}_{$post->post_type}", $post->ID, $post );
4764+
}
47574765
}
47584766

47594767
//

‎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
@@ -550,7 +550,7 @@ public function create_item_permissions_check( $request ) {
550550
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() ) );
551551
}
552552

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

@@ -705,7 +705,7 @@ public function update_item_permissions_check( $request ) {
705705
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() ) );
706706
}
707707

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

0 commit comments

Comments
 (0)