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 FreeAtomic 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.
Below is a differential between the unpatched vulnerable code and the patched update, for reference.
--- 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, "