Plugin Directory

Changeset 3788934


Ignore:
Timestamp:
11/07/2026 02:13:32 AM (less than one hour ago)
Author:
addonsorg
Message:

Release new version

Location:
drag-and-drop-file-upload-for-elementor-forms
Files:
21 added
3 edited

Legend:

Unmodified
Added
Removed
  • drag-and-drop-file-upload-for-elementor-forms/trunk/drag-and-drop-file-upload-for-elementor-forms.php

    r3691226 r3788934  
    77 * Author: add-ons.org
    88 * Author URI: https://add-ons.org/
    9  * Version: 1.6.2
     9 * Version: 1.6.3
    1010 * Requires PHP: 5.2
    1111 * Elementor tested up to: 4.2
  • drag-and-drop-file-upload-for-elementor-forms/trunk/fields/file_upload.php

    r3691226 r3788934  
    723723                }
    724724                if ($field["raw_value"] != "") {
    725                         $temp_dir = $this->get_temp_dir();
    726                         $dir_upload = $this->get_ensure_upload_dir();
     725                        $temp_dir = trailingslashit($this->get_temp_dir());
     726                        $dir_upload = trailingslashit($this->get_ensure_upload_dir());
    727727                        $files = explode("|", $field["raw_value"]);
    728728                        $new_files = array();
    729729                        $index = 0;
     730                        global $wp_filesystem;
     731                        if (empty($wp_filesystem)) {
     732                                require_once ABSPATH . 'wp-admin/includes/file.php';
     733                                WP_Filesystem();
     734                        }
    730735                        foreach ($files as $file) {
    731                                 $file_datas = explode("/", $file);
    732                                 $filename = end($file_datas);
     736                                // Only accept a plain file name that was really uploaded to the temp folder
     737                                $filename = $this->sanitize_submitted_filename($file);
     738                                if ($filename === '') {
     739                                        continue;
     740                                }
    733741                                $temp_path = $temp_dir . $filename;
    734742                                $dest_path = $dir_upload . $filename;
    735 
    736                                 // Move file from temp to final uploads folder if it exists in temp
    737                                 global $wp_filesystem;
    738                                 if (empty($wp_filesystem)) {
    739                                         require_once ABSPATH . 'wp-admin/includes/file.php';
    740                                         WP_Filesystem();
    741                                 }
    742                                 if ($wp_filesystem->exists($temp_path)) {
    743                                         $wp_filesystem->move($temp_path, $dest_path, true);
     743                                if (!is_file($temp_path) || !$this->is_path_inside_dir($temp_path, $temp_dir)) {
     744                                        continue;
     745                                }
     746                                // Never overwrite a file that is already in the uploads folder
     747                                if (file_exists($dest_path)) {
     748                                        continue;
     749                                }
     750                                if (!$wp_filesystem->move($temp_path, $dest_path, false) || !$this->is_path_inside_dir($dest_path, $dir_upload)) {
     751                                        continue;
    744752                                }
    745753
    … …  
    773781                        }
    774782
     783                        if (empty($new_files) && !empty($field['required'])) {
     784                                $ajax_handler->add_error($id, esc_html__('Please upload the file again.', 'drag-and-drop-file-upload-for-elementor-forms'));
     785                                return;
     786                        }
    775787                        // Update the field value in the record to use the permanent URLs
    776788                        $new_raw_value = implode("|", $new_files);
    … …  
    835847        {
    836848                $attachments_mode_attach = $this->get_file_by_attachment_type_ok($settings['form_fields'], $record, "yes");
     849                $upload_dir = $this->get_upload_dir();
    837850                foreach ($attachments_mode_attach as $file) {
    838                         @wp_delete_file($file);
    839                 }
     851                        if (!is_string($file) || $this->is_protected_filename(basename($file))) {
     852                                continue;
     853                        }
     854                        if (is_file($file) && $this->is_path_inside_dir($file, $upload_dir)) {
     855                                @wp_delete_file(realpath($file));
     856                        }
     857                }
     858        }
     859        /**
     860         * Turns a submitted field token (temp URL or file name) into a safe plain file name.
     861         * Returns '' when the token cannot be a file uploaded by this field.
     862         */
     863        private function sanitize_submitted_filename($value)
     864        {
     865                $value = trim(rawurldecode((string) $value));
     866                if ($value === '') {
     867                        return '';
     868                }
     869                // Handle both separators so Windows paths cannot traverse directories
     870                $value = str_replace('\\', '/', $value);
     871                $value = strtok($value, '?#');
     872                $filename = sanitize_file_name(wp_basename((string) $value));
     873                if ($filename === '' || $filename[0] === '.' || $this->is_protected_filename($filename)) {
     874                        return '';
     875                }
     876                return $filename;
     877        }
     878        private function is_protected_filename($filename)
     879        {
     880                $protected_files = array('.htaccess', 'index.php', 'index.html', 'php.ini', '.user.ini', 'web.config');
     881                return in_array(strtolower((string) $filename), $protected_files, true);
     882        }
     883        /**
     884         * True when $path resolves to a location inside $dir.
     885         */
     886        private function is_path_inside_dir($path, $dir)
     887        {
     888                $real_path = realpath($path);
     889                $real_dir = realpath($dir);
     890                if ($real_path === false || $real_dir === false) {
     891                        return false;
     892                }
     893                return strpos($real_path, trailingslashit($real_dir)) === 0;
    840894        }
    841895        private function get_file_by_attachment_type_ok($form_fields, $record, $type)
  • drag-and-drop-file-upload-for-elementor-forms/trunk/readme.txt

    r3691226 r3788934  
    22Contributors: addonsorg
    33Tags: Elementor Forms, File field, Elementor Forms upload, uploads, uploads field
    4 Stable tag: 1.6.2
     4Stable tag: 1.6.3
    55Tested up to: 7.1
    66Requires PHP: 5.2
    … …  
    6060
    6161== Changelog ==
     62= 1.6.3 =
     63- Security: Form submissions now only accept files that were really uploaded through the field. Submitted file names are sanitized and confined to the upload folder, existing files are never overwritten, and the "files are not saved on the server" cleanup can only delete files inside the upload folder.
     64
    6265= 1.6.0 =
    6366- Fixed: Create a temporary upload directory and automatically delete its contents daily to prevent unnecessary files from accumulating on the server.
Note: See TracChangeset for help on using the changeset viewer.