Skip to content

Commit d9fcfe3

Browse files
committed
Security: Backport the WordPress 7.1.5 security fixes to the 7.0 branch.
- Interactivity API: Escape the store namespace in `wp_interactivity_data_wp_context()`. - REST API: Return no terms when a term search resolves to no taxonomy. - REST API: Escape a hyphen in `wp_is_json_media_type()`. - XML-RPC: Only return comments the user can read from `wp.getComments`. - Meta API: Validate the `relation` argument in `WP_Meta_Query`. - Query: Use prepared statements for more `WP_Query` clauses. - Customize: Sanitize option settings with sanitize_option() when previewing. - REST API: Only serve `rest_route` requests outside of the admin. - XML-RPC: Process only one pingback per request. - Comments: Check permissions before moving a comment to another post in the admin. - Shortcodes: Prevent attribute escape sequences from forming HTML. - Customize: Harden nav menu args handling. - REST API: Harden comment author handling. - Embeds: Return scripts from the oEmbed proxy only for embed handlers. - REST API: Restrict post and template author assignment to site members. Merges [65567], [65568], [65569], [65570], [65571], [65572], [65573], [65574], [65575], [65576], [65577], [65578], [65579], [65580], [65581], [65582] to the 7.0 branch. Props jrf, gziolo, luisherranz, jonsurrell, lancewillett, xknown, dmsnell, jeremyfelt, batmoo, villanovachile, peterwilsoncc, westonruter, johnbillion, rfaile313, tyxla, jorbin, ramonopoly, adamsilverstein, ntsekouras, ehtis, andrewserong, jsnajdr, jeryj. git-svn-id: https://develop.svn.wordpress.org/branches/7.0@65587 602fd350-edb4-49c9-b593-d223f7449a82
1 parent ec49f3c commit d9fcfe3

18 files changed

Lines changed: 592 additions & 79 deletions

‎src/wp-admin/includes/comment.php‎

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ function comment_exists( $comment_author, $comment_date, $timezone = 'blog' ) {
4646
*
4747
* @since 2.0.0
4848
* @since 5.5.0 A return value was added.
49+
* @since 7.1.5 Moving a comment to another post is checked against the user's capabilities,
50+
* and the comment type can no longer be changed.
4951
*
5052
* @return int|WP_Error The value 1 if the comment was updated, 0 if not updated.
5153
* A WP_Error object on failure.
@@ -74,6 +76,42 @@ function edit_comment() {
7476
$_POST['comment_ID'] = (int) $_POST['comment_ID'];
7577
}
7678

79+
$comment_id = (int) $_POST['comment_ID'];
80+
$comment = get_comment( $comment_id );
81+
82+
/*
83+
* The comment type is not editable from the Edit Comment screen. Changing it
84+
* would turn a private note into a public comment or vice versa.
85+
*/
86+
if ( $comment && isset( $_POST['comment_type'] ) && $_POST['comment_type'] !== $comment->comment_type ) {
87+
return new WP_Error( 'comment_type_invalid', __( 'The comment type cannot be changed.' ) );
88+
}
89+
90+
/*
91+
* The capability check above only establishes that the comment may be edited
92+
* where it currently sits, because 'edit_comment' maps to 'edit_post' on the
93+
* comment's current post. Moving the comment to another post has to be
94+
* authorized separately, otherwise a user who can edit a comment on their own
95+
* post could attach it to any post, including posts they can neither read nor
96+
* edit.
97+
*/
98+
99+
$comment_post_id = $comment ? (int) $comment->comment_post_ID : 0;
100+
101+
if ( $comment && isset( $_POST['comment_post_ID'] ) ) {
102+
$target_post_id = (int) $_POST['comment_post_ID'];
103+
104+
$_POST['comment_post_ID'] = $target_post_id;
105+
106+
if ( $target_post_id !== $comment_post_id ) {
107+
$target_post_check = _wp_check_comment_target_post( $comment, $target_post_id );
108+
109+
if ( is_wp_error( $target_post_check ) ) {
110+
return $target_post_check;
111+
}
112+
}
113+
}
114+
77115
foreach ( array( 'aa', 'mm', 'jj', 'hh', 'mn' ) as $timeunit ) {
78116
if ( ! empty( $_POST[ 'hidden_' . $timeunit ] ) && $_POST[ 'hidden_' . $timeunit ] !== $_POST[ $timeunit ] ) {
79117
$_POST['edit_date'] = '1';
@@ -99,6 +137,68 @@ function edit_comment() {
99137
return wp_update_comment( $_POST, true );
100138
}
101139

140+
/**
141+
* Checks that the current user may move a comment to another post.
142+
*
143+
* @since 7.1.5
144+
* @access private
145+
*
146+
* @param WP_Comment $comment The comment being moved.
147+
* @param int $post_id ID of the post the comment is being moved to.
148+
* @return true|WP_Error True if the comment may be moved to the post, WP_Error otherwise.
149+
*/
150+
function _wp_check_comment_target_post( WP_Comment $comment, int $post_id ) {
151+
$post = $post_id ? get_post( $post_id ) : null;
152+
153+
if ( ! $post ) {
154+
return new WP_Error( 'comment_post_invalid', __( 'Invalid post ID.' ) );
155+
}
156+
157+
/*
158+
* Notes are editorial content, so they may only be attached to a post the
159+
* user can edit. Any other comment needs either comment moderation rights
160+
* or edit access to the post, matching what 'edit_comment' requires on the
161+
* post the comment is moving away from.
162+
*/
163+
$is_note = 'note' === strtolower( $comment->comment_type );
164+
165+
if ( $is_note ) {
166+
$can_target_post = current_user_can( 'edit_post', $post->ID );
167+
} else {
168+
$can_target_post = current_user_can( 'moderate_comments' ) || current_user_can( 'edit_post', $post->ID );
169+
}
170+
171+
if ( ! $can_target_post ) {
172+
return new WP_Error( 'comment_post_invalid', __( 'Sorry, you are not allowed to move this comment to that post.' ) );
173+
}
174+
175+
if ( ! $is_note ) {
176+
return true;
177+
}
178+
179+
$supports_notes = false;
180+
$supports = get_all_post_type_supports( $post->post_type );
181+
182+
if ( isset( $supports['editor'] ) && is_array( $supports['editor'] ) ) {
183+
$supports_notes = array_any(
184+
$supports['editor'],
185+
static function ( $item ) {
186+
return is_array( $item ) && ! empty( $item['notes'] );
187+
}
188+
);
189+
}
190+
191+
if ( ! $supports_notes ) {
192+
return new WP_Error( 'comment_post_invalid', __( 'Sorry, this post type does not support notes.' ) );
193+
}
194+
195+
if ( 'trash' === $post->post_status || ! current_user_can( 'read_post', $post->ID ) ) {
196+
return new WP_Error( 'comment_post_invalid', __( 'Sorry, you are not allowed to move this comment to that post.' ) );
197+
}
198+
199+
return true;
200+
}
201+
102202
/**
103203
* Returns a WP_Comment object based on comment ID.
104204
*

‎src/wp-includes/class-wp-customize-manager.php‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5231,8 +5231,9 @@ public function register_controls() {
52315231
$this->add_setting(
52325232
'custom_logo',
52335233
array(
5234-
'theme_supports' => array( 'custom-logo' ),
5235-
'transport' => 'postMessage',
5234+
'theme_supports' => array( 'custom-logo' ),
5235+
'transport' => 'postMessage',
5236+
'sanitize_callback' => 'absint',
52365237
)
52375238
);
52385239

‎src/wp-includes/class-wp-customize-nav-menus.php‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1527,13 +1527,17 @@ public function filter_wp_nav_menu( $nav_menu_content, $args ) {
15271527
*
15281528
* Note that the array is expected to be pre-sorted.
15291529
*
1530+
* The serialized arguments are prefixed so that the resulting hash cannot
1531+
* collide with other `wp_hash()` values computed over serialized data.
1532+
*
15301533
* @since 4.3.0
1534+
* @since 7.1.5 The hash is now domain-separated from other hashes.
15311535
*
15321536
* @param array $args The arguments to hash.
15331537
* @return string Hashed nav menu arguments.
15341538
*/
15351539
public function hash_nav_menu_args( $args ) {
1536-
return wp_hash( serialize( $args ) );
1540+
return wp_hash( 'customize_nav_menu_args|' . serialize( $args ) );
15371541
}
15381542

15391543
/**

0 commit comments

Comments
 (0)