From 7c8fbd2966fd0ad5c984224e88b874aaafe1e4ad Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Tue, 19 Sep 2017 10:21:48 +0000 Subject: [PATCH] General: Add missing URL-encoding and add extra hardening to plugin and template names when they're displayed in the admin area. Merges [41412] to the 4.7 branch See #13377 Built from https://develop.svn.wordpress.org/branches/4.7@41413 git-svn-id: http://core.svn.wordpress.org/branches/4.7@41246 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../includes/class-wp-plugins-list-table.php | 14 +++++++------- wp-admin/includes/template.php | 2 +- wp-admin/plugin-editor.php | 18 +++++++++--------- wp-admin/plugins.php | 18 +++++++++--------- wp-admin/theme-editor.php | 14 ++++++++------ wp-includes/version.php | 2 +- 6 files changed, 35 insertions(+), 33 deletions(-) diff --git a/wp-admin/includes/class-wp-plugins-list-table.php b/wp-admin/includes/class-wp-plugins-list-table.php index 136fbd4c73..93e590b1b9 100644 --- a/wp-admin/includes/class-wp-plugins-list-table.php +++ b/wp-admin/includes/class-wp-plugins-list-table.php @@ -601,16 +601,16 @@ class WP_Plugins_List_Table extends WP_List_Table { if ( $is_active ) { if ( current_user_can( 'manage_network_plugins' ) ) { /* translators: %s: plugin name */ - $actions['deactivate'] = '' . __( 'Network Deactivate' ) . ''; + $actions['deactivate'] = '' . __( 'Network Deactivate' ) . ''; } } else { if ( current_user_can( 'manage_network_plugins' ) ) { /* translators: %s: plugin name */ - $actions['activate'] = '' . __( 'Network Activate' ) . ''; + $actions['activate'] = '' . __( 'Network Activate' ) . ''; } if ( current_user_can( 'delete_plugins' ) && ! is_plugin_active( $plugin_file ) ) { /* translators: %s: plugin name */ - $actions['delete'] = '' . __( 'Delete' ) . ''; + $actions['delete'] = '' . __( 'Delete' ) . ''; } } } else { @@ -624,14 +624,14 @@ class WP_Plugins_List_Table extends WP_List_Table { ); } elseif ( $is_active ) { /* translators: %s: plugin name */ - $actions['deactivate'] = '' . __( 'Deactivate' ) . ''; + $actions['deactivate'] = '' . __( 'Deactivate' ) . ''; } else { /* translators: %s: plugin name */ - $actions['activate'] = '' . __( 'Activate' ) . ''; + $actions['activate'] = '' . __( 'Activate' ) . ''; if ( ! is_multisite() && current_user_can( 'delete_plugins' ) ) { /* translators: %s: plugin name */ - $actions['delete'] = '' . __( 'Delete' ) . ''; + $actions['delete'] = '' . __( 'Delete' ) . ''; } } // end if $is_active @@ -639,7 +639,7 @@ class WP_Plugins_List_Table extends WP_List_Table { if ( ( ! is_multisite() || $screen->in_admin( 'network' ) ) && current_user_can( 'edit_plugins' ) && is_writable( WP_PLUGIN_DIR . '/' . $plugin_file ) ) { /* translators: %s: plugin name */ - $actions['edit'] = '' . __( 'Edit' ) . ''; + $actions['edit'] = '' . __( 'Edit' ) . ''; } } // end if $context diff --git a/wp-admin/includes/template.php b/wp-admin/includes/template.php index edf9a8641c..6eae838582 100644 --- a/wp-admin/includes/template.php +++ b/wp-admin/includes/template.php @@ -772,7 +772,7 @@ function page_template_dropdown( $default = '', $post_type = 'page' ) { ksort( $templates ); foreach ( array_keys( $templates ) as $template ) { $selected = selected( $default, $templates[ $template ], false ); - echo "\n\t"; + echo "\n\t"; } } diff --git a/wp-admin/plugin-editor.php b/wp-admin/plugin-editor.php index ab8968db87..327c4c3d7b 100644 --- a/wp-admin/plugin-editor.php +++ b/wp-admin/plugin-editor.php @@ -37,11 +37,11 @@ if ( empty( $plugins ) ) { $file = ''; $plugin = ''; if ( isset( $_REQUEST['file'] ) ) { - $file = sanitize_text_field( $_REQUEST['file'] ); + $file = wp_unslash( $_REQUEST['file'] ); } if ( isset( $_REQUEST['plugin'] ) ) { - $plugin = sanitize_text_field( $_REQUEST['plugin'] ); + $plugin = wp_unslash( $_REQUEST['plugin'] ); } if ( empty( $plugin ) ) { @@ -107,10 +107,10 @@ if ( isset( $_REQUEST['action'] ) && 'update' === $_REQUEST['action'] ) { } if ( ( ! empty( $_GET['networkwide'] ) && ! is_plugin_active_for_network( $file ) ) || ! is_plugin_active( $file ) ) { - activate_plugin( $plugin, "plugin-editor.php?file=$file&phperror=1", ! empty( $_GET['networkwide'] ) ); + activate_plugin( $plugin, "plugin-editor.php?file=" . urlencode( $file ) . "&phperror=1", ! empty( $_GET['networkwide'] ) ); } // we'll override this later if the plugin can be included without fatal error - wp_redirect( self_admin_url("plugin-editor.php?file=$file&plugin=$plugin&a=te&scrollto=$scrollto") ); + wp_redirect( self_admin_url( 'plugin-editor.php?file=' . urlencode( $file ) . '&plugin=' . urlencode( $plugin ) . "&a=te&scrollto=$scrollto" ) ); exit; } @@ -203,18 +203,18 @@ if ( isset( $_REQUEST['action'] ) && 'update' === $_REQUEST['action'] ) { if ( is_plugin_active( $plugin ) ) { if ( is_writeable( $real_file ) ) { /* translators: %s: plugin file name */ - echo sprintf( __( 'Editing %s (active)' ), '' . $file . '' ); + echo sprintf( __( 'Editing %s (active)' ), '' . esc_html( $file ) . '' ); } else { /* translators: %s: plugin file name */ - echo sprintf( __( 'Browsing %s (active)' ), '' . $file . '' ); + echo sprintf( __( 'Browsing %s (active)' ), '' . esc_html( $file ) . '' ); } } else { if ( is_writeable( $real_file ) ) { /* translators: %s: plugin file name */ - echo sprintf( __( 'Editing %s (inactive)' ), '' . $file . '' ); + echo sprintf( __( 'Editing %s (inactive)' ), '' . esc_html( $file ) . '' ); } else { /* translators: %s: plugin file name */ - echo sprintf( __( 'Browsing %s (inactive)' ), '' . $file . '' ); + echo sprintf( __( 'Browsing %s (inactive)' ), '' . esc_html( $file ) . '' ); } } ?> @@ -259,7 +259,7 @@ foreach ( $plugin_files as $plugin_file ) : continue; } ?> - > + > diff --git a/wp-admin/plugins.php b/wp-admin/plugins.php index 8fca84adf1..28e9f0737e 100644 --- a/wp-admin/plugins.php +++ b/wp-admin/plugins.php @@ -17,7 +17,7 @@ $pagenum = $wp_list_table->get_pagenum(); $action = $wp_list_table->current_action(); -$plugin = isset($_REQUEST['plugin']) ? $_REQUEST['plugin'] : ''; +$plugin = isset($_REQUEST['plugin']) ? wp_unslash( $_REQUEST['plugin'] ) : ''; $s = isset($_REQUEST['s']) ? urlencode( wp_unslash( $_REQUEST['s'] ) ) : ''; // Clean up request URI from temporary args for screen options/paging uri's to work as expected. @@ -39,10 +39,10 @@ if ( $action ) { check_admin_referer('activate-plugin_' . $plugin); - $result = activate_plugin($plugin, self_admin_url('plugins.php?error=true&plugin=' . $plugin), is_network_admin() ); + $result = activate_plugin($plugin, self_admin_url('plugins.php?error=true&plugin=' . urlencode( $plugin ) ), is_network_admin() ); if ( is_wp_error( $result ) ) { if ( 'unexpected_output' == $result->get_error_code() ) { - $redirect = self_admin_url('plugins.php?error=true&charsout=' . strlen($result->get_error_data()) . '&plugin=' . $plugin . "&plugin_status=$status&paged=$page&s=$s"); + $redirect = self_admin_url('plugins.php?error=true&charsout=' . strlen($result->get_error_data()) . '&plugin=' . urlencode( $plugin ) . "&plugin_status=$status&paged=$page&s=$s"); wp_redirect(add_query_arg('_error_nonce', wp_create_nonce('plugin-activation-error_' . $plugin), $redirect)); exit; } else { @@ -73,7 +73,7 @@ if ( $action ) { check_admin_referer('bulk-plugins'); - $plugins = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array(); + $plugins = isset( $_POST['checked'] ) ? (array) wp_unslash( $_POST['checked'] ) : array(); if ( is_network_admin() ) { foreach ( $plugins as $i => $plugin ) { @@ -122,9 +122,9 @@ if ( $action ) { check_admin_referer( 'bulk-plugins' ); if ( isset( $_GET['plugins'] ) ) - $plugins = explode( ',', $_GET['plugins'] ); + $plugins = explode( ',', wp_unslash( $_GET['plugins'] ) ); elseif ( isset( $_POST['checked'] ) ) - $plugins = (array) $_POST['checked']; + $plugins = (array) wp_unslash( $_POST['checked'] ); else $plugins = array(); @@ -197,7 +197,7 @@ if ( $action ) { check_admin_referer('bulk-plugins'); - $plugins = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array(); + $plugins = isset( $_POST['checked'] ) ? (array) wp_unslash( $_POST['checked'] ) : array(); // Do not deactivate plugins which are already deactivated. if ( is_network_admin() ) { $plugins = array_filter( $plugins, 'is_plugin_active_for_network' ); @@ -234,7 +234,7 @@ if ( $action ) { check_admin_referer('bulk-plugins'); //$_POST = from the plugin form; $_GET = from the FTP details screen. - $plugins = isset( $_REQUEST['checked'] ) ? (array) $_REQUEST['checked'] : array(); + $plugins = isset( $_REQUEST['checked'] ) ? (array) wp_unslash( $_REQUEST['checked'] ) : array(); if ( empty( $plugins ) ) { wp_redirect( self_admin_url("plugins.php?plugin_status=$status&paged=$page&s=$s") ); exit; @@ -368,7 +368,7 @@ if ( $action ) { default: if ( isset( $_POST['checked'] ) ) { check_admin_referer('bulk-plugins'); - $plugins = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array(); + $plugins = isset( $_POST['checked'] ) ? (array) wp_unslash( $_POST['checked'] ) : array(); $sendback = wp_get_referer(); /** This action is documented in wp-admin/edit-comments.php */ diff --git a/wp-admin/theme-editor.php b/wp-admin/theme-editor.php index 03b91944ea..6e37870792 100644 --- a/wp-admin/theme-editor.php +++ b/wp-admin/theme-editor.php @@ -99,7 +99,7 @@ if ( empty( $file ) ) { $relative_file = 'style.css'; $file = $allowed_files['style.css']; } else { - $relative_file = $file; + $relative_file = wp_unslash( $file ); $file = $theme->get_stylesheet_directory() . '/' . $relative_file; } @@ -156,10 +156,12 @@ default:

(' . $file_show . ')'; +$description = esc_html( $file_description ); +if ( $file_description != $file_show ) { + $description .= ' (' . esc_html( $file_show ) . ')'; +} ?>

@@ -230,9 +232,9 @@ if ( $allowed_files ) : echo "\t
    \n"; } - $file_description = get_file_description( $filename ); + $file_description = esc_html( get_file_description( $filename ) ); if ( $filename !== basename( $absolute_filename ) || $file_description !== $filename ) { - $file_description .= '
    (' . $filename . ')'; + $file_description .= '
    (' . esc_html( $filename ) . ')'; } if ( $absolute_filename === $file ) { diff --git a/wp-includes/version.php b/wp-includes/version.php index 2ae7c58eb4..e650fe2d41 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.7.6-alpha-41401'; +$wp_version = '4.7.6-alpha-41413'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.