Plugin Directory

Changeset 3411413


Ignore:
Timestamp:
12/04/2025 09:03:53 PM (9 days ago)
Author:
ideastocode
Message:

Tested up to 6.9

Location:
enable-svg-webp-ico-upload/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • enable-svg-webp-ico-upload/trunk/README.txt

    r3396267 r3411413  
    44Tags: SVG, WebP, ico, image, Serve images
    55Requires at least: 4.7
    6 Tested up to: 6.8
    7 Stable tag: 1.1.3
     6Tested up to: 6.9
     7Stable tag: 1.1.4
    88Requires PHP: 7.0
    99License: GPLv2 or later
     
    4949
    5050== Changelog ==
     51
     52= 1.1.4 =
     53* Security fixes
    5154
    5255= 1.1.3 =
  • enable-svg-webp-ico-upload/trunk/includes/BaseController.php

    r3396265 r3411413  
    1111                'title'     =>'Enable SVG, WebP & ICO Upload',
    1212                'slug'      =>'itc-svg-upload',
    13                 'version'   => ( defined( 'ITC_SVG_UPLOAD_VERSION' ) ) ? ITC_SVG_UPLOAD_VERSION: '1.1.3',
     13                'version'   => ( defined( 'ITC_SVG_UPLOAD_VERSION' ) ) ? ITC_SVG_UPLOAD_VERSION: '1.1.4',
    1414                'settings'  =>'itc_svg_upload_settings',
    1515            );
  • enable-svg-webp-ico-upload/trunk/includes/class-ico.php

    r3396265 r3411413  
    22class ITC_SVG_Upload_Ico {
    33
    4     /**
    5      * Adds ICO file type support during the file upload process.
    6      * Sanitizes and validates the filename and MIME type to prevent arbitrary file uploads.
    7      *
    8      * @param array $types Allowed types array containing 'ext' and 'type'.
    9      * @param string $file The full path to the file being uploaded.
    10      * @param string $filename The name of the file being uploaded.
    11      * @param array $mimes Allowed MIME types.
    12      * @return array Updated types array with 'ext' and 'type' for ICO files if valid.
    13      */
    144    public function upload_ico_files( $types, $file, $filename, $mimes ) {
    15         // Validate the filename for .ico extension
    16         if ( false !== strpos( strtolower( $filename ), '.ico' ) ) {
    17             // Check file MIME type and validate the ICO file structure
     5
     6        if ( $this->has_valid_ico_extension( $filename ) ) {
     7
    188            if ( $this->is_valid_ico( $file ) ) {
    199                $types['ext'] = 'ico';
    2010                $types['type'] = 'image/x-icon';
    2111            } else {
    22                 // Invalidate file type if the file content is not valid
     12
    2313                $types['ext'] = false;
    2414                $types['type'] = false;
     
    2616        }
    2717
     18
    2819        return $types;
    2920    }
    3021
    31     /**
    32      * Adds ICO MIME type support to WordPress file uploads.
    33      * Ensures the MIME type is correctly specified and secure.
    34      *
    35      * @param array $mimes Allowed MIME types.
    36      * @return array Updated MIME types with support for ICO files.
    37      */
    3822    public function ico_files( $mimes ) {
    39         // Only allow the official MIME type for ICO files
    4023        $mimes['ico'] = 'image/x-icon';
    41 
    4224        return $mimes;
    4325    }
    4426
    45     /**
    46      * Validates the ICO file by checking its content structure.
    47      *
    48      * @param string $file The path to the file being uploaded.
    49      * @return bool True if the file is a valid ICO, false otherwise.
    50      */
    5127    private function is_valid_ico( $file ) {
    52         // Read the first 4 bytes of the file to check the ICO signature
    5328        $handle = @fopen( $file, 'rb' );
    5429        if ( $handle === false ) {
    5530            return false;
    5631        }
    57 
    5832        $header = fread( $handle, 4 );
    5933        fclose( $handle );
    60 
    61         // ICO files start with two null bytes followed by 0x01 and 0x00
    6234        return $header === "\x00\x00\x01\x00";
    6335    }
     36   
     37    private function has_valid_ico_extension( $filename ) {
     38        $filename_lower = strtolower( $filename );
     39        $extension = '.ico';
     40        $extension_length = strlen( $extension );
     41       
     42        if ( strlen( $filename_lower ) < $extension_length ) {
     43            return false;
     44        }
     45       
     46        return substr_compare( $filename_lower, $extension, -$extension_length ) === 0;
     47    }
    6448
     49    public function sanitize_upload_filename_prefilter( $file ) {
     50        $filename = $file['name'];
     51        $pathinfo = pathinfo( $filename );
     52       
     53
     54        $is_possible_ico = false;
     55        if ( isset( $pathinfo['extension'] ) ) {
     56            $extension_lower = strtolower( $pathinfo['extension'] );
     57            $is_possible_ico = ( $extension_lower === 'ico' );
     58        }
     59       
     60
     61        if ( $is_possible_ico && isset( $pathinfo['filename'] ) ) {
     62
     63            if ( strpos( $pathinfo['filename'], '.' ) !== false ) {
     64
     65                $sanitized_filename = str_replace( '.', '', $pathinfo['filename'] );
     66                $file['name'] = $sanitized_filename . '.' . $pathinfo['extension'];
     67            }
     68        }
     69       
     70        return $file;
     71    }
     72
     73    public function generate_htaccess_protection() {
     74        $htaccess_content = "# Protect ICO files from execution - Generated by Enable SVG, WebP, and ICO Upload plugin\n";
     75        $htaccess_content .= "<FilesMatch \"\\.ico$\">\n";
     76        $htaccess_content .= "    SetHandler default-handler\n";
     77        $htaccess_content .= "    ForceType application/octet-stream\n";
     78        $htaccess_content .= "    Header set Content-Disposition attachment\n";
     79        $htaccess_content .= "</FilesMatch>\n";
     80       
     81        return $htaccess_content;
     82    }
     83
     84    public static function activate_plugin() {
     85        $instance = new self();
     86       
     87
     88        if ( function_exists( 'apache_get_modules' ) ) {
     89            $uploads_dir = wp_upload_dir();
     90            $htaccess_path = $uploads_dir['basedir'] . '/.htaccess';
     91           
     92
     93            if ( file_exists( $htaccess_path ) ) {
     94                $current_content = file_get_contents( $htaccess_path );
     95                $new_rules = $instance->generate_htaccess_protection();
     96               
     97 
     98                if ( strpos( $current_content, 'Protect ICO files from execution' ) === false ) {
     99                    file_put_contents( $htaccess_path, $new_rules . "\n" . $current_content, LOCK_EX );
     100                }
     101            } else {
     102
     103                file_put_contents( $htaccess_path, $instance->generate_htaccess_protection(), LOCK_EX );
     104            }
     105        }
     106    }
    65107}
  • enable-svg-webp-ico-upload/trunk/includes/class-itc.php

    r3193062 r3411413  
    7373            $this->loader->add_filter( 'wp_check_filetype_and_ext', $plugin_ico, 'upload_ico_files', 10, 4 );
    7474            $this->loader->add_filter( 'upload_mimes', $plugin_ico, 'ico_files' );
     75            $this->loader->add_filter( 'wp_handle_upload_prefilter', $plugin_ico, 'sanitize_upload_filename_prefilter' );           
     76
    7577        }
    7678    }
  • enable-svg-webp-ico-upload/trunk/itc-svg-upload.php

    r3396265 r3411413  
    1010 * Plugin URI:        https://ideastocode.com/plugins/enable-svg-WebP-ico-upload/
    1111 * Description:       This plugin will enable you to upload SVG, WebP & ICO files
    12  * Version:           1.1.3
     12 * Version:           1.1.4
    1313 * Author:            ideasToCode
    1414 * Author URI:        http://ideastocode.com/
     
    2424}
    2525
    26 define( 'ITC_SVG_UPLOAD_VERSION', '1.1.3' );
     26define( 'ITC_SVG_UPLOAD_VERSION', '1.1.4' );
    2727if ( ! defined( 'ITC_SVG_UPLOAD_BASENAME' ) ) {
    2828    define( 'ITC_SVG_UPLOAD_BASENAME', plugin_basename( __FILE__ ) );
Note: See TracChangeset for help on using the changeset viewer.