WordPress.org

Make WordPress Core

Changeset 41444


Ignore:
Timestamp:
09/19/2017 01:19:20 PM (3 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 [41434] with changes to the 4.3 branch.

See #13377

Location:
branches/4.3
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/4.3

  • branches/4.3/src/wp-admin/includes/class-wp-plugins-list-table.php

    r33196 r41444  
    488488                    if ( current_user_can( 'manage_network_plugins' ) ) {
    489489                        /* translators: %s: plugin name */
    490                         $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( __( 'Network deactivate %s' ), $plugin_data['Name'] ) ) . '">' . __( 'Network Deactivate' ) . '</a>';
     490                        $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( __( 'Network deactivate %s' ), $plugin_data['Name'] ) ) . '">' . __( 'Network Deactivate' ) . '</a>';
    491491                        }
    492492                } else {
    493493                    if ( current_user_can( 'manage_network_plugins' ) ) {
    494494                        /* translators: %s: plugin name */
    495                         $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( __( 'Network Activate %s' ), $plugin_data['Name'] ) ) . '">' . __( 'Network Activate' ) . '</a>';
     495                        $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( __( 'Network Activate %s' ), $plugin_data['Name'] ) ) . '">' . __( 'Network Activate' ) . '</a>';
    496496                    }
    497497                    if ( current_user_can( 'delete_plugins' ) && ! is_plugin_active( $plugin_file ) ) {
    498498                        /* translators: %s: plugin name */
    499                         $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( __( 'Delete %s' ), $plugin_data['Name'] ) ) . '">' . __( 'Delete' ) . '</a>';
     499                        $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( __( 'Delete %s' ), $plugin_data['Name'] ) ) . '">' . __( 'Delete' ) . '</a>';
    500500                    }
    501501                }
     
    503503                if ( $is_active ) {
    504504                    /* translators: %s: plugin name */
    505                     $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( __( 'Deactivate %s' ), $plugin_data['Name'] ) ) . '">' . __( 'Deactivate' ) . '</a>';
     505                    $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( __( 'Deactivate %s' ), $plugin_data['Name'] ) ) . '">' . __( 'Deactivate' ) . '</a>';
    506506                } else {
    507507                    /* translators: %s: plugin name */
    508                     $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( __( 'Activate %s' ), $plugin_data['Name'] ) ) . '">' . __( 'Activate' ) . '</a>';
     508                    $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( __( 'Activate %s' ), $plugin_data['Name'] ) ) . '">' . __( 'Activate' ) . '</a>';
    509509
    510510                    if ( ! is_multisite() && current_user_can( 'delete_plugins' ) ) {
    511511                        /* translators: %s: plugin name */
    512                         $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( __( 'Delete %s' ), $plugin_data['Name'] ) ) . '">' . __( 'Delete' ) . '</a>';
     512                        $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( __( 'Delete %s' ), $plugin_data['Name'] ) ) . '">' . __( 'Delete' ) . '</a>';
    513513                    }
    514514                } // end if $is_active
     
    518518            if ( ( ! is_multisite() || $screen->in_admin( 'network' ) ) && current_user_can( 'edit_plugins' ) && is_writable( WP_PLUGIN_DIR . '/' . $plugin_file ) ) {
    519519                /* translators: %s: plugin name */
    520                 $actions['edit'] = '<a href="plugin-editor.php?file=' . $plugin_file . '" class="edit" aria-label="' . esc_attr( sprintf( __( 'Edit %s' ), $plugin_data['Name'] ) ) . '">' . __( 'Edit' ) . '</a>';
     520                $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>';
    521521            }
    522522        } // end if $context
  • branches/4.3/src/wp-admin/includes/template.php

    r34095 r41444  
    841841    foreach ( array_keys( $templates ) as $template ) {
    842842        $selected = selected( $default, $templates[ $template ], false );
    843         echo "\n\t<option value='" . $templates[ $template ] . "' $selected>$template</option>";
     843        echo "\n\t<option value='" . esc_attr( $templates[ $template ] ) . "' $selected>" . esc_html( $template ) . "</option>";
    844844    }
    845845}
  • branches/4.3/src/wp-admin/plugin-editor.php

    r32974 r41444  
    9494
    9595        if ( ( ! empty( $_GET['networkwide'] ) && ! is_plugin_active_for_network($file) ) || ! is_plugin_active($file) )
    96             activate_plugin($file, "plugin-editor.php?file=$file&phperror=1", ! empty( $_GET['networkwide'] ) ); // we'll override this later if the plugin can be included without fatal error
    97 
    98         wp_redirect( self_admin_url("plugin-editor.php?file=$file&a=te&scrollto=$scrollto") );
     96            activate_plugin($file, "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
     97
     98        wp_redirect( self_admin_url("plugin-editor.php?file=" . urlencode( $file ) . "&a=te&scrollto=$scrollto") );
    9999        exit;
    100100    }
     
    182182    if ( is_plugin_active($plugin) ) {
    183183        if ( is_writeable($real_file) )
    184             echo sprintf(__('Editing <strong>%s</strong> (active)'), $file);
     184            echo sprintf(__('Editing <strong>%s</strong> (active)'), esc_html( $file ) );
    185185        else
    186             echo sprintf(__('Browsing <strong>%s</strong> (active)'), $file);
     186            echo sprintf(__('Browsing <strong>%s</strong> (active)'), esc_html( $file ) );
    187187    } else {
    188188        if ( is_writeable($real_file) )
    189             echo sprintf(__('Editing <strong>%s</strong> (inactive)'), $file);
     189            echo sprintf(__('Editing <strong>%s</strong> (inactive)'), esc_html( $file ) );
    190190        else
    191             echo sprintf(__('Browsing <strong>%s</strong> (inactive)'), $file);
     191            echo sprintf(__('Browsing <strong>%s</strong> (inactive)'), esc_html( $file ) );
    192192    }
    193193    ?></big>
     
    233233    }
    234234?>
    235         <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>
     235        <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>
    236236<?php endforeach; ?>
    237237    </ul>
  • branches/4.3/src/wp-admin/plugins.php

    r40174 r41444  
    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($_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;
     
    7070            check_admin_referer('bulk-plugins');
    7171
    72             $plugins = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
     72            $plugins = isset( $_POST['checked'] ) ? (array) wp_unslash( $_POST['checked'] ) : array();
    7373
    7474            if ( is_network_admin() ) {
     
    110110
    111111            if ( isset( $_GET['plugins'] ) )
    112                 $plugins = explode( ',', $_GET['plugins'] );
     112                $plugins = explode( ',', wp_unslash( $_GET['plugins'] ) );
    113113            elseif ( isset( $_POST['checked'] ) )
    114                 $plugins = (array) $_POST['checked'];
     114                $plugins = (array) wp_unslash( $_POST['checked'] );
    115115            else
    116116                $plugins = array();
     
    187187            check_admin_referer('bulk-plugins');
    188188
    189             $plugins = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
     189            $plugins = isset( $_POST['checked'] ) ? (array) wp_unslash( $_POST['checked'] ) : array();
    190190            // Do not deactivate plugins which are already deactivated.
    191191            if ( is_network_admin() ) {
     
    220220
    221221            //$_POST = from the plugin form; $_GET = from the FTP details screen.
    222             $plugins = isset( $_REQUEST['checked'] ) ? (array) $_REQUEST['checked'] : array();
     222            $plugins = isset( $_REQUEST['checked'] ) ? (array) wp_unslash( $_REQUEST['checked'] ) : array();
    223223            if ( empty( $plugins ) ) {
    224224                wp_redirect( self_admin_url("plugins.php?plugin_status=$status&paged=$page&s=$s") );
  • branches/4.3/src/wp-admin/theme-editor.php

    r32974 r41444  
    6969    $file = $allowed_files['style.css'];
    7070} else {
    71     $relative_file = $file;
     71    $relative_file = wp_unslash( $file );
    7272    $file = $theme->get_stylesheet_directory() . '/' . $relative_file;
    7373}
     
    126126<?php endif;
    127127
    128 $description = get_file_description( $file );
     128$file_description = get_file_description( $relative_file );
    129129$file_show = array_search( $file, array_filter( $allowed_files ) );
    130 if ( $description != $file_show )
    131     $description .= ' <span>(' . $file_show . ')</span>';
     130$description = esc_html( $file_description );
     131if ( $file_description != $file_show ) {
     132    $description .= ' <span>(' . esc_html( $file_show ) . ')</span>';
     133}
    132134?>
    133135<div class="wrap">
     
    178180            echo "\t</ul>\n\t<h3>" . _x( 'Styles', 'Theme stylesheets in theme editor' ) . "</h3>\n\t<ul>\n";
    179181
    180         $file_description = get_file_description( $absolute_filename );
     182        $file_description = esc_html( get_file_description( $filename ) );
    181183        if ( $file_description != basename( $filename ) )
    182             $file_description .= '<br /><span class="nonessential">(' . $filename . ')</span>';
     184            $file_description .= '<br /><span class="nonessential">(' . esc_html( $filename ) . ')</span>';
    183185
    184186        if ( $absolute_filename == $file )
Note: See TracChangeset for help on using the changeset viewer.