Skip to content

Commit c0a9831

Browse files
committed
Grouped backports to the 4.7 branch.
- Comments: Prevent users who can not see a post from seeing comments on it. - Shortcodes: Restrict media shortcode ajax to certain type. - REST API: Ensure no-cache headers are sent when methods are overridden. - REST API: Limit `search_columns` for users without `list_users`. - Prevent unintended behavior when certain objects are unserialized. Merges [56834], [56835], [56836], [56838], and [56840] to the 4.7 branch. Props xknown, jorbin, joehoyle, timothyblynjacobs, peterwilsoncc, ehtis, tykoted, antpb, rmccue. git-svn-id: https://develop.svn.wordpress.org/branches/4.7@56862 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 356867f commit c0a9831

File tree

13 files changed

+198
-20
lines changed

13 files changed

+198
-20
lines changed

src/wp-admin/includes/ajax-actions.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3043,13 +3043,29 @@ function wp_ajax_parse_media_shortcode() {
30433043

30443044
$shortcode = wp_unslash( $_POST['shortcode'] );
30453045

3046+
// Only process previews for media related shortcodes:
3047+
$found_shortcodes = get_shortcode_tags_in_content( $shortcode );
3048+
$media_shortcodes = array(
3049+
'audio',
3050+
'embed',
3051+
'playlist',
3052+
'video',
3053+
'gallery',
3054+
);
3055+
3056+
$other_shortcodes = array_diff( $found_shortcodes, $media_shortcodes );
3057+
3058+
if ( ! empty( $other_shortcodes ) ) {
3059+
wp_send_json_error();
3060+
}
3061+
30463062
if ( ! empty( $_POST['post_ID'] ) ) {
30473063
$post = get_post( (int) $_POST['post_ID'] );
30483064
}
30493065

30503066
// the embed shortcode requires a post
30513067
if ( ! $post || ! current_user_can( 'edit_post', $post->ID ) ) {
3052-
if ( 'embed' === $shortcode ) {
3068+
if ( in_array( 'embed', $found_shortcodes, true ) ) {
30533069
wp_send_json_error();
30543070
}
30553071
} else {

src/wp-admin/includes/class-wp-comments-list-table.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,19 @@ public function single_row( $item ) {
494494
}
495495
$this->user_can = current_user_can( 'edit_comment', $comment->comment_ID );
496496

497+
$edit_post_cap = $post ? 'edit_post' : 'edit_posts';
498+
if (
499+
current_user_can( $edit_post_cap, $comment->comment_post_ID ) ||
500+
(
501+
empty( $post->post_password ) &&
502+
current_user_can( 'read_post', $comment->comment_post_ID )
503+
)
504+
) {
505+
// The user has access to the post
506+
} else {
507+
return false;
508+
}
509+
497510
echo "<tr id='comment-$comment->comment_ID' class='$the_comment_class'>";
498511
$this->single_row_columns( $comment );
499512
echo "</tr>\n";

src/wp-admin/includes/class-wp-list-table.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,20 @@ protected function comments_bubble( $post_id, $pending_comments ) {
654654
$approved_phrase = sprintf( _n( '%s approved comment', '%s approved comments', $approved_comments ), $approved_comments_number );
655655
$pending_phrase = sprintf( _n( '%s pending comment', '%s pending comments', $pending_comments ), $pending_comments_number );
656656

657-
// No comments at all.
657+
$post_object = get_post( $post_id );
658+
$edit_post_cap = $post_object ? 'edit_post' : 'edit_posts';
659+
if (
660+
current_user_can( $edit_post_cap, $post_id ) ||
661+
(
662+
empty( $post_object->post_password ) &&
663+
current_user_can( 'read_post', $post_id )
664+
)
665+
) {
666+
// The user has access to the post and thus can see comments
667+
} else {
668+
return false;
669+
}
670+
658671
if ( ! $approved_comments && ! $pending_comments ) {
659672
printf( '<span aria-hidden="true">—</span><span class="screen-reader-text">%s</span>',
660673
__( 'No comments' )

src/wp-admin/includes/dashboard.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -919,8 +919,18 @@ function wp_dashboard_recent_comments( $total_items = 5 ) {
919919
echo '<h3>' . __( 'Recent Comments' ) . '</h3>';
920920

921921
echo '<ul id="the-comment-list" data-wp-lists="list:comment">';
922-
foreach ( $comments as $comment )
923-
_wp_dashboard_recent_comments_row( $comment );
922+
foreach ( $comments as $comment ) {
923+
$comment_post = get_post( $comment->comment_post_ID );
924+
if (
925+
current_user_can( 'edit_post', $comment->comment_post_ID ) ||
926+
(
927+
empty( $comment_post->post_password ) &&
928+
current_user_can( 'read_post', $comment->comment_post_ID )
929+
)
930+
) {
931+
_wp_dashboard_recent_comments_row( $comment );
932+
}
933+
}
924934
echo '</ul>';
925935

926936
if ( current_user_can( 'edit_posts' ) ) {

src/wp-includes/Requests/Hooks.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,8 @@ public function dispatch($hook, $parameters = array()) {
6565

6666
return true;
6767
}
68-
}
68+
69+
public function __wakeup() {
70+
throw new \LogicException( __CLASS__ . ' should never be unserialized' );
71+
}
72+
}

src/wp-includes/Requests/IRI.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,20 @@ public function is_valid() {
703703
return true;
704704
}
705705

706+
public function __wakeup() {
707+
$class_props = get_class_vars( __CLASS__ );
708+
$string_props = array( 'scheme', 'iuserinfo', 'ihost', 'port', 'ipath', 'iquery', 'ifragment' );
709+
$array_props = array( 'normalization' );
710+
foreach ( $class_props as $prop => $default_value ) {
711+
if ( in_array( $prop, $string_props, true ) && ! is_string( $this->$prop ) ) {
712+
throw new UnexpectedValueException();
713+
} elseif ( in_array( $prop, $array_props, true ) && ! is_array( $this->$prop ) ) {
714+
throw new UnexpectedValueException();
715+
}
716+
$this->$prop = null;
717+
}
718+
}
719+
706720
/**
707721
* Set the entire IRI. Returns true on success, false on failure (if there
708722
* are any invalid characters).

src/wp-includes/Requests/Session.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,10 @@ public function request_multiple($requests, $options = array()) {
227227
return Requests::request_multiple($requests, $options);
228228
}
229229

230+
public function __wakeup() {
231+
throw new \LogicException( __CLASS__ . ' should never be unserialized' );
232+
}
233+
230234
/**
231235
* Merge a request's data with the default data
232236
*

src/wp-includes/class-wp-theme.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,28 @@ public function parent() {
530530
return isset( $this->parent ) ? $this->parent : false;
531531
}
532532

533+
/**
534+
* Perform reinitialization tasks.
535+
*
536+
* Prevents a callback from being injected during unserialization of an object.
537+
*
538+
* @return void
539+
*/
540+
public function __wakeup() {
541+
if ( $this->parent && ! $this->parent instanceof self ) {
542+
throw new UnexpectedValueException();
543+
}
544+
if ( $this->headers && ! is_array( $this->headers ) ) {
545+
throw new UnexpectedValueException();
546+
}
547+
foreach ( $this->headers as $value ) {
548+
if ( ! is_string( $value ) ) {
549+
throw new UnexpectedValueException();
550+
}
551+
}
552+
$this->headers_sanitized = array();
553+
}
554+
533555
/**
534556
* Adds theme data to cache.
535557
*
@@ -1496,4 +1518,16 @@ private static function _name_sort_i18n( $a, $b ) {
14961518
// Don't mark up; Do translate.
14971519
return strnatcasecmp( $a->display( 'Name', false, true ), $b->display( 'Name', false, true ) );
14981520
}
1521+
1522+
private static function _check_headers_property_has_correct_type( $headers ) {
1523+
if ( ! is_array( $headers ) ) {
1524+
return false;
1525+
}
1526+
foreach ( $headers as $key => $value ) {
1527+
if ( ! is_string( $key ) || ! is_string( $value ) ) {
1528+
return false;
1529+
}
1530+
}
1531+
return true;
1532+
}
14991533
}

src/wp-includes/media.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1687,11 +1687,24 @@ function gallery_shortcode( $attr ) {
16871687
$attachments[$val->ID] = $_attachments[$key];
16881688
}
16891689
} elseif ( ! empty( $atts['exclude'] ) ) {
1690+
$post_parent_id = $id;
16901691
$attachments = get_children( array( 'post_parent' => $id, 'exclude' => $atts['exclude'], 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $atts['order'], 'orderby' => $atts['orderby'] ) );
16911692
} else {
1693+
$post_parent_id = $id;
16921694
$attachments = get_children( array( 'post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $atts['order'], 'orderby' => $atts['orderby'] ) );
16931695
}
16941696

1697+
if ( ! empty( $post_parent_id ) ) {
1698+
$post_parent = get_post( $post_parent_id );
1699+
1700+
// terminate the shortcode execution if user cannot read the post or password-protected
1701+
if (
1702+
( ! is_post_publicly_viewable( $post_parent->ID ) && ! current_user_can( 'read_post', $post_parent->ID ) )
1703+
|| post_password_required( $post_parent ) ) {
1704+
return '';
1705+
}
1706+
}
1707+
16951708
if ( empty( $attachments ) ) {
16961709
return '';
16971710
}
@@ -1991,6 +2004,15 @@ function wp_playlist_shortcode( $attr ) {
19912004
$attachments = get_children( $args );
19922005
}
19932006

2007+
if ( ! empty( $args['post_parent'] ) ) {
2008+
$post_parent = get_post( $id );
2009+
2010+
// terminate the shortcode execution if user cannot read the post or password-protected
2011+
if ( ! current_user_can( 'read_post', $post_parent->ID ) || post_password_required( $post_parent ) ) {
2012+
return '';
2013+
}
2014+
}
2015+
19942016
if ( empty( $attachments ) ) {
19952017
return '';
19962018
}

src/wp-includes/rest-api.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,7 @@ function rest_cookie_check_errors( $result ) {
725725
$result = wp_verify_nonce( $nonce, 'wp_rest' );
726726

727727
if ( ! $result ) {
728+
add_filter( 'rest_send_nocache_headers', '__return_true', 20 );
728729
return new WP_Error( 'rest_cookie_invalid_nonce', __( 'Cookie nonce is invalid' ), array( 'status' => 403 ) );
729730
}
730731

0 commit comments

Comments
 (0)