Skip to content

Commit f246022

Browse files
committed
Grouped backports to the 5.1 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 [56833], [56834], [56835], [56836], and [56838] to the 5.1 branch. Props xknown, jorbin, joehoyle, timothyblynjacobs, peterwilsoncc, ehtis, tykoted, antpb, rmccue. git-svn-id: https://develop.svn.wordpress.org/branches/5.1@56873 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 96938e4 commit f246022

File tree

14 files changed

+216
-25
lines changed

14 files changed

+216
-25
lines changed

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

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

34973497
$shortcode = wp_unslash( $_POST['shortcode'] );
34983498

3499+
// Only process previews for media related shortcodes:
3500+
$found_shortcodes = get_shortcode_tags_in_content( $shortcode );
3501+
$media_shortcodes = array(
3502+
'audio',
3503+
'embed',
3504+
'playlist',
3505+
'video',
3506+
'gallery',
3507+
);
3508+
3509+
$other_shortcodes = array_diff( $found_shortcodes, $media_shortcodes );
3510+
3511+
if ( ! empty( $other_shortcodes ) ) {
3512+
wp_send_json_error();
3513+
}
3514+
34993515
if ( ! empty( $_POST['post_ID'] ) ) {
35003516
$post = get_post( (int) $_POST['post_ID'] );
35013517
}
35023518

35033519
// the embed shortcode requires a post
35043520
if ( ! $post || ! current_user_can( 'edit_post', $post->ID ) ) {
3505-
if ( 'embed' === $shortcode ) {
3521+
if ( in_array( 'embed', $found_shortcodes, true ) ) {
35063522
wp_send_json_error();
35073523
}
35083524
} 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
@@ -554,6 +554,19 @@ public function single_row( $item ) {
554554
}
555555
$this->user_can = current_user_can( 'edit_comment', $comment->comment_ID );
556556

557+
$edit_post_cap = $post ? 'edit_post' : 'edit_posts';
558+
if (
559+
current_user_can( $edit_post_cap, $comment->comment_post_ID ) ||
560+
(
561+
empty( $post->post_password ) &&
562+
current_user_can( 'read_post', $comment->comment_post_ID )
563+
)
564+
) {
565+
// The user has access to the post
566+
} else {
567+
return false;
568+
}
569+
557570
echo "<tr id='comment-$comment->comment_ID' class='$the_comment_class'>";
558571
$this->single_row_columns( $comment );
559572
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
@@ -665,7 +665,20 @@ protected function comments_bubble( $post_id, $pending_comments ) {
665665
$approved_phrase = sprintf( _n( '%s approved comment', '%s approved comments', $approved_comments ), $approved_comments_number );
666666
$pending_phrase = sprintf( _n( '%s pending comment', '%s pending comments', $pending_comments ), $pending_comments_number );
667667

668-
// No comments at all.
668+
$post_object = get_post( $post_id );
669+
$edit_post_cap = $post_object ? 'edit_post' : 'edit_posts';
670+
if (
671+
current_user_can( $edit_post_cap, $post_id ) ||
672+
(
673+
empty( $post_object->post_password ) &&
674+
current_user_can( 'read_post', $post_id )
675+
)
676+
) {
677+
// The user has access to the post and thus can see comments
678+
} else {
679+
return false;
680+
}
681+
669682
if ( ! $approved_comments && ! $pending_comments ) {
670683
printf(
671684
'<span aria-hidden="true">&#8212;</span><span class="screen-reader-text">%s</span>',

src/wp-admin/includes/dashboard.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,16 @@ function wp_dashboard_recent_comments( $total_items = 5 ) {
947947

948948
echo '<ul id="the-comment-list" data-wp-lists="list:comment">';
949949
foreach ( $comments as $comment ) {
950-
_wp_dashboard_recent_comments_row( $comment );
950+
$comment_post = get_post( $comment->comment_post_ID );
951+
if (
952+
current_user_can( 'edit_post', $comment->comment_post_ID ) ||
953+
(
954+
empty( $comment_post->post_password ) &&
955+
current_user_can( 'read_post', $comment->comment_post_ID )
956+
)
957+
) {
958+
_wp_dashboard_recent_comments_row( $comment );
959+
}
951960
}
952961
echo '</ul>';
953962

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-block-type-registry.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,20 @@ public function is_registered( $name ) {
154154
return isset( $this->registered_block_types[ $name ] );
155155
}
156156

157+
public function __wakeup() {
158+
if ( ! $this->registered_block_types ) {
159+
return;
160+
}
161+
if ( ! is_array( $this->registered_block_types ) ) {
162+
throw new UnexpectedValueException();
163+
}
164+
foreach ( $this->registered_block_types as $value ) {
165+
if ( ! $value instanceof WP_Block_Type ) {
166+
throw new UnexpectedValueException();
167+
}
168+
}
169+
}
170+
157171
/**
158172
* Utility method to retrieve the main instance of the class.
159173
*

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

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

629+
/**
630+
* Perform reinitialization tasks.
631+
*
632+
* Prevents a callback from being injected during unserialization of an object.
633+
*
634+
* @return void
635+
*/
636+
public function __wakeup() {
637+
if ( $this->parent && ! $this->parent instanceof self ) {
638+
throw new UnexpectedValueException();
639+
}
640+
if ( $this->headers && ! is_array( $this->headers ) ) {
641+
throw new UnexpectedValueException();
642+
}
643+
foreach ( $this->headers as $value ) {
644+
if ( ! is_string( $value ) ) {
645+
throw new UnexpectedValueException();
646+
}
647+
}
648+
$this->headers_sanitized = array();
649+
}
650+
629651
/**
630652
* Adds theme data to cache.
631653
*
@@ -1604,4 +1626,16 @@ private static function _name_sort( $a, $b ) {
16041626
private static function _name_sort_i18n( $a, $b ) {
16051627
return strnatcasecmp( $a->name_translated, $b->name_translated );
16061628
}
1629+
1630+
private static function _check_headers_property_has_correct_type( $headers ) {
1631+
if ( ! is_array( $headers ) ) {
1632+
return false;
1633+
}
1634+
foreach ( $headers as $key => $value ) {
1635+
if ( ! is_string( $key ) || ! is_string( $value ) ) {
1636+
return false;
1637+
}
1638+
}
1639+
return true;
1640+
}
16071641
}

src/wp-includes/media.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,7 +1747,8 @@ function gallery_shortcode( $attr ) {
17471747
$attachments[ $val->ID ] = $_attachments[ $key ];
17481748
}
17491749
} elseif ( ! empty( $atts['exclude'] ) ) {
1750-
$attachments = get_children(
1750+
$post_parent_id = $id;
1751+
$attachments = get_children(
17511752
array(
17521753
'post_parent' => $id,
17531754
'exclude' => $atts['exclude'],
@@ -1759,7 +1760,8 @@ function gallery_shortcode( $attr ) {
17591760
)
17601761
);
17611762
} else {
1762-
$attachments = get_children(
1763+
$post_parent_id = $id;
1764+
$attachments = get_children(
17631765
array(
17641766
'post_parent' => $id,
17651767
'post_status' => 'inherit',
@@ -1771,6 +1773,17 @@ function gallery_shortcode( $attr ) {
17711773
);
17721774
}
17731775

1776+
if ( ! empty( $post_parent_id ) ) {
1777+
$post_parent = get_post( $post_parent_id );
1778+
1779+
// terminate the shortcode execution if user cannot read the post or password-protected
1780+
if (
1781+
( ! is_post_publicly_viewable( $post_parent->ID ) && ! current_user_can( 'read_post', $post_parent->ID ) )
1782+
|| post_password_required( $post_parent ) ) {
1783+
return '';
1784+
}
1785+
}
1786+
17741787
if ( empty( $attachments ) ) {
17751788
return '';
17761789
}
@@ -2078,6 +2091,15 @@ function wp_playlist_shortcode( $attr ) {
20782091
$attachments = get_children( $args );
20792092
}
20802093

2094+
if ( ! empty( $args['post_parent'] ) ) {
2095+
$post_parent = get_post( $id );
2096+
2097+
// terminate the shortcode execution if user cannot read the post or password-protected
2098+
if ( ! current_user_can( 'read_post', $post_parent->ID ) || post_password_required( $post_parent ) ) {
2099+
return '';
2100+
}
2101+
}
2102+
20812103
if ( empty( $attachments ) ) {
20822104
return '';
20832105
}

0 commit comments

Comments
 (0)