Skip to content

Commit 345f6c1

Browse files
committed
Grouped backports to the 5.5 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.5 branch. Props xknown, jorbin, joehoyle, timothyblynjacobs, peterwilsoncc, ehtis, tykoted, antpb, rmccue. git-svn-id: https://develop.svn.wordpress.org/branches/5.5@56880 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 5cfa531 commit 345f6c1

15 files changed

+230
-22
lines changed

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

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

37673767
$shortcode = wp_unslash( $_POST['shortcode'] );
37683768

3769+
// Only process previews for media related shortcodes:
3770+
$found_shortcodes = get_shortcode_tags_in_content( $shortcode );
3771+
$media_shortcodes = array(
3772+
'audio',
3773+
'embed',
3774+
'playlist',
3775+
'video',
3776+
'gallery',
3777+
);
3778+
3779+
$other_shortcodes = array_diff( $found_shortcodes, $media_shortcodes );
3780+
3781+
if ( ! empty( $other_shortcodes ) ) {
3782+
wp_send_json_error();
3783+
}
3784+
37693785
if ( ! empty( $_POST['post_ID'] ) ) {
37703786
$post = get_post( (int) $_POST['post_ID'] );
37713787
}
37723788

37733789
// The embed shortcode requires a post.
37743790
if ( ! $post || ! current_user_can( 'edit_post', $post->ID ) ) {
3775-
if ( 'embed' === $shortcode ) {
3791+
if ( in_array( 'embed', $found_shortcodes, true ) ) {
37763792
wp_send_json_error();
37773793
}
37783794
} 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
@@ -614,6 +614,19 @@ public function single_row( $item ) {
614614
}
615615
$this->user_can = current_user_can( 'edit_comment', $comment->comment_ID );
616616

617+
$edit_post_cap = $post ? 'edit_post' : 'edit_posts';
618+
if (
619+
current_user_can( $edit_post_cap, $comment->comment_post_ID ) ||
620+
(
621+
empty( $post->post_password ) &&
622+
current_user_can( 'read_post', $comment->comment_post_ID )
623+
)
624+
) {
625+
// The user has access to the post
626+
} else {
627+
return false;
628+
}
629+
617630
echo "<tr id='comment-$comment->comment_ID' class='$the_comment_class'>";
618631
$this->single_row_columns( $comment );
619632
echo "</tr>\n";

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,20 @@ protected function comments_bubble( $post_id, $pending_comments ) {
698698
$pending_comments_number
699699
);
700700

701+
$post_object = get_post( $post_id );
702+
$edit_post_cap = $post_object ? 'edit_post' : 'edit_posts';
703+
if (
704+
current_user_can( $edit_post_cap, $post_id ) ||
705+
(
706+
empty( $post_object->post_password ) &&
707+
current_user_can( 'read_post', $post_id )
708+
)
709+
) {
710+
// The user has access to the post and thus can see comments
711+
} else {
712+
return false;
713+
}
714+
701715
if ( ! $approved_comments && ! $pending_comments ) {
702716
// No comments at all.
703717
printf(

src/wp-admin/includes/dashboard.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,17 @@ function wp_dashboard_recent_comments( $total_items = 5 ) {
10421042

10431043
echo '<ul id="the-comment-list" data-wp-lists="list:comment">';
10441044
foreach ( $comments as $comment ) {
1045-
_wp_dashboard_recent_comments_row( $comment );
1045+
1046+
$comment_post = get_post( $comment->comment_post_ID );
1047+
if (
1048+
current_user_can( 'edit_post', $comment->comment_post_ID ) ||
1049+
(
1050+
empty( $comment_post->post_password ) &&
1051+
current_user_can( 'read_post', $comment->comment_post_ID )
1052+
)
1053+
) {
1054+
_wp_dashboard_recent_comments_row( $comment );
1055+
}
10461056
}
10471057
echo '</ul>';
10481058

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-patterns-registry.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,21 @@ public function is_registered( $pattern_name ) {
122122
return isset( $this->registered_patterns[ $pattern_name ] );
123123
}
124124

125+
public function __wakeup() {
126+
if ( ! $this->registered_patterns ) {
127+
return;
128+
}
129+
if ( ! is_array( $this->registered_patterns ) ) {
130+
throw new UnexpectedValueException();
131+
}
132+
foreach ( $this->registered_patterns as $value ) {
133+
if ( ! is_array( $value ) ) {
134+
throw new UnexpectedValueException();
135+
}
136+
}
137+
$this->registered_patterns_outside_init = array();
138+
}
139+
125140
/**
126141
* Utility method to retrieve the main instance of the class.
127142
*

src/wp-includes/class-wp-block-type-registry.php

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

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

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

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

677+
/**
678+
* Perform reinitialization tasks.
679+
*
680+
* Prevents a callback from being injected during unserialization of an object.
681+
*
682+
* @return void
683+
*/
684+
public function __wakeup() {
685+
if ( $this->parent && ! $this->parent instanceof self ) {
686+
throw new UnexpectedValueException();
687+
}
688+
if ( $this->headers && ! is_array( $this->headers ) ) {
689+
throw new UnexpectedValueException();
690+
}
691+
foreach ( $this->headers as $value ) {
692+
if ( ! is_string( $value ) ) {
693+
throw new UnexpectedValueException();
694+
}
695+
}
696+
$this->headers_sanitized = array();
697+
}
698+
677699
/**
678700
* Adds theme data to cache.
679701
*
@@ -1658,4 +1680,16 @@ private static function _name_sort( $a, $b ) {
16581680
private static function _name_sort_i18n( $a, $b ) {
16591681
return strnatcasecmp( $a->name_translated, $b->name_translated );
16601682
}
1683+
1684+
private static function _check_headers_property_has_correct_type( $headers ) {
1685+
if ( ! is_array( $headers ) ) {
1686+
return false;
1687+
}
1688+
foreach ( $headers as $key => $value ) {
1689+
if ( ! is_string( $key ) || ! is_string( $value ) ) {
1690+
return false;
1691+
}
1692+
}
1693+
return true;
1694+
}
16611695
}

0 commit comments

Comments
 (0)