Plugin Directory

Changeset 3360611


Ignore:
Timestamp:
09/12/2025 03:17:43 PM (6 months ago)
Author:
smackcoders
Message:

Security Fix – Arbitrary File Deletion

Location:
wp-ultimate-csv-importer
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • wp-ultimate-csv-importer/tags/7.29/uploadModules/FtpUpload.php

    r3360428 r3360611  
    110110                    $path = isset($path[0]) ? $path[0] : '';
    111111                    $file_extension = pathinfo($ftp_file_name, PATHINFO_EXTENSION);
     112                    $allowed_exts = ['csv', 'xml', 'xlsx', 'xls', 'txt', 'tsv'];
     113                    if ( ! in_array( $file_extension, $allowed_exts, true ) ) {
     114                        wp_die( __( 'Invalid file type.', 'wp-ultimate-csv-importer' ), 400 );
     115                    }
    112116                    if(empty($file_extension)){
    113117                        $file_extension = 'xml';
     
    221225                            $response['message'] = $validate_file;
    222226                            echo wp_json_encode($response);
    223                             unlink($path);
     227                            $upload_dir = wp_upload_dir();
     228                            $base_dir   = trailingslashit($upload_dir['basedir']);
     229
     230                            $real_base = realpath($base_dir);
     231                            $real_path = realpath($path);
     232
     233                            if ($real_path !== false && strpos($real_path, $real_base) === 0) {
     234                                unlink($real_path); // safe delete inside uploads only
     235                            }
    224236                            $wpdb->get_results("UPDATE $file_table_name SET status='Download Failed' WHERE id = '$lastid'");
    225237                        }
  • wp-ultimate-csv-importer/trunk/uploadModules/FtpUpload.php

    r3357936 r3360611  
    110110                    $path = isset($path[0]) ? $path[0] : '';
    111111                    $file_extension = pathinfo($ftp_file_name, PATHINFO_EXTENSION);
     112                    $allowed_exts = ['csv', 'xml', 'xlsx', 'xls', 'txt', 'tsv'];
     113                    if ( ! in_array( $file_extension, $allowed_exts, true ) ) {
     114                        wp_die( __( 'Invalid file type.', 'wp-ultimate-csv-importer' ), 400 );
     115                    }
    112116                    if(empty($file_extension)){
    113117                        $file_extension = 'xml';
     
    221225                            $response['message'] = $validate_file;
    222226                            echo wp_json_encode($response);
    223                             unlink($path);
     227                            $upload_dir = wp_upload_dir();
     228                            $base_dir   = trailingslashit($upload_dir['basedir']);
     229
     230                            $real_base = realpath($base_dir);
     231                            $real_path = realpath($path);
     232
     233                            if ($real_path !== false && strpos($real_path, $real_base) === 0) {
     234                                unlink($real_path); // safe delete inside uploads only
     235                            }
    224236                            $wpdb->get_results("UPDATE $file_table_name SET status='Download Failed' WHERE id = '$lastid'");
    225237                        }
Note: See TracChangeset for help on using the changeset viewer.