Make WordPress Core

Changeset 41412


Ignore:
Timestamp:
09/19/2017 10:15:56 AM (9 years ago)
Author:
johnbillion
Message:

General: Add missing URL-encoding and add extra hardening to plugin and template names when they're displayed in the admin area.

Merges [41399], with additions, to the 4.8 branch.

See #13377

Location:
branches/4.8/src/wp-admin
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/4.8/src/wp-admin/includes/class-wp-plugins-list-table.php

    r39063 r41412  
    602602                                        if ( current_user_can( 'manage_network_plugins' ) ) {
    603603                                                /* translators: %s: plugin name */
    604                                                 $actions['deactivate'] = '<a href="' . wp_nonce_url( 'plugins.php?action=deactivate&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'deactivate-plugin_' . $plugin_file ) . '" aria-label="' . esc_attr( sprintf( _x( 'Network Deactivate %s', 'plugin' ), $plugin_data['Name'] ) ) . '">' . __( 'Network Deactivate' ) . '</a>';
     604                                                $actions['deactivate'] = '<a href="' . wp_nonce_url( 'plugins.php?action=deactivate&amp;plugin=' . urlencode( $plugin_file ) . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'deactivate-plugin_' . $plugin_file ) . '" aria-label="' . esc_attr( sprintf( _x( 'Network Deactivate %s', 'plugin' ), $plugin_data['Name'] ) ) . '">' . __( 'Network Deactivate' ) . '</a>';
    605605                                                }
    606606                                } else {
    607607                                        if ( current_user_can( 'manage_network_plugins' ) ) {
    608608                                                /* translators: %s: plugin name */
    609                                                 $actions['activate'] = '<a href="' . wp_nonce_url( 'plugins.php?action=activate&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'activate-plugin_' . $plugin_file ) . '" class="edit" aria-label="' . esc_attr( sprintf( _x( 'Network Activate %s', 'plugin' ), $plugin_data['Name'] ) ) . '">' . __( 'Network Activate' ) . '</a>';
     609                                                $actions['activate'] = '<a href="' . wp_nonce_url( 'plugins.php?action=activate&amp;plugin=' . urlencode( $plugin_file ) . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'activate-plugin_' . $plugin_file ) . '" class="edit" aria-label="' . esc_attr( sprintf( _x( 'Network Activate %s', 'plugin' ), $plugin_data['Name'] ) ) . '">' . __( 'Network Activate' ) . '</a>';
    610610                                        }
    611611                                        if ( current_user_can( 'delete_plugins' ) && ! is_plugin_active( $plugin_file ) ) {
    612612                                                /* translators: %s: plugin name */
    613                                                 $actions['delete'] = '<a href="' . wp_nonce_url( 'plugins.php?action=delete-selected&amp;checked[]=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'bulk-plugins' ) . '" class="delete" aria-label="' . esc_attr( sprintf( _x( 'Delete %s', 'plugin' ), $plugin_data['Name'] ) ) . '">' . __( 'Delete' ) . '</a>';
     613                                                $actions['delete'] = '<a href="' . wp_nonce_url( 'plugins.php?action=delete-selected&amp;checked[]=' . urlencode( $plugin_file ) . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'bulk-plugins' ) . '" class="delete" aria-label="' . esc_attr( sprintf( _x( 'Delete %s', 'plugin' ), $plugin_data['Name'] ) ) . '">' . __( 'Delete' ) . '</a>';
    614614                                        }
    615615                                }
    … …  
    625625                                } elseif ( $is_active ) {
    626626                                        /* translators: %s: plugin name */
    627                                         $actions['deactivate'] = '<a href="' . wp_nonce_url( 'plugins.php?action=deactivate&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'deactivate-plugin_' . $plugin_file ) . '" aria-label="' . esc_attr( sprintf( _x( 'Deactivate %s', 'plugin' ), $plugin_data['Name'] ) ) . '">' . __( 'Deactivate' ) . '</a>';
     627                                        $actions['deactivate'] = '<a href="' . wp_nonce_url( 'plugins.php?action=deactivate&amp;plugin=' . urlencode( $plugin_file ) . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'deactivate-plugin_' . $plugin_file ) . '" aria-label="' . esc_attr( sprintf( _x( 'Deactivate %s', 'plugin' ), $plugin_data['Name'] ) ) . '">' . __( 'Deactivate' ) . '</a>';
    628628                                } else {
    629629                                        /* translators: %s: plugin name */
    630                                         $actions['activate'] = '<a href="' . wp_nonce_url( 'plugins.php?action=activate&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'activate-plugin_' . $plugin_file ) . '" class="edit" aria-label="' . esc_attr( sprintf( _x( 'Activate %s', 'plugin' ), $plugin_data['Name'] ) ) . '">' . __( 'Activate' ) . '</a>';
     630                                        $actions['activate'] = '<a href="' . wp_nonce_url( 'plugins.php?action=activate&amp;plugin=' . urlencode( $plugin_file ) . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'activate-plugin_' . $plugin_file ) . '" class="edit" aria-label="' . esc_attr( sprintf( _x( 'Activate %s', 'plugin' ), $plugin_data['Name'] ) ) . '">' . __( 'Activate' ) . '</a>';
    631631
    632632                                        if ( ! is_multisite() && current_user_can( 'delete_plugins' ) ) {
    633633                                                /* translators: %s: plugin name */
    634                                                 $actions['delete'] = '<a href="' . wp_nonce_url( 'plugins.php?action=delete-selected&amp;checked[]=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'bulk-plugins' ) . '" class="delete" aria-label="' . esc_attr( sprintf( _x( 'Delete %s', 'plugin' ), $plugin_data['Name'] ) ) . '">' . __( 'Delete' ) . '</a>';
     634                                                $actions['delete'] = '<a href="' . wp_nonce_url( 'plugins.php?action=delete-selected&amp;checked[]=' . urlencode( $plugin_file ) . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'bulk-plugins' ) . '" class="delete" aria-label="' . esc_attr( sprintf( _x( 'Delete %s', 'plugin' ), $plugin_data['Name'] ) ) . '">' . __( 'Delete' ) . '</a>';
    635635                                        }
    636636                                } // end if $is_active
    … …  
    640640                        if ( ( ! is_multisite() || $screen->in_admin( 'network' ) ) && current_user_can( 'edit_plugins' ) && is_writable( WP_PLUGIN_DIR . '/' . $plugin_file ) ) {
    641641                                /* translators: %s: plugin name */
    642                                 $actions['edit'] = '<a href="plugin-editor.php?file=' . $plugin_file . '" class="edit" aria-label="' . esc_attr( sprintf( __( 'Edit %s' ), $plugin_data['Name'] ) ) . '">' . __( 'Edit' ) . '</a>';
     642                                $actions['edit'] = '<a href="plugin-editor.php?file=' . urlencode( $plugin_file ) . '" class="edit" aria-label="' . esc_attr( sprintf( __( 'Edit %s' ), $plugin_data['Name'] ) ) . '">' . __( 'Edit' ) . '</a>';
    643643                        }
    644644                } // end if $context
  • branches/4.8/src/wp-admin/includes/template.php

    r40823 r41412  
    773773        foreach ( array_keys( $templates ) as $template ) {
    774774                $selected = selected( $default, $templates[ $template ], false );
    775                 echo "\n\t<option value='" . $templates[ $template ] . "' $selected>$template</option>";
     775                echo "\n\t<option value='" . esc_attr( $templates[ $template ] ) . "' $selected>" . esc_html( $template ) . "</option>";
    776776        }
    777777}
  • branches/4.8/src/wp-admin/plugin-editor.php

    r38745 r41412  
    3838$plugin = '';
    3939if ( isset( $_REQUEST['file'] ) ) {
    40         $file = sanitize_text_field( $_REQUEST['file'] );
     40        $file = wp_unslash( $_REQUEST['file'] );
    4141}
    4242
    4343if ( isset( $_REQUEST['plugin'] ) ) {
    44         $plugin = sanitize_text_field( $_REQUEST['plugin'] );
     44        $plugin = wp_unslash( $_REQUEST['plugin'] );
    4545}
    4646
    … …  
    108108
    109109                if ( ( ! empty( $_GET['networkwide'] ) && ! is_plugin_active_for_network( $file ) ) || ! is_plugin_active( $file ) ) {
    110                         activate_plugin( $plugin, "plugin-editor.php?file=$file&phperror=1", ! empty( $_GET['networkwide'] ) );
     110                        activate_plugin( $plugin, "plugin-editor.php?file=" . urlencode( $file ) . "&phperror=1", ! empty( $_GET['networkwide'] ) );
    111111                } // we'll override this later if the plugin can be included without fatal error
    112112
    113                 wp_redirect( self_admin_url("plugin-editor.php?file=$file&plugin=$plugin&a=te&scrollto=$scrollto") );
     113                wp_redirect( self_admin_url( 'plugin-editor.php?file=' . urlencode( $file ) . '&plugin=' . urlencode( $plugin ) . "&a=te&scrollto=$scrollto" ) );
    114114                exit;
    115115        }
    … …  
    204204                if ( is_writeable( $real_file ) ) {
    205205                        /* translators: %s: plugin file name */
    206                         echo sprintf( __( 'Editing %s (active)' ), '<strong>' . $file . '</strong>' );
     206                        echo sprintf( __( 'Editing %s (active)' ), '<strong>' . esc_html( $file ) . '</strong>' );
    207207                } else {
    208208                        /* translators: %s: plugin file name */
    209                         echo sprintf( __( 'Browsing %s (active)' ), '<strong>' . $file . '</strong>' );
     209                        echo sprintf( __( 'Browsing %s (active)' ), '<strong>' . esc_html( $file ) . '</strong>' );
    210210                }
    211211        } else {
    212212                if ( is_writeable( $real_file ) ) {
    213213                        /* translators: %s: plugin file name */
    214                         echo sprintf( __( 'Editing %s (inactive)' ), '<strong>' . $file . '</strong>' );
     214                        echo sprintf( __( 'Editing %s (inactive)' ), '<strong>' . esc_html( $file ) . '</strong>' );
    215215                } else {
    216216                        /* translators: %s: plugin file name */
    217                         echo sprintf( __( 'Browsing %s (inactive)' ), '<strong>' . $file . '</strong>' );
     217                        echo sprintf( __( 'Browsing %s (inactive)' ), '<strong>' . esc_html( $file ) . '</strong>' );
    218218                }
    219219        }
    … …  
    260260        }
    261261?>
    262                 <li<?php echo $file == $plugin_file ? ' class="highlight"' : ''; ?>><a href="plugin-editor.php?file=<?php echo urlencode( $plugin_file ) ?>&amp;plugin=<?php echo urlencode( $plugin ) ?>"><?php echo $plugin_file ?></a></li>
     262                <li<?php echo $file == $plugin_file ? ' class="highlight"' : ''; ?>><a href="plugin-editor.php?file=<?php echo urlencode( $plugin_file ) ?>&amp;plugin=<?php echo urlencode( $plugin ) ?>"><?php echo esc_html( $plugin_file ); ?></a></li>
    263263<?php endforeach; ?>
    264264        </ul>
  • branches/4.8/src/wp-admin/plugins.php

    r40169 r41412  
    1818$action = $wp_list_table->current_action();
    1919
    20 $plugin = isset($_REQUEST['plugin']) ? $_REQUEST['plugin'] : '';
     20$plugin = isset($_REQUEST['plugin']) ? wp_unslash( $_REQUEST['plugin'] ) : '';
    2121$s = isset($_REQUEST['s']) ? urlencode( wp_unslash( $_REQUEST['s'] ) ) : '';
    2222
    … …  
    4040                        check_admin_referer('activate-plugin_' . $plugin);
    4141
    42                         $result = activate_plugin($plugin, self_admin_url('plugins.php?error=true&plugin=' . $plugin), is_network_admin() );
     42                        $result = activate_plugin($plugin, self_admin_url('plugins.php?error=true&plugin=' . urlencode( $plugin ) ), is_network_admin() );
    4343                        if ( is_wp_error( $result ) ) {
    4444                                if ( 'unexpected_output' == $result->get_error_code() ) {
    45                                         $redirect = self_admin_url('plugins.php?error=true&charsout=' . strlen($result->get_error_data()) . '&plugin=' . $plugin . "&plugin_status=$status&paged=$page&s=$s");
     45                                        $redirect = self_admin_url('plugins.php?error=true&charsout=' . strlen($result->get_error_data()) . '&plugin=' . urlencode( $plugin ) . "&plugin_status=$status&paged=$page&s=$s");
    4646                                        wp_redirect(add_query_arg('_error_nonce', wp_create_nonce('plugin-activation-error_' . $plugin), $redirect));
    4747                                        exit;
    … …  
    7474                        check_admin_referer('bulk-plugins');
    7575
    76                         $plugins = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
     76                        $plugins = isset( $_POST['checked'] ) ? (array) wp_unslash( $_POST['checked'] ) : array();
    7777
    7878                        if ( is_network_admin() ) {
    … …  
    123123
    124124                        if ( isset( $_GET['plugins'] ) )
    125                                 $plugins = explode( ',', $_GET['plugins'] );
     125                                $plugins = explode( ',', wp_unslash( $_GET['plugins'] ) );
    126126                        elseif ( isset( $_POST['checked'] ) )
    127                                 $plugins = (array) $_POST['checked'];
     127                                $plugins = (array) wp_unslash( $_POST['checked'] );
    128128                        else
    129129                                $plugins = array();
    … …  
    198198                        check_admin_referer('bulk-plugins');
    199199
    200                         $plugins = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
     200                        $plugins = isset( $_POST['checked'] ) ? (array) wp_unslash( $_POST['checked'] ) : array();
    201201                        // Do not deactivate plugins which are already deactivated.
    202202                        if ( is_network_admin() ) {
    … …  
    235235
    236236                        //$_POST = from the plugin form; $_GET = from the FTP details screen.
    237                         $plugins = isset( $_REQUEST['checked'] ) ? (array) $_REQUEST['checked'] : array();
     237                        $plugins = isset( $_REQUEST['checked'] ) ? (array) wp_unslash( $_REQUEST['checked'] ) : array();
    238238                        if ( empty( $plugins ) ) {
    239239                                wp_redirect( self_admin_url("plugins.php?plugin_status=$status&paged=$page&s=$s") );
    … …  
    369369                        if ( isset( $_POST['checked'] ) ) {
    370370                                check_admin_referer('bulk-plugins');
    371                                 $plugins = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
     371                                $plugins = isset( $_POST['checked'] ) ? (array) wp_unslash( $_POST['checked'] ) : array();
    372372                                $sendback = wp_get_referer();
    373373
  • branches/4.8/src/wp-admin/theme-editor.php

    r38722 r41412  
    100100        $file = $allowed_files['style.css'];
    101101} else {
    102         $relative_file = $file;
     102        $relative_file = wp_unslash( $file );
    103103        $file = $theme->get_stylesheet_directory() . '/' . $relative_file;
    104104}
    … …  
    157157<?php endif;
    158158
    159 $description = get_file_description( $relative_file );
     159$file_description = get_file_description( $relative_file );
    160160$file_show = array_search( $file, array_filter( $allowed_files ) );
    161 if ( $description != $file_show )
    162         $description .= ' <span>(' . $file_show . ')</span>';
     161$description = esc_html( $file_description );
     162if ( $file_description != $file_show ) {
     163        $description .= ' <span>(' . esc_html( $file_show ) . ')</span>';
     164}
    163165?>
    164166<div class="wrap">
    … …  
    231233                }
    232234
    233                 $file_description = get_file_description( $filename );
     235                $file_description = esc_html( get_file_description( $filename ) );
    234236                if ( $filename !== basename( $absolute_filename ) || $file_description !== $filename ) {
    235                         $file_description .= '<br /><span class="nonessential">(' . $filename . ')</span>';
     237                        $file_description .= '<br /><span class="nonessential">(' . esc_html( $filename ) . ')</span>';
    236238                }
    237239
Note: See TracChangeset for help on using the changeset viewer.