Make WordPress Core


Ignore:
Timestamp:
09/19/2017 10:10:35 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.

Props kawauso, Mte90 for initial patches

Fixes #13377

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/plugin-editor.php

    r41376 r41399  
    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        }
    … …  
    243243                if ( is_writeable( $real_file ) ) {
    244244                        /* translators: %s: plugin file name */
    245                         echo sprintf( __( 'Editing %s (active)' ), '<strong>' . $file . '</strong>' );
     245                        echo sprintf( __( 'Editing %s (active)' ), '<strong>' . esc_html( $file ) . '</strong>' );
    246246                } else {
    247247                        /* translators: %s: plugin file name */
    248                         echo sprintf( __( 'Browsing %s (active)' ), '<strong>' . $file . '</strong>' );
     248                        echo sprintf( __( 'Browsing %s (active)' ), '<strong>' . esc_html( $file ) . '</strong>' );
    249249                }
    250250        } else {
    251251                if ( is_writeable( $real_file ) ) {
    252252                        /* translators: %s: plugin file name */
    253                         echo sprintf( __( 'Editing %s (inactive)' ), '<strong>' . $file . '</strong>' );
     253                        echo sprintf( __( 'Editing %s (inactive)' ), '<strong>' . esc_html( $file ) . '</strong>' );
    254254                } else {
    255255                        /* translators: %s: plugin file name */
    256                         echo sprintf( __( 'Browsing %s (inactive)' ), '<strong>' . $file . '</strong>' );
     256                        echo sprintf( __( 'Browsing %s (inactive)' ), '<strong>' . esc_html( $file ) . '</strong>' );
    257257                }
    258258        }
    … …  
    299299        }
    300300?>
    301                 <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>
     301                <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>
    302302<?php endforeach; ?>
    303303        </ul>
Note: See TracChangeset for help on using the changeset viewer.