From e3a3ba4caacf96dfd51633e48d96f86de7622398 Mon Sep 17 00:00:00 2001
From: Scott Taylor
Date: Sun, 30 Aug 2015 05:37:53 +0000
Subject: [PATCH] Improve/update escaping in default widgets:
* wrap some variables in `esc_attr()` before echoing
* replace some `strip_tags()` calls with `sanitize_text_field()`
* call `esc_url()` when wrapping some URLs
Props welcher.
See #23012.
git-svn-id: https://develop.svn.wordpress.org/trunk@33814 602fd350-edb4-49c9-b593-d223f7449a82
---
src/wp-includes/default-widgets.php | 119 ++++++++++++++--------------
1 file changed, 59 insertions(+), 60 deletions(-)
diff --git a/src/wp-includes/default-widgets.php b/src/wp-includes/default-widgets.php
index ab7a977ea5..482ee81586 100644
--- a/src/wp-includes/default-widgets.php
+++ b/src/wp-includes/default-widgets.php
@@ -290,7 +290,7 @@ class WP_Widget_Search extends WP_Widget {
public function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$new_instance = wp_parse_args((array) $new_instance, array( 'title' => ''));
- $instance['title'] = strip_tags($new_instance['title']);
+ $instance['title'] = sanitize_text_field( $new_instance['title'] );
return $instance;
}
@@ -402,7 +402,7 @@ class WP_Widget_Archives extends WP_Widget {
public function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$new_instance = wp_parse_args( (array) $new_instance, array( 'title' => '', 'count' => 0, 'dropdown' => '') );
- $instance['title'] = strip_tags($new_instance['title']);
+ $instance['title'] = sanitize_text_field( $new_instance['title'] );
$instance['count'] = $new_instance['count'] ? 1 : 0;
$instance['dropdown'] = $new_instance['dropdown'] ? 1 : 0;
@@ -414,15 +414,13 @@ class WP_Widget_Archives extends WP_Widget {
*/
public function form( $instance ) {
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'count' => 0, 'dropdown' => '') );
- $title = strip_tags($instance['title']);
- $count = $instance['count'] ? 'checked="checked"' : '';
- $dropdown = $instance['dropdown'] ? 'checked="checked"' : '';
+ $title = sanitize_text_field( $instance['title'] );
?>
- id="get_field_id('dropdown'); ?>" name="get_field_name('dropdown'); ?>" />
+ id="get_field_id('dropdown'); ?>" name="get_field_name('dropdown'); ?>" />
- id="get_field_id('count'); ?>" name="get_field_name('count'); ?>" />
+ id="get_field_id('count'); ?>" name="get_field_name('count'); ?>" />
- RSS'); ?>
- RSS'); ?>
+ RSS'); ?>
+ RSS'); ?>
'' ) );
- $title = strip_tags($instance['title']);
+ $title = sanitize_text_field( $instance['title'] );
?>
'' ) );
- $title = strip_tags($instance['title']);
+ $title = sanitize_text_field( $instance['title'] );
?>
@@ -606,11 +604,11 @@ class WP_Widget_Text extends WP_Widget {
*/
public function update( $new_instance, $old_instance ) {
$instance = $old_instance;
- $instance['title'] = strip_tags($new_instance['title']);
+ $instance['title'] = sanitize_text_field( $new_instance['title'] );
if ( current_user_can('unfiltered_html') )
$instance['text'] = $new_instance['text'];
else
- $instance['text'] = stripslashes( wp_filter_post_kses( addslashes($new_instance['text']) ) ); // wp_filter_post_kses() expects slashed
+ $instance['text'] = wp_kses_post( stripslashes( $new_instance['text'] ) );
$instance['filter'] = ! empty( $new_instance['filter'] );
return $instance;
}
@@ -620,16 +618,16 @@ class WP_Widget_Text extends WP_Widget {
*/
public function form( $instance ) {
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'text' => '' ) );
- $title = strip_tags($instance['title']);
- $text = esc_textarea($instance['text']);
-?>
+ $filter = isset( $instance['filter'] ) ? $instance['filter'] : 0;
+ $title = sanitize_text_field( $instance['title'] );
+ ?>
-
+
- />
+ />
'') );
- $title = esc_attr( $instance['title'] );
+ $title = sanitize_text_field( $instance['title'] );
$count = isset($instance['count']) ? (bool) $instance['count'] :false;
$hierarchical = isset( $instance['hierarchical'] ) ? (bool) $instance['hierarchical'] : false;
$dropdown = isset( $instance['dropdown'] ) ? (bool) $instance['dropdown'] : false;
?>
-
+
/>
@@ -879,7 +877,7 @@ class WP_Widget_Recent_Posts extends WP_Widget {
*/
public function update( $new_instance, $old_instance ) {
$instance = $old_instance;
- $instance['title'] = strip_tags($new_instance['title']);
+ $instance['title'] = santize_text_field( $new_instance['title'] );
$instance['number'] = (int) $new_instance['number'];
$instance['show_date'] = isset( $new_instance['show_date'] ) ? (bool) $new_instance['show_date'] : false;
$this->flush_widget_cache();
@@ -1056,7 +1054,7 @@ class WP_Widget_Recent_Comments extends WP_Widget {
*/
public function update( $new_instance, $old_instance ) {
$instance = $old_instance;
- $instance['title'] = strip_tags($new_instance['title']);
+ $instance['title'] = sanitize_text_field( $new_instance['title'] );
$instance['number'] = absint( $new_instance['number'] );
$this->flush_widget_cache();
@@ -1071,11 +1069,11 @@ class WP_Widget_Recent_Comments extends WP_Widget {
* @param array $instance
*/
public function form( $instance ) {
- $title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
+ $title = isset( $instance['title'] ) ? $instance['title'] : '';
$number = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5;
?>
-
+
@@ -1123,8 +1121,8 @@ class WP_Widget_RSS extends WP_Widget {
if ( ! is_wp_error($rss) ) {
$desc = esc_attr(strip_tags(@html_entity_decode($rss->get_description(), ENT_QUOTES, get_option('blog_charset'))));
if ( empty($title) )
- $title = esc_html(strip_tags($rss->get_title()));
- $link = esc_url(strip_tags($rss->get_permalink()));
+ $title = strip_tags( $rss->get_title() );
+ $link = strip_tags( $rss->get_permalink() );
while ( stristr($link, 'http') != $link )
$link = substr($link, 1);
}
@@ -1135,10 +1133,10 @@ class WP_Widget_RSS extends WP_Widget {
/** This filter is documented in wp-includes/default-widgets.php */
$title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
- $url = esc_url(strip_tags($url));
- $icon = includes_url('images/rss.png');
+ $url = strip_tags( $url );
+ $icon = includes_url( 'images/rss.png' );
if ( $title )
- $title = " ";
+ $title = ' ';
echo $args['before_widget'];
if ( $title ) {
@@ -1291,9 +1289,8 @@ function wp_widget_rss_form( $args, $inputs = null ) {
$default_inputs = array( 'url' => true, 'title' => true, 'items' => true, 'show_summary' => true, 'show_author' => true, 'show_date' => true );
$inputs = wp_parse_args( $inputs, $default_inputs );
- $args['number'] = esc_attr( $args['number'] );
- $args['title'] = isset( $args['title'] ) ? esc_attr( $args['title'] ) : '';
- $args['url'] = isset( $args['url'] ) ? esc_url( $args['url'] ) : '';
+ $args['title'] = isset( $args['title'] ) ? $args['title'] : '';
+ $args['url'] = isset( $args['url'] ) ? $args['url'] : '';
$args['items'] = isset( $args['items'] ) ? (int) $args['items'] : 0;
if ( $args['items'] < 1 || 20 < $args['items'] ) {
@@ -1308,38 +1305,39 @@ function wp_widget_rss_form( $args, $inputs = null ) {
echo '' . sprintf( __( 'RSS Error: %s' ), $args['error'] ) . '
';
}
+ $esc_number = esc_attr( $args['number'] );
if ( $inputs['url'] ) :
?>
-
-
+
+
-
-
+
+
-
-