Skip to content

Commit c3e22fd

Browse files
committed
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. git-svn-id: https://develop.svn.wordpress.org/branches/4.7@64183 602fd350-edb4-49c9-b593-d223f7449a82
1 parent a6737eb commit c3e22fd

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
@@ -944,7 +944,10 @@ public static function make_absolute_url( $maybe_relative_path, $url ) {
944944

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

950953
// 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
@@ -83,7 +83,6 @@ public function __construct() {
8383
'#https?://(.+?\.)?slideshare\.net/.*#i' => array( 'https://www.slideshare.net/api/oembed/2', true ),
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 ),
8988
'#https?://(www\.)?collegehumor\.com/video/.*#i' => array( 'http://www.collegehumor.com/oembed.{format}', true ),
@@ -155,7 +154,6 @@ public function __construct() {
155154
* | Dailymotion | dai.ly | Yes | 3.6.0 |
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 |
161159
* | Animoto | animoto.com | Yes | 4.0.0 |
@@ -192,6 +190,7 @@ public function __construct() {
192190
* | Blip | blip.tv | No | 2.9.0 | 4.4.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()
197196
*

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

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2886,31 +2886,6 @@ public function get_posts() {
28862886
$this->posts = apply_filters_ref_array( 'posts_results', array( $this->posts, &$this ) );
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) ) {
29162891
$status = get_post_status($this->posts[0]);
@@ -2959,6 +2934,31 @@ public function get_posts() {
29592934
}
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');
29642964
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
@@ -4060,38 +4060,46 @@ function wp_transition_post_status( $new_status, $old_status, $post ) {
40604060
*/
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 );
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 );
40744066

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 );
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

40974105
//

‎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
@@ -548,7 +548,7 @@ public function create_item_permissions_check( $request ) {
548548
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() ) );
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
}
554554

@@ -692,7 +692,7 @@ public function update_item_permissions_check( $request ) {
692692
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() ) );
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
}
698698

0 commit comments

Comments
 (0)