Commit a159a58212 for wordpress.org
commit a159a58212923db3020f097163af355fd44afc8b
Author: johnbillion <johnbillion@git.wordpress.org>
Date: Wed Nov 18 13:14:51 2026 +0000
XML-RPC: Only return comments the user can read from `wp.getComments`.
Props villanovachile, peterwilsoncc, westonruter, johnbillion, jonsurrell, jeremyfelt.
Built from https://develop.svn.wordpress.org/trunk@65571
git-svn-id: http://core.svn.wordpress.org/trunk@64644 1a063a9b-81f0-0310-95a4-ce76da25c4cd
diff --git a/wp-includes/class-wp-xmlrpc-server.php b/wp-includes/class-wp-xmlrpc-server.php
index 4ac680065f..3a4db2f5f1 100644
--- a/wp-includes/class-wp-xmlrpc-server.php
+++ b/wp-includes/class-wp-xmlrpc-server.php
@@ -1243,6 +1243,9 @@ class wp_xmlrpc_server extends IXR_Server {
} else {
$comment_status = $comment->comment_approved;
}
+
+ $can_moderate_or_edit = current_user_can( 'moderate_comments' ) || current_user_can( 'edit_comment', $comment->comment_ID );
+
$_comment = array(
'date_created_gmt' => $comment_date_gmt,
'user_id' => $comment->user_id,
@@ -1255,8 +1258,8 @@ class wp_xmlrpc_server extends IXR_Server {
'post_title' => get_the_title( $comment->comment_post_ID ),
'author' => $comment->comment_author,
'author_url' => $comment->comment_author_url,
- 'author_email' => $comment->comment_author_email,
- 'author_ip' => $comment->comment_author_IP,
+ 'author_email' => $can_moderate_or_edit ? $comment->comment_author_email : '',
+ 'author_ip' => $can_moderate_or_edit ? $comment->comment_author_IP : '',
'type' => $comment->comment_type,
);
@@ -3784,7 +3787,9 @@ class wp_xmlrpc_server extends IXR_Server {
$status = $struct['status'] ?? '';
- if ( ! current_user_can( 'moderate_comments' ) && 'approve' !== $status ) {
+ $can_moderate = current_user_can( 'moderate_comments' );
+
+ if ( ! $can_moderate && 'approve' !== $status ) {
return new IXR_Error( 401, __( 'Invalid comment status.' ) );
}
@@ -3793,6 +3798,17 @@ class wp_xmlrpc_server extends IXR_Server {
$post_id = absint( $struct['post_id'] );
}
+ $has_public_status = static function ( $post ) {
+ $status = get_post_status( $post );
+ $status_object = $status ? get_post_status_object( $status ) : null;
+
+ return $status_object && $status_object->public;
+ };
+
+ if ( $post_id && ! $can_moderate && ! $has_public_status( $post_id ) && ! current_user_can( 'read_post', $post_id ) ) {
+ return new IXR_Error( 401, __( 'Invalid post ID.' ) );
+ }
+
$post_type = '';
if ( isset( $struct['post_type'] ) ) {
$post_type_object = get_post_type_object( $struct['post_type'] );
@@ -3814,17 +3830,31 @@ class wp_xmlrpc_server extends IXR_Server {
$comments = get_comments(
array(
- 'status' => $status,
- 'post_id' => $post_id,
- 'offset' => $offset,
- 'number' => $number,
- 'post_type' => $post_type,
+ 'status' => $status,
+ 'post_id' => $post_id,
+ 'offset' => $offset,
+ 'number' => $number,
+ 'post_type' => $post_type,
+ 'update_comment_post_cache' => true,
)
);
$comments_struct = array();
if ( is_array( $comments ) ) {
foreach ( $comments as $comment ) {
+ if ( ! $can_moderate && ! current_user_can( 'edit_comment', $comment->comment_ID ) ) {
+ $post = get_post( $comment->comment_post_ID );
+
+ if (
+ ! $post
+ || ! is_post_type_viewable( $post->post_type )
+ || post_password_required( $post )
+ || ( ! $has_public_status( $post ) && ! current_user_can( 'read_post', $post->ID ) )
+ ) {
+ continue;
+ }
+ }
+
$comments_struct[] = $this->_prepare_comment( $comment );
}
}
diff --git a/wp-includes/version.php b/wp-includes/version.php
index cd24148660..1b16ef855b 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
-$wp_version = '7.2-RC1-65570';
+$wp_version = '7.2-RC1-65571';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.