Changeset 3411413
- Timestamp:
- 12/04/2025 09:03:53 PM (9 days ago)
- Location:
- enable-svg-webp-ico-upload/trunk
- Files:
-
- 5 edited
-
README.txt (modified) (2 diffs)
-
includes/BaseController.php (modified) (1 diff)
-
includes/class-ico.php (modified) (2 diffs)
-
includes/class-itc.php (modified) (1 diff)
-
itc-svg-upload.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
enable-svg-webp-ico-upload/trunk/README.txt
r3396267 r3411413 4 4 Tags: SVG, WebP, ico, image, Serve images 5 5 Requires at least: 4.7 6 Tested up to: 6. 87 Stable tag: 1.1. 36 Tested up to: 6.9 7 Stable tag: 1.1.4 8 8 Requires PHP: 7.0 9 9 License: GPLv2 or later … … 49 49 50 50 == Changelog == 51 52 = 1.1.4 = 53 * Security fixes 51 54 52 55 = 1.1.3 = -
enable-svg-webp-ico-upload/trunk/includes/BaseController.php
r3396265 r3411413 11 11 'title' =>'Enable SVG, WebP & ICO Upload', 12 12 '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', 14 14 'settings' =>'itc_svg_upload_settings', 15 15 ); -
enable-svg-webp-ico-upload/trunk/includes/class-ico.php
r3396265 r3411413 2 2 class ITC_SVG_Upload_Ico { 3 3 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 */14 4 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 18 8 if ( $this->is_valid_ico( $file ) ) { 19 9 $types['ext'] = 'ico'; 20 10 $types['type'] = 'image/x-icon'; 21 11 } else { 22 // Invalidate file type if the file content is not valid 12 23 13 $types['ext'] = false; 24 14 $types['type'] = false; … … 26 16 } 27 17 18 28 19 return $types; 29 20 } 30 21 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 */38 22 public function ico_files( $mimes ) { 39 // Only allow the official MIME type for ICO files40 23 $mimes['ico'] = 'image/x-icon'; 41 42 24 return $mimes; 43 25 } 44 26 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 */51 27 private function is_valid_ico( $file ) { 52 // Read the first 4 bytes of the file to check the ICO signature53 28 $handle = @fopen( $file, 'rb' ); 54 29 if ( $handle === false ) { 55 30 return false; 56 31 } 57 58 32 $header = fread( $handle, 4 ); 59 33 fclose( $handle ); 60 61 // ICO files start with two null bytes followed by 0x01 and 0x0062 34 return $header === "\x00\x00\x01\x00"; 63 35 } 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 } 64 48 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 } 65 107 } -
enable-svg-webp-ico-upload/trunk/includes/class-itc.php
r3193062 r3411413 73 73 $this->loader->add_filter( 'wp_check_filetype_and_ext', $plugin_ico, 'upload_ico_files', 10, 4 ); 74 74 $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 75 77 } 76 78 } -
enable-svg-webp-ico-upload/trunk/itc-svg-upload.php
r3396265 r3411413 10 10 * Plugin URI: https://ideastocode.com/plugins/enable-svg-WebP-ico-upload/ 11 11 * Description: This plugin will enable you to upload SVG, WebP & ICO files 12 * Version: 1.1. 312 * Version: 1.1.4 13 13 * Author: ideasToCode 14 14 * Author URI: http://ideastocode.com/ … … 24 24 } 25 25 26 define( 'ITC_SVG_UPLOAD_VERSION', '1.1. 3' );26 define( 'ITC_SVG_UPLOAD_VERSION', '1.1.4' ); 27 27 if ( ! defined( 'ITC_SVG_UPLOAD_BASENAME' ) ) { 28 28 define( 'ITC_SVG_UPLOAD_BASENAME', plugin_basename( __FILE__ ) );
Note: See TracChangeset
for help on using the changeset viewer.