From 16c32fb590d39d3e70ab89d23a80c416d8c15fbd Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 17 Oct 2022 17:56:20 +0000 Subject: [PATCH] Grouped backports to the 4.2 branch. - Posts, Post types: Apply KSES to post-by-email content, - General: Validate host on "Are you sure?" screen, - Posts, Post types: Remove emails from post-by-email logs, - Pings/trackbacks: Apply KSES to all trackbacks, - Comments: Apply kses when editing comments, - Mail: Reset PHPMailer properties between use, - Query: Validate relation in `WP_Date_Query`, - Widgets: Escape RSS error messages for display. Merges [54521], [54522], [54523], [54525], [54527], [54529], [54530], [54541] to the 4.2 branch. Props voldemortensen, johnbillion, paulkevan, peterwilsoncc, xknown, dd32, audrasjb, martinkrcho, davidbaumwald, tykoted, johnjamesjacoby, ehtis, matveb, talldanwp. Built from https://develop.svn.wordpress.org/branches/4.2@54554 git-svn-id: http://core.svn.wordpress.org/branches/4.2@54109 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/comment.php | 13 +++++++++++++ wp-includes/date.php | 23 +++++++++++++++++++++-- wp-includes/default-widgets.php | 4 ++-- wp-includes/functions.php | 12 ++++++++++-- wp-includes/pluggable.php | 2 ++ wp-mail.php | 4 +++- wp-trackback.php | 3 +++ 7 files changed, 54 insertions(+), 7 deletions(-) diff --git a/wp-includes/comment.php b/wp-includes/comment.php index e2ed55386a..aa8759e190 100644 --- a/wp-includes/comment.php +++ b/wp-includes/comment.php @@ -2426,6 +2426,15 @@ function wp_update_comment($commentarr) { return 0; } + $filter_comment = false; + if ( ! has_filter( 'pre_comment_content', 'wp_filter_kses' ) ) { + $filter_comment = ! user_can( isset( $comment['user_id'] ) ? $comment['user_id'] : 0, 'unfiltered_html' ); + } + + if ( $filter_comment ) { + add_filter( 'pre_comment_content', 'wp_filter_kses' ); + } + // Escape data pulled from DB. $comment = wp_slash($comment); @@ -2436,6 +2445,10 @@ function wp_update_comment($commentarr) { $commentarr = wp_filter_comment( $commentarr ); + if ( $filter_comment ) { + remove_filter( 'pre_comment_content', 'wp_filter_kses' ); + } + // Now extract the merged array. $data = wp_unslash( $commentarr ); diff --git a/wp-includes/date.php b/wp-includes/date.php index 2e903a2518..5422143601 100644 --- a/wp-includes/date.php +++ b/wp-includes/date.php @@ -152,8 +152,8 @@ class WP_Date_Query { */ public function __construct( $date_query, $default_column = 'post_date' ) { - if ( isset( $date_query['relation'] ) && 'OR' === strtoupper( $date_query['relation'] ) ) { - $this->relation = 'OR'; + if ( isset( $date_query['relation'] ) ) { + $this->relation = $this->sanitize_relation( $date_query['relation'] ); } else { $this->relation = 'AND'; } @@ -233,6 +233,9 @@ class WP_Date_Query { $this->validate_date_values( $queries ); } + // Sanitize the relation parameter. + $queries['relation'] = $this->sanitize_relation( $queries['relation'] ); + foreach ( $queries as $key => $q ) { if ( ! is_array( $q ) || in_array( $key, $this->time_keys, true ) ) { // This is a first-order query. Trust the values and sanitize when building SQL. @@ -1010,4 +1013,20 @@ class WP_Date_Query { return $wpdb->prepare( "DATE_FORMAT( $column, %s ) $compare %f", $format, $time ); } + + /** + * Sanitizes a 'relation' operator. + * + * @since 6.0.3 + * + * @param string $relation Raw relation key from the query argument. + * @return string Sanitized relation ('AND' or 'OR'). + */ + public function sanitize_relation( $relation ) { + if ( 'OR' === strtoupper( $relation ) ) { + return 'OR'; + } else { + return 'AND'; + } + } } diff --git a/wp-includes/default-widgets.php b/wp-includes/default-widgets.php index fe87837e3c..02a371deb2 100644 --- a/wp-includes/default-widgets.php +++ b/wp-includes/default-widgets.php @@ -1054,7 +1054,7 @@ function wp_widget_rss_output( $rss, $args = array() ) { if ( is_wp_error($rss) ) { if ( is_admin() || current_user_can('manage_options') ) - echo '

' . sprintf( __('RSS Error: %s'), $rss->get_error_message() ) . '

'; + echo '

' . sprintf( __('RSS Error: %s'), esc_html( $rss->get_error_message() ) ) . '

'; return; } @@ -1164,7 +1164,7 @@ function wp_widget_rss_form( $args, $inputs = null ) { $args['show_date'] = isset( $args['show_date'] ) ? (int) $args['show_date'] : (int) $inputs['show_date']; if ( ! empty( $args['error'] ) ) { - echo '

' . sprintf( __( 'RSS Error: %s' ), $args['error'] ) . '

'; + echo '

' . sprintf( __( 'RSS Error: %s' ), esc_html( $args['error'] ) ) . '

'; } if ( $inputs['url'] ) : diff --git a/wp-includes/functions.php b/wp-includes/functions.php index fc5b7b7697..f4f8a44a31 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -2440,8 +2440,16 @@ function wp_nonce_ays( $action ) { $html .= sprintf( __( "Do you really want to log out?"), wp_logout_url( $redirect_to ) ); } else { $html = __( 'Are you sure you want to do this?' ); - if ( wp_get_referer() ) - $html .= "

" . __( 'Please try again.' ) . ""; + if ( wp_get_referer() ) { + $wp_http_referer = remove_query_arg( 'updated', wp_get_referer() ); + $wp_http_referer = wp_validate_redirect( esc_url_raw( $wp_http_referer ) ); + $html .= '

'; + $html .= sprintf( + '%s', + esc_url( $wp_http_referer ), + __( 'Please try again.' ) + ); + } } wp_die( $html, __( 'WordPress Failure Notice' ), 403 ); diff --git a/wp-includes/pluggable.php b/wp-includes/pluggable.php index 430834b9a9..a851cf396b 100644 --- a/wp-includes/pluggable.php +++ b/wp-includes/pluggable.php @@ -356,6 +356,8 @@ function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() $phpmailer->ClearAttachments(); $phpmailer->ClearCustomHeaders(); $phpmailer->ClearReplyTos(); + $phpmailer->Body = ''; + $phpmailer->AltBody = ''; // From email and name // If we don't have a name from the input headers diff --git a/wp-mail.php b/wp-mail.php index aa062c6874..a0a0459f90 100644 --- a/wp-mail.php +++ b/wp-mail.php @@ -60,6 +60,9 @@ if( 0 === $count ) { wp_die( __('There doesn’t seem to be any new mail.') ); } +// Always run as an unauthenticated user. +wp_set_current_user( 0 ); + for ( $i = 1; $i <= $count; $i++ ) { $message = $pop3->get($i); @@ -125,7 +128,6 @@ for ( $i = 1; $i <= $count; $i++ ) { $author = trim($line); $author = sanitize_email($author); if ( is_email($author) ) { - echo '

' . sprintf(__('Author is %s'), $author) . '

'; $userdata = get_user_by('email', $author); if ( ! empty( $userdata ) ) { $post_author = $userdata->ID; diff --git a/wp-trackback.php b/wp-trackback.php index 3d211043eb..8fe5b087be 100644 --- a/wp-trackback.php +++ b/wp-trackback.php @@ -13,6 +13,9 @@ if (empty($wp)) { wp( array( 'tb' => '1' ) ); } +// Always run as an unauthenticated user. +wp_set_current_user( 0 ); + /** * Response to a trackback. *