Changeset 2590623
- Timestamp:
- 08/30/2021 02:06:45 AM (4 years ago)
- Location:
- frontend-uploader/trunk
- Files:
-
- 1 added
- 5 edited
-
composer.json (added)
-
frontend-uploader.php (modified) (7 diffs)
-
lib/php/frontend-uploader-settings.php (modified) (2 diffs)
-
lib/php/functions.php (modified) (1 diff)
-
readme.md (modified) (1 diff)
-
readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
frontend-uploader/trunk/frontend-uploader.php
r2008848 r2590623 73 73 $this->html = new Html_Helper; 74 74 75 // Either use default settings if no setting set, or try to merge defaults with existing settings76 // Needed if new options were added in upgraded version of the plugin77 $this->settings = get_option( $this->settings_slug, $this->settings_defaults() );78 75 register_activation_hook( __FILE__, array( $this, 'activate_plugin' ) ); 79 76 } … … 83 80 */ 84 81 function action_init() { 82 // Try to gracefully fallback on default values, as well as merge any potentially new settings coming from an upgrade (: 83 $this->settings = array_merge( $this->settings_defaults(), (array) get_option( $this->settings_slug, [] ) ); 85 84 86 85 load_plugin_textdomain( 'frontend-uploader', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); … … 142 141 143 142 /** 144 * Add extra mime-types 145 * 146 * This is mostly legacy, and really should be deprecated or refactored due to unneccessary complexity 147 * 148 * @return [type] [description] 143 * Handle MIME-types: 144 * 145 * First we check what's in the plugin setting (if there's nothing we're falling back to Core list) 146 * If we're falling back to core value, make sure to remove HTML and JS files. 147 * Then we also explicitly try to remove any variant of PHP, just in case. 148 * 149 * After that we pass the value to the filter, 150 * so if somebody really wants to shoot in the foot they can do so. 151 * 152 * @return array the list of allowed for uploading mime types 149 153 */ 150 154 function _get_mime_types() { 151 $mime_types = wp_get_mime_types();152 $fu_mime_types = fu_get_mime_types();153 154 $ enabled = isset( $this->settings['enabled_files'] ) && is_array( $this->settings['enabled_files'] ) ? $this->settings['enabled_files'] : array();155 156 // $fu_mime_types holds extra mimes that are not allowed by WP157 foreach ( $fu_mime_types as $extension => $details ) { 158 // Skip if it's not in the settings159 if ( ! in_array( $extension, $enabled, true ) ) 160 continue;161 162 // Files have multiple mimes sometimes, we need to cover all of them163 foreach ( $details['mimes'] as $ext_mime ) {164 $mime_types[ $extension . '|' . $extension . sanitize_title_with_dashes( $ext_mime ) ] = $ext_mime;165 } 166 } 167 168 // Configuration filter: fu_allowed_mime_types should return array of allowed mime types (see readme)169 $mime_types = apply_filters( 'fu_allowed_mime_types', $mime_types );170 171 foreach ( $mime_types as $ext_key => $mime ) {172 // Check for php just in case173 if ( false !== strpos( $mime, 'php' ) )174 unset( $mime_types[$ext_key] );175 }155 // Use the fallback value but explicitly discard HTML and JS to prevent a possibility of XSS: 156 // If these types are enabled in the UI they'll end up in $this->settings['enabled_files']. 157 // $mime_types_orig is needed to re-map the values from the settings lib structure to core WP extension regex => mime-type format. 158 $mime_types = $mime_types_orig = wp_get_mime_types(); 159 unset( $mime_types['htm|html'] ); 160 unset( $mime_types['js'] ); 161 162 $enabled = isset( $this->settings['enabled_files'] ) && is_array( $this->settings['enabled_files'] ) && $this->settings['enabled_files'] ? $this->settings['enabled_files'] : $mime_types; 163 164 foreach ( $enabled as $ext_key => $mime ) { 165 // Check for PHP. 166 if ( false !== strpos( $mime, 'php' ) ) { 167 unset( $enabled[ $ext_key ] ); 168 trigger_error( __( "Frontend Uploader doesn't support PHP uploads for security reasons", 'frontend-uploader' ) ); 169 } 170 171 // We need to re-map the value from our settings to the proper MIME-type instead of regex key for mime check to work correctly. 172 $enabled[ $ext_key ] = $mime_types_orig[ $ext_key ]; 173 } 174 175 /** 176 * Configuration filter: fu_allowed_mime_types should return array of allowed mime types (see readme) 177 * @param array $enabled the list of enabled mime-types in core-compatible [ 'ext|ext2' => 'mime/type' ] format. 178 */ 179 $mime_types = apply_filters( 'fu_allowed_mime_types', $enabled ); 176 180 177 181 return $mime_types; … … 186 190 $defaults = array(); 187 191 $settings = Frontend_Uploader_Settings::get_settings_fields(); 188 foreach ( $settings[ $this->settings_slug] as $setting ) {192 foreach ( $settings[ $this->settings_slug ] as $setting ) { 189 193 $defaults[ $setting['name'] ] = $setting['default']; 190 194 } … … 257 261 */ 258 262 function _upload_files( $post_id = 0 ) { 259 // Only filter mimes just before the upload 263 // Only filter mimes just before the upload. 260 264 add_filter( 'upload_mimes', array( $this, '_get_mime_types' ), 999 ); 261 265 … … 284 288 285 289 // Skip to the next file if upload went wrong 286 if ( $k['error'] !== 0 ) {290 if ( $k['error'] !== 0 ) { 287 291 $errors['fu-error-media'][] = array( 'name' => $k['name'], 'code' => $k['error'] ); 288 292 continue; 289 293 } 290 294 291 $typecheck = wp_check_filetype_and_ext( $k['tmp_name'], $k['name'], false);295 $typecheck = mime_content_type( $k['tmp_name'] ); 292 296 // Add an error message if MIME-type is not allowed 293 if ( ! in_array( $typecheck ['type'], (array) $this->allowed_mime_types, true ) ) {297 if ( ! in_array( $typecheck, (array) $this->allowed_mime_types, true ) ) { 294 298 $errors['fu-disallowed-mime-type'][] = array( 'name' => $k['name'], 'mime' => $k['type'] ); 295 299 continue; … … 1084 1088 'post_type' => 'post', 1085 1089 'category' => '', 1086 'suppress_default_fields' => ! ( isset( $this->settings['suppress_default_fields'] ) && 'on' === $this->settings['suppress_default_fields'] ),1090 'suppress_default_fields' => isset( $this->settings['suppress_default_fields'] ) && 'on' === $this->settings['suppress_default_fields'], 1087 1091 'append_to_post' => false, 1088 1092 ), $atts ) ); -
frontend-uploader/trunk/lib/php/frontend-uploader-settings.php
r1971315 r2590623 64 64 */ 65 65 static function get_settings_fields() { 66 static $settings_fields; 67 68 if ( $settings_fields ) { 69 return $settings_fields; 70 } 71 66 72 $default_post_type = array( 'post' => 'Posts' ); 73 $core_mime_types = fu_get_exts_descs(); 74 75 // Sanitize a bit. 76 $safe_defaults = $core_mime_types; 77 unset( $safe_defaults['htm|html'] ); 78 unset( $safe_defaults['js'] ); 79 $safe_defaults_keys = array_keys( $safe_defaults ); 80 67 81 $settings_fields = array( 68 82 'frontend_uploader_settings' => array( … … 145 159 'desc' => '', 146 160 'type' => 'multicheck', 147 'default' => array (),148 'options' => fu_get_exts_descs(),161 'default' => array_combine( $safe_defaults_keys, $safe_defaults_keys ), 162 'options' => $core_mime_types, 149 163 ), 150 164 array( -
frontend-uploader/trunk/lib/php/functions.php
r1688580 r2590623 5 5 6 6 /** 7 * Get the common MIME-types for extensions8 * @return array9 */10 function fu_get_mime_types() {11 // Generated with dyn_php class: http://www.phpclasses.org/package/2923-PHP-Generate-PHP-code-programmatically.html12 $mimes_exts = array(13 'csv'=>14 array(15 'label'=> 'Comma Separated Values File',16 'mimes'=>17 array(18 'text/comma-separated-values',19 'text/csv',20 'application/csv',21 'application/excel',22 'application/vnd.ms-excel',23 'application/vnd.msexcel',24 'text/anytext',25 ),26 ),27 'mp3'=>28 array(29 'label'=> 'MP3 Audio File',30 'mimes'=>31 array(32 'audio/mpeg',33 'audio/x-mpeg',34 'audio/mp3',35 'audio/x-mp3',36 'audio/mpeg3',37 'audio/x-mpeg3',38 'audio/mpg',39 'audio/x-mpg',40 'audio/x-mpegaudio',41 ),42 ),43 'avi'=>44 array(45 'label'=> 'Audio Video Interleave File',46 'mimes'=>47 array(48 'video/avi',49 'video/msvideo',50 'video/x-msvideo',51 'image/avi',52 'video/xmpg2',53 'application/x-troff-msvideo',54 'audio/aiff',55 'audio/avi',56 ),57 ),58 59 'mid'=>60 array(61 'label'=> 'MIDI File',62 'mimes'=>63 array(64 'audio/mid',65 'audio/m',66 'audio/midi',67 'audio/x-midi',68 'application/x-midi',69 'audio/soundtrack',70 ),71 ),72 'wav'=>73 array(74 'label'=> 'WAVE Audio File',75 'mimes'=>76 array(77 'audio/wav',78 'audio/x-wav',79 'audio/wave',80 'audio/x-pn-wav',81 ),82 ),83 'wma'=>84 array(85 'label'=> 'Windows Media Audio File',86 'mimes'=>87 array(88 'audio/x-ms-wma',89 'video/x-ms-asf',90 ),91 ),92 );93 94 return $mimes_exts;95 }96 97 /**98 7 * Generate slug => description array for Frontend Uploader settings 99 8 * @return array 100 9 */ 101 10 function fu_get_exts_descs() { 102 $mimes = fu_get_mime_types();11 $mimes = wp_get_mime_types(); 103 12 $a = array(); 104 13 105 foreach( $mimes as $ext => $mime ) 106 $a[$ext] = sprintf( '%1$s (.%2$s)', $mime['label'], $ext ); 14 foreach( $mimes as $ext => $mime ) { 15 $a[ $ext ] = sprintf( '%2$s (%1$s)', $mime, str_replace( '|', ', ', $ext ) ); 16 } 107 17 108 18 return $a; -
frontend-uploader/trunk/readme.md
r1030331 r2590623 1 1 # Frontend Uploader 2 3 ⚠️ _This plugin is not actively maintained._ Any discovered security issues will be patched though. ⚠️ 4 5 If you're interested in becoming a maintainer please let me know. 2 6 3 7 ## Description -
frontend-uploader/trunk/readme.txt
r2008848 r2590623 4 4 Tags: frontend, image, images, media, uploader, upload, video, audio, photo, photos, picture, pictures, file, user generated content, ugc, frontend upload 5 5 Requires at least: 4.6 6 Requires PHP: 5.47 6 Tested up to: 5.0 8 7 Stable tag: 1.3.2 … … 16 15 17 16 This plugin is a simple way for users to submit content to your site. The plugin uses a set of shortcodes to let you create highly customizable submission forms to your posts and pages. Once the content is submitted, it is held for moderation until you approve it. It’s that easy! 17 18 **Security** 19 20 Allowing uploads from unauthenticated users is inherently risky. The plugin relies on the core allow list for files. However, we explicitly remove HTML, JS and PHP files even if they're in the allow list. To modify the list of allowed file types please refer to *fu_allowed_mime_types* configuration filter section for additional details. 18 21 19 22 = Exploring Customizations = … … 334 337 335 338 This action runs after form was uploaded. Arguments are: (string) $layout (form layout), (array) $result - result of the upload. 336 `add_action( 'fu_upload_result', 'my_fu_upload_result', 10, 2 );339 `add_action( 'fu_upload_result', 'my_fu_upload_result', 10, 2 ); 337 340 338 341 function my_fu_upload_result( $layout, $result ) {
Note: See TracChangeset
for help on using the changeset viewer.