Make WordPress Core

Changeset 22521


Ignore:
Timestamp:
11/10/2012 05:36:37 AM (14 years ago)
Author:
nacin
Message:

Don't allow non-image uploads for custom headers and backgrounds. props kovshenin. fixes #22149.

Location:
trunk/wp-admin
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/custom-background.php

    r22503 r22521  
    356356                check_admin_referer('custom-background-upload', '_wpnonce-custom-background-upload');
    357357                $overrides = array('test_form' => false);
    358                 $file = wp_handle_upload($_FILES['import'], $overrides);
     358
     359                $uploaded_file = $_FILES['import'];
     360                $wp_filetype = wp_check_filetype_and_ext( $uploaded_file['tmp_name'], $uploaded_file['name'], false );
     361                if ( ! wp_match_mime_types( 'image', $wp_filetype['type'] ) )
     362                        wp_die( __( 'The uploaded file is not a valid image. Please try again.' ) );
     363
     364                $file = wp_handle_upload($uploaded_file, $overrides);
    359365
    360366                if ( isset($file['error']) )
  • trunk/wp-admin/custom-header.php

    r22520 r22521  
    769769        function step_2_manage_upload() {
    770770                $overrides = array('test_form' => false);
    771                 $file = wp_handle_upload($_FILES['import'], $overrides);
     771
     772                $uploaded_file = $_FILES['import'];
     773                $wp_filetype = wp_check_filetype_and_ext( $uploaded_file['tmp_name'], $uploaded_file['name'], false );
     774                if ( ! wp_match_mime_types( 'image', $wp_filetype['type'] ) )
     775                        wp_die( __( 'The uploaded file is not a valid image. Please try again.' ) );
     776
     777                $file = wp_handle_upload($uploaded_file, $overrides);
    772778
    773779                if ( isset($file['error']) )
  • trunk/wp-admin/includes/ajax-actions.php

    r22370 r22521  
    16101610        $post_data = isset( $_REQUEST['post_data'] ) ? $_REQUEST['post_data'] : array();
    16111611
     1612        // If the context is custom header or background, make sure the uploaded file is an image.
     1613        if ( isset( $post_data['context'] ) && in_array( $post_data['context'], array( 'custom-header', 'custom-background' ) ) ) {
     1614                $wp_filetype = wp_check_filetype_and_ext( $_FILES['async-upload']['tmp_name'], $_FILES['async-upload']['name'], false );
     1615                if ( ! wp_match_mime_types( 'image', $wp_filetype['type'] ) ) {
     1616                        wp_send_json_error( array(
     1617                                'message' => __( 'The uploaded file is not a valid image. Please try again.' ),
     1618                                'filename' => $_FILES['async-upload']['name'],
     1619                        ) );
     1620                }
     1621        }
     1622
    16121623        $attachment_id = media_handle_upload( 'async-upload', $post_id, $post_data );
    16131624
Note: See TracChangeset for help on using the changeset viewer.