Skip to content

Commit e79d8fa

Browse files
Grouped backports to the 4.5 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, - Customize: Escape blogname option in underscores templates, - 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], [54526], [54527], [54529], [54530], [54541] to the 4.5 branch. Props voldemortensen, johnbillion, paulkevan, peterwilsoncc, xknown, dd32, audrasjb, martinkrcho, davidbaumwald, tykoted, johnjamesjacoby, ehtis, matveb, talldanwp. git-svn-id: https://develop.svn.wordpress.org/branches/4.5@54560 602fd350-edb4-49c9-b593-d223f7449a82
1 parent e223196 commit e79d8fa

File tree

10 files changed

+58
-11
lines changed

10 files changed

+58
-11
lines changed

src/wp-includes/comment.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,6 +1986,15 @@ function wp_update_comment($commentarr) {
19861986
return 0;
19871987
}
19881988

1989+
$filter_comment = false;
1990+
if ( ! has_filter( 'pre_comment_content', 'wp_filter_kses' ) ) {
1991+
$filter_comment = ! user_can( isset( $comment['user_id'] ) ? $comment['user_id'] : 0, 'unfiltered_html' );
1992+
}
1993+
1994+
if ( $filter_comment ) {
1995+
add_filter( 'pre_comment_content', 'wp_filter_kses' );
1996+
}
1997+
19891998
// Escape data pulled from DB.
19901999
$comment = wp_slash($comment);
19912000

@@ -1996,6 +2005,10 @@ function wp_update_comment($commentarr) {
19962005

19972006
$commentarr = wp_filter_comment( $commentarr );
19982007

2008+
if ( $filter_comment ) {
2009+
remove_filter( 'pre_comment_content', 'wp_filter_kses' );
2010+
}
2011+
19992012
// Now extract the merged array.
20002013
$data = wp_unslash( $commentarr );
20012014

src/wp-includes/customize/class-wp-customize-header-image-control.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ public function print_header_image_template() {
107107
<# } #>
108108

109109
<button type="button" class="choice thumbnail"
110-
data-customize-image-value="{{{data.header.url}}}"
110+
data-customize-image-value="{{data.header.url}}"
111111
data-customize-header-image-data="{{JSON.stringify(data.header)}}">
112112
<span class="screen-reader-text"><?php _e( 'Set image' ); ?></span>
113-
<img src="{{{data.header.thumbnail_url}}}" alt="{{{data.header.alt_text || data.header.description}}}">
113+
<img src="{{data.header.thumbnail_url}}" alt="{{data.header.alt_text || data.header.description}}" />
114114
</button>
115115

116116
<# } #>

src/wp-includes/customize/class-wp-customize-site-icon-control.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function content_template() {
7070
<div class="favicon">
7171
<img id="preview-favicon" src="{{ data.attachment.sizes.full.url }}" alt="<?php esc_attr_e( 'Preview as a browser icon' ); ?>"/>
7272
</div>
73-
<span class="browser-title"><?php bloginfo( 'name' ); ?></span>
73+
<span class="browser-title"><?php echo esc_js( get_bloginfo( 'name' ) ); ?></span>
7474
</div>
7575
<img class="app-icon-preview" src="{{ data.attachment.sizes.full.url }}" alt="<?php esc_attr_e( 'Preview as an app icon' ); ?>"/>
7676
</div>

src/wp-includes/date.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ class WP_Date_Query {
152152
*/
153153
public function __construct( $date_query, $default_column = 'post_date' ) {
154154

155-
if ( isset( $date_query['relation'] ) && 'OR' === strtoupper( $date_query['relation'] ) ) {
156-
$this->relation = 'OR';
155+
if ( isset( $date_query['relation'] ) ) {
156+
$this->relation = $this->sanitize_relation( $date_query['relation'] );
157157
} else {
158158
$this->relation = 'AND';
159159
}
@@ -233,6 +233,9 @@ public function sanitize_query( $queries, $parent_query = null ) {
233233
$this->validate_date_values( $queries );
234234
}
235235

236+
// Sanitize the relation parameter.
237+
$queries['relation'] = $this->sanitize_relation( $queries['relation'] );
238+
236239
foreach ( $queries as $key => $q ) {
237240
if ( ! is_array( $q ) || in_array( $key, $this->time_keys, true ) ) {
238241
// This is a first-order query. Trust the values and sanitize when building SQL.
@@ -1011,4 +1014,20 @@ public function build_time_query( $column, $compare, $hour = null, $minute = nul
10111014

10121015
return $wpdb->prepare( "DATE_FORMAT( $column, %s ) $compare %f", $format, $time );
10131016
}
1017+
1018+
/**
1019+
* Sanitizes a 'relation' operator.
1020+
*
1021+
* @since 6.0.3
1022+
*
1023+
* @param string $relation Raw relation key from the query argument.
1024+
* @return string Sanitized relation ('AND' or 'OR').
1025+
*/
1026+
public function sanitize_relation( $relation ) {
1027+
if ( 'OR' === strtoupper( $relation ) ) {
1028+
return 'OR';
1029+
} else {
1030+
return 'AND';
1031+
}
1032+
}
10141033
}

src/wp-includes/functions.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2605,8 +2605,16 @@ function wp_nonce_ays( $action ) {
26052605
$html .= sprintf( __( "Do you really want to <a href='%s'>log out</a>?"), wp_logout_url( $redirect_to ) );
26062606
} else {
26072607
$html = __( 'Are you sure you want to do this?' );
2608-
if ( wp_get_referer() )
2609-
$html .= "</p><p><a href='" . esc_url( remove_query_arg( 'updated', wp_get_referer() ) ) . "'>" . __( 'Please try again.' ) . "</a>";
2608+
if ( wp_get_referer() ) {
2609+
$wp_http_referer = remove_query_arg( 'updated', wp_get_referer() );
2610+
$wp_http_referer = wp_validate_redirect( esc_url_raw( $wp_http_referer ) );
2611+
$html .= '</p><p>';
2612+
$html .= sprintf(
2613+
'<a href="%s">%s</a>',
2614+
esc_url( $wp_http_referer ),
2615+
__( 'Please try again.' )
2616+
);
2617+
}
26102618
}
26112619

26122620
wp_die( $html, __( 'WordPress Failure Notice' ), 403 );

src/wp-includes/media-template.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1245,7 +1245,7 @@ function wp_print_media_templates() {
12451245
<div class="favicon">
12461246
<img id="preview-favicon" src="{{ data.url }}" alt="<?php esc_attr_e( 'Preview as a browser icon' ); ?>"/>
12471247
</div>
1248-
<span class="browser-title"><?php bloginfo( 'name' ); ?></span>
1248+
<span class="browser-title"><?php echo esc_js( get_bloginfo( 'name' ) ); ?></span>
12491249
</div>
12501250

12511251
<strong><?php _e( 'As an app icon' ); ?></strong>

src/wp-includes/pluggable.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,8 @@ function wp_mail( $to, $subject, $message, $headers = '', $attachments = array()
305305
$phpmailer->ClearAttachments();
306306
$phpmailer->ClearCustomHeaders();
307307
$phpmailer->ClearReplyTos();
308+
$phpmailer->Body = '';
309+
$phpmailer->AltBody = '';
308310

309311
// From email and name
310312
// If we don't have a name from the input headers

src/wp-includes/widgets.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,7 +1233,7 @@ function wp_widget_rss_output( $rss, $args = array() ) {
12331233

12341234
if ( is_wp_error($rss) ) {
12351235
if ( is_admin() || current_user_can('manage_options') )
1236-
echo '<p>' . sprintf( __('<strong>RSS Error</strong>: %s'), $rss->get_error_message() ) . '</p>';
1236+
echo '<p>' . sprintf( __('<strong>RSS Error</strong>: %s'), esc_html( $rss->get_error_message() ) ) . '</p>';
12371237
return;
12381238
}
12391239

@@ -1342,7 +1342,7 @@ function wp_widget_rss_form( $args, $inputs = null ) {
13421342
$args['show_date'] = isset( $args['show_date'] ) ? (int) $args['show_date'] : (int) $inputs['show_date'];
13431343

13441344
if ( ! empty( $args['error'] ) ) {
1345-
echo '<p class="widget-error"><strong>' . sprintf( __( 'RSS Error: %s' ), $args['error'] ) . '</strong></p>';
1345+
echo '<p class="widget-error"><strong>' . sprintf( __( 'RSS Error: %s' ), esc_html( $args['error'] ) ) . '</strong></p>';
13461346
}
13471347

13481348
$esc_number = esc_attr( $args['number'] );

src/wp-mail.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@
6060
wp_die( __('There doesn&#8217;t seem to be any new mail.') );
6161
}
6262

63+
// Always run as an unauthenticated user.
64+
wp_set_current_user( 0 );
65+
6366
for ( $i = 1; $i <= $count; $i++ ) {
6467

6568
$message = $pop3->get($i);
@@ -125,7 +128,6 @@
125128
$author = trim($line);
126129
$author = sanitize_email($author);
127130
if ( is_email($author) ) {
128-
echo '<p>' . sprintf(__('Author is %s'), $author) . '</p>';
129131
$userdata = get_user_by('email', $author);
130132
if ( ! empty( $userdata ) ) {
131133
$post_author = $userdata->ID;

src/wp-trackback.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
wp( array( 'tb' => '1' ) );
1414
}
1515

16+
// Always run as an unauthenticated user.
17+
wp_set_current_user( 0 );
18+
1619
/**
1720
* Response to a trackback.
1821
*

0 commit comments

Comments
 (0)