Below is a differential between the unpatched vulnerable code and the patched update, for reference.
--- a/forminator/addons/pro/mailchimp/class-forminator-addon-mailchimp-form-hooks.php
+++ b/forminator/addons/pro/mailchimp/class-forminator-addon-mailchimp-form-hooks.php
@@ -401,6 +401,7 @@
$status = 'pending';
}
+ $member_status_request = null;
try {
// keep subscribed if already subscribed.
$member_status_request = $mailchimp_api->get_member( $addon_setting_values['mail_list_id'], $subscriber_hash, array() );
@@ -417,6 +418,12 @@
}
}
+ // Only the owner may update an existing member.
+ if ( is_object( $member_status_request ) && ! empty( $member_status_request->status )
+ && ! $this->addon->can_update_member( $submitted_data[ $addon_setting_values['fields_map']['EMAIL'] ], $member_status_request, $form_id, $addon_setting_values['mail_list_id'], $entry ) ) {
+ throw new Forminator_Integration_Exception( esc_html__( 'Member already exists, only its owner can update it.', 'forminator' ) );
+ }
+
$args = array(
'status' => $status,
'status_if_new' => $status,
--- a/forminator/addons/pro/mailchimp/class-forminator-addon-mailchimp-quiz-hooks.php
+++ b/forminator/addons/pro/mailchimp/class-forminator-addon-mailchimp-quiz-hooks.php
@@ -32,6 +32,7 @@
* @throws Forminator_Integration_Exception Throws Integration Exception.
*/
protected function custom_entry_fields( $submitted_data, $current_entry_fields ): array {
+ $entry = func_get_args()[2];
$quiz_id = $this->module_id;
$quiz_settings_instance = $this->settings_instance;
$gdpr = false;
@@ -215,6 +216,7 @@
$status = 'pending';
}
+ $member_status_request = null;
try {
// keep subscribed if already subscribed.
$member_status_request = $mailchimp_api->get_member( $addon_setting_values['mail_list_id'], $subscriber_hash, array() );
@@ -231,6 +233,12 @@
}
}
+ // Only the owner may update an existing member.
+ if ( is_object( $member_status_request ) && ! empty( $member_status_request->status )
+ && ! $this->addon->can_update_member( $submitted_data[ $addon_setting_values['fields_map']['EMAIL'] ], $member_status_request, $quiz_id, $addon_setting_values['mail_list_id'], $entry ) ) {
+ throw new Forminator_Integration_Exception( esc_html__( 'Member already exists, only its owner can update it.', 'forminator' ) );
+ }
+
$args = array(
'status' => $status,
'status_if_new' => $status,
--- a/forminator/addons/pro/mailchimp/class-forminator-addon-mailchimp.php
+++ b/forminator/addons/pro/mailchimp/class-forminator-addon-mailchimp.php
@@ -514,4 +514,45 @@
wp_send_json_success( $html );
}
+
+ /**
+ * Check whether a submission may update an existing member.
+ *
+ * Only the WordPress user with the member's email may. Account emails are not always verified,
+ * so sites can tighten this with the filter.
+ *
+ * @since 1.59.0
+ *
+ * @param string $email Submitted email.
+ * @param object $member Existing member.
+ * @param int $module_id Module ID.
+ * @param string $list_id Audience ID.
+ * @param Forminator_Form_Entry_Model|null $entry Entry.
+ *
+ * @return bool
+ */
+ public function can_update_member( $email, $member, $module_id, $list_id, $entry = null ) {
+ // Payments completed later use the stored submitter, not the current user.
+ $submitter = $entry instanceof Forminator_Form_Entry_Model ? $entry->get_meta( '_submitter_user_id', null ) : null;
+ $user = null === $submitter ? wp_get_current_user() : new WP_User( (int) $submitter );
+ $email = strtolower( trim( (string) ( $member->email_address ?? $email ) ) );
+ $is_owner = $user->exists() && strtolower( trim( $user->user_email ) ) === $email;
+
+ /**
+ * Filter whether a submission may update an existing Mailchimp member
+ *
+ * Returning true lets anyone who submits the email overwrite the member.
+ *
+ * @since 1.59.0
+ *
+ * @param bool $is_owner Whether the submitter's account email matches the member.
+ * @param string $email Member email.
+ * @param object $member Existing member.
+ * @param int $module_id Module ID.
+ * @param string $list_id Audience ID.
+ * @param Forminator_Form_Entry_Model|null $entry Entry.
+ * @param WP_User $user Submitter, ID 0 for guests. Check it with user_can(), not current_user_can().
+ */
+ return (bool) apply_filters( 'forminator_addon_mailchimp_update_existing_member', $is_owner, $email, $member, $module_id, $list_id, $entry, $user );
+ }
}
--- a/forminator/admin/locale.php
+++ b/forminator/admin/locale.php
@@ -1367,7 +1367,7 @@
"Additional filetypes" => array( null, __("Additional filetypes", "forminator"), ), // src/form/components/settings/filetypes.js:259
"E.g. .dts|audio/vnd.dts, .ai|application/postscript" => array( null, __("E.g. .dts|audio/vnd.dts, .ai|application/postscript", "forminator"), ), // src/form/components/settings/filetypes.js:260
"Note that if you're having trouble uploading one of the enabled filetypes, that filetype may be restricted by your hosting provider." => array( null, __("Note that if you're having trouble uploading one of the enabled filetypes, that filetype may be restricted by your hosting provider.", "forminator"), ), // src/form/components/settings/filetypes.js:278
-"For security reasons, the following file types are disabled by default: .htm, .html, .shtml, .phtml, .jse, .jar, .xml, .css, .asp, .aspx, .jsp, .sql, .hta, .dll, .bat, .com, .sh, .bash, .py, .pl, .js, .php, .svg, .swf, .dfxp, .rar and .exe. The above file types could potentially allow malicious files to be uploaded, which could be used to gain access to your site." => array( null, __("For security reasons, the following file types are disabled by default: .htm, .html, .shtml, .phtml, .jse, .jar, .xml, .css, .asp, .aspx, .jsp, .sql, .hta, .dll, .bat, .com, .sh, .bash, .py, .pl, .js, .php, .svg, .swf, .dfxp, .rar and .exe. The above file types could potentially allow malicious files to be uploaded, which could be used to gain access to your site.", "forminator"), ), // src/form/components/settings/filetypes.js:306
+"For security reasons, the following file types are disabled by default: .htm, .html, .shtml, .phtml, .jse, .jar, .xml, .css, .asp, .aspx, .jsp, .sql, .hta, .dll, .bat, .com, .sh, .bash, .py, .pl, .js, .php, .svg, .swf, .dfxp, .rar, .rtx and .exe. The above file types could potentially allow malicious files to be uploaded, which could be used to gain access to your site." => array( null, __("For security reasons, the following file types are disabled by default: .htm, .html, .shtml, .phtml, .jse, .jar, .xml, .css, .asp, .aspx, .jsp, .sql, .hta, .dll, .bat, .com, .sh, .bash, .py, .pl, .js, .php, .svg, .swf, .dfxp, .rar, .rtx and .exe. The above file types could potentially allow malicious files to be uploaded, which could be used to gain access to your site.", "forminator"), ), // src/form/components/settings/filetypes.js:306
"Above Inputs" => array( null, __("Above Inputs", "forminator"), ), // src/form/components/settings/description-placement.js:23
"Below Inputs" => array( null, __("Below Inputs", "forminator"), ), // src/form/components/settings/description-placement.js:26
"Pick custom date(s) to restrict" => array( null, __("Pick custom date(s) to restrict", "forminator"), ), // src/form/components/settings/date-multiple.js:67
--- a/forminator/admin/pages/settings-page.php
+++ b/forminator/admin/pages/settings-page.php
@@ -141,6 +141,10 @@
public static function only_appearance_settings( $all_settings ) {
// todo: refactor - it's better to use separate array `appearance` in the modal settings,
// which includes all appearance settings. And then we can remove this method.
+ $exclude = array(
+ 'indicator-label',
+ 'remember-me-label',
+ );
$consist = array(
'-font-family',
'-custom-family',
@@ -205,6 +209,9 @@
foreach ( $all_settings as $key => $value ) {
$apply = false;
+ if ( in_array( $key, $exclude, true ) ) {
+ continue;
+ }
if ( in_array( $key, $props, true ) || 'basic-' === substr( $key, 0, 6 ) ) {
$apply = true;
}
--- a/forminator/constants.php
+++ b/forminator/constants.php
@@ -11,7 +11,7 @@
*/
if ( ! defined( 'FORMINATOR_VERSION' ) ) {
- define( 'FORMINATOR_VERSION', '1.58.4' );
+ define( 'FORMINATOR_VERSION', '1.58.5' );
}
if ( ! defined( 'FORMINATOR_SUI_VERSION' ) ) {
--- a/forminator/forminator.php
+++ b/forminator/forminator.php
@@ -1,7 +1,7 @@
<?php
/**
* Plugin Name: Forminator
- * Version: 1.58.4
+ * Version: 1.58.5
* Plugin URI: https://wpmudev.com/project/forminator/
* Description: Build powerful, customizable forms with ease using Forminator’s drag-and-drop builder, conditional logic, payment support, real-time analytics, and seamless integrations—no coding needed.
* Author: WPMU DEV
--- a/forminator/library/abstracts/abstract-class-field.php
+++ b/forminator/library/abstracts/abstract-class-field.php
@@ -578,7 +578,11 @@
$html .= self::get_description( $description, $attr['id'], $description_position );
}
- $html .= sprintf( '<textarea %s >%s</textarea>', $markup, wp_kses_post( $content ) );
+ // get_post_data() / some callers already entity-encode; decode first so
+ // esc_textarea() does not double-encode.
+ // Still encode for the textarea text context so stored HTML cannot close this tag.
+ $content = htmlspecialchars_decode( (string) $content, ENT_QUOTES );
+ $html .= sprintf( '<textarea %s >%s</textarea>', $markup, esc_textarea( $content ) );
if ( 'above' !== $description_position ) {
$html .= self::get_description( $description, $attr['id'], $description_position );
@@ -2419,10 +2423,43 @@
*/
public static function add_htaccess_file( $upload_root ) {
$htaccess_file = $upload_root . '.htaccess';
- if ( file_exists( $htaccess_file ) ) {
+ $rules = self::get_upload_root_htaccess_rules();
+
+ /**
+ * A filter to allow the modification/disabling of parsing certain PHP
+ *
+ * @since 1.23.1
+ *
+ * @param mixed $rules The Rules of what to parse or not to parse
+ */
+ $rules = apply_filters( 'forminator_upload_root_htaccess_rules', $rules );
+
+ // Refresh an existing file when the security rules change. insert_with_markers() keeps lines outside the Forminator block.
+ if ( file_exists( $htaccess_file ) && self::upload_htaccess_is_current( $htaccess_file, $rules ) ) {
return;
}
- $rules = '# Disable parsing of PHP for some server configurations.
+
+ if ( ! function_exists( 'insert_with_markers' ) ) {
+ require_once ABSPATH . 'wp-admin/includes/misc.php';
+ }
+
+ if ( ! empty( $rules ) ) {
+ insert_with_markers( $htaccess_file, 'Forminator', $rules );
+ }
+ }
+
+ /**
+ * Apache rules for the Forminator upload root.
+ *
+ * .rtx is text/richtext in WordPress, and fileinfo often reads those bytes as text/plain.
+ * Debian and Ubuntu Apache do not map .rtx, so the response has no Content-Type and the browser may sniff it as HTML.
+ *
+ * @since 1.58.5
+ *
+ * @return string
+ */
+ private static function get_upload_root_htaccess_rules() {
+ return '# Disable parsing of PHP for some server configurations.
<Files *>
SetHandler none
SetHandler default-handler
@@ -2435,19 +2472,37 @@
</IfModule>
<IfModule headers_module>
Header set X-Robots-Tag "noindex"
+ Header set X-Content-Type-Options "nosniff"
+</IfModule>
+<IfModule mime_module>
+ <FilesMatch "(?i).rtx$">
+ ForceType text/plain
+ </FilesMatch>
</IfModule>';
+ }
- /**
- * A filter to allow the modification/disabling of parsing certain PHP
- *
- * @since 1.23.1
- *
- * @param mixed $rules The Rules of what to parse or not to parse
- */
- $rules = apply_filters( 'forminator_upload_root_htaccess_rules', $rules );
- if ( ! empty( $rules ) ) {
- insert_with_markers( $htaccess_file, 'Forminator', $rules );
+ /**
+ * Whether the upload .htaccess already contains the current Forminator rules.
+ *
+ * @since 1.58.5
+ *
+ * @param string $htaccess_file Htaccess path.
+ * @param mixed $rules Rules that would be written.
+ * @return bool
+ */
+ private static function upload_htaccess_is_current( $htaccess_file, $rules ) {
+ $contents = file_get_contents( $htaccess_file ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- Local .htaccess, not a remote URL.
+ if ( ! is_string( $contents ) ) {
+ return false;
}
+
+ // A filtered ruleset that drops the .rtx rule is left as the site configured it.
+ if ( ! is_string( $rules ) || false === strpos( $rules, 'ForceType text/plain' ) ) {
+ return false !== strpos( $contents, '# BEGIN Forminator' );
+ }
+
+ return false !== strpos( $contents, 'ForceType text/plain' )
+ && false !== strpos( $contents, 'X-Content-Type-Options' );
}
/**
--- a/forminator/library/addon/class-integration-hooks.php
+++ b/forminator/library/addon/class-integration-hooks.php
@@ -845,7 +845,8 @@
// For quiz lead forms, $prepared_data contains quiz data (answers, entry_id)
// instead of form field values. Load field data from the lead entry meta.
- if ( ! empty( $field_data['has_lead'] ) && ! empty( $field_data['entry_id'] ) ) {
+ // Only quiz submissions have a verified lead entry.
+ if ( 'quiz' === static::$slug && ! empty( $field_data['has_lead'] ) && ! empty( $field_data['entry_id'] ) ) {
$entry = forminator_lead_form_data( $field_data );
if ( ! empty( $entry->meta_data ) ) {
$field_data = $entry->meta_data;
--- a/forminator/library/class-handle-webhooks.php
+++ b/forminator/library/class-handle-webhooks.php
@@ -25,6 +25,15 @@
private static $instance = null;
/**
+ * Lock values acquired by this request, keyed by entry ID.
+ *
+ * @since 1.59.0
+ *
+ * @var array
+ */
+ private $lock_values = array();
+
+ /**
* Return the plugin instance
*
* @return Forminator_Handle_Webhooks
@@ -218,8 +227,11 @@
* Lock the webhook processing for the given entry to prevent concurrent processing.
*
* @param Forminator_Form_Entry_Model $entry The entry object.
+ * @return bool True if the processing is already locked, false otherwise.
*/
public function lock_webhook_processing( $entry ) {
+ global $wpdb;
+
if ( $this->is_webhook_processing_locked( $entry ) ) {
// If the lock already exists, return early to prevent concurrent processing.
return true;
@@ -230,26 +242,29 @@
$entry->add_meta( '_stripe_webhook_processing_lock', $expire_time );
- // This is a safeguard to ensure that we don't allow concurrent processing.
- $result = add_option( 'forminator_stripe_webhook_processing_lock_' . $entry->entry_id, $expire_time, '', 'no' );
+ $option_name = 'forminator_stripe_webhook_processing_lock_' . $entry->entry_id;
+ // Add a random token so only this request can release the lock.
+ $lock_value = $expire_time . ':' . wp_generate_password( 32, false );
+
+ // Use direct queries, as the options API cannot add or update atomically.
+ // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
+ $result = $wpdb->query( $wpdb->prepare( "INSERT IGNORE INTO {$wpdb->options} (`option_name`, `option_value`, `autoload`) VALUES (%s, %s, 'no')", $option_name, $lock_value ) );
if ( ! $result ) {
- $expiration = get_option( 'forminator_stripe_webhook_processing_lock_' . $entry->entry_id, false );
- // If the lock does not exist, return true to block parallel processing.
- if ( false === $expiration ) {
+ // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
+ $current_value = $wpdb->get_var( $wpdb->prepare( "SELECT `option_value` FROM {$wpdb->options} WHERE `option_name` = %s", $option_name ) );
+ // If the lock does not exist or is still active, return true to block parallel processing.
+ if ( is_null( $current_value ) || time() <= (int) $current_value ) {
return true;
}
- // If the lock is still active, return true.
- if ( time() <= (int) $expiration ) {
+ // If the lock has expired, take it over unless another request already did.
+ // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
+ $result = $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->options} SET `option_value` = %s WHERE `option_name` = %s AND `option_value` = %s", $lock_value, $option_name, $current_value ) );
+ if ( ! $result ) {
return true;
- } else {
- // If the lock has expired, delete the lock option and try to acquire the lock again.
- delete_option( 'forminator_stripe_webhook_processing_lock_' . $entry->entry_id );
- $result = add_option( 'forminator_stripe_webhook_processing_lock_' . $entry->entry_id, $expire_time, '', 'no' );
- if ( ! $result ) {
- return true;
- }
}
}
+ $this->lock_values[ $entry->entry_id ] = $lock_value;
+
return false;
}
@@ -283,8 +298,19 @@
* @param Forminator_Form_Entry_Model $entry The entry object.
*/
public function unlock_webhook_processing( $entry ) {
- delete_option( 'forminator_stripe_webhook_processing_lock_' . $entry->entry_id );
- if ( ! empty( $entry->status ) && 'pending' === $entry->status ) {
+ global $wpdb;
+
+ // If the lock was not acquired by this request, return early.
+ if ( empty( $this->lock_values[ $entry->entry_id ] ) ) {
+ return;
+ }
+ $lock_value = $this->lock_values[ $entry->entry_id ];
+ unset( $this->lock_values[ $entry->entry_id ] );
+
+ // Delete the lock only if this request still owns it.
+ // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
+ $released = $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->options} WHERE `option_name` = %s AND `option_value` = %s", 'forminator_stripe_webhook_processing_lock_' . $entry->entry_id, $lock_value ) );
+ if ( $released && ! empty( $entry->status ) && 'pending' === $entry->status ) {
// If the entry is still pending, we can remove the lock meta to allow immediate future processing attempts.
$entry->delete_meta_by_key( '_stripe_webhook_processing_lock' );
}
--- a/forminator/library/fields/email.php
+++ b/forminator/library/fields/email.php
@@ -471,6 +471,11 @@
$item = preg_quote( $item, '/' );
// Support * as wildcard.
$item = str_replace( '*', '.*', $item );
+ if ( 0 !== strpos( $item, '@' ) && 0 !== strpos( $item, '.*' ) ) {
+ // If the item does not start with @ or *, add ^ to match the start of the email address.
+ $item = '^' . $item;
+ }
+
// Add start and end delimiters (case-insensitive; email domains are not case-sensitive).
$item = '/' . $item . '$/i';
if ( preg_match( $item, $email ) ) {
--- a/forminator/library/fields/text.php
+++ b/forminator/library/fields/text.php
@@ -187,17 +187,17 @@
$textarea['maxlength'] = $limit;
}
+ // create_textarea() applies esc_textarea(); pass plain values, not pre-escaped HTML.
if ( isset( $draft_value['value'] ) ) {
-
- $default = wp_kses_post( $draft_value['value'] );
-
+ $textarea_content = forminator_sanitize_textarea( $draft_value['value'] );
} elseif ( $this->has_prefill( $field ) ) {
- // We have pre-fill parameter, use its value or $value.
- $default = $this->get_prefill( $field, $default );
+ $textarea_content = $this->get_prefill( $field, self::get_property( 'default', $field, false ) );
+ } else {
+ $textarea_content = self::get_property( 'default', $field, false );
}
- if ( ! empty( $default ) ) {
- $textarea['content'] = $default;
+ if ( ! empty( $textarea_content ) ) {
+ $textarea['content'] = $textarea_content;
} elseif ( isset( $autofill_markup['value'] ) ) {
$textarea['content'] = $autofill_markup['value'];
unset( $autofill_markup['value'] );
--- a/forminator/library/fields/textarea.php
+++ b/forminator/library/fields/textarea.php
@@ -141,11 +141,12 @@
$this->form_settings = $settings;
$descr_position = self::get_description_position( $field, $settings );
- $html = '';
- $name = self::get_property( 'element_id', $field );
- $id = self::get_field_id( $name );
- $required = self::get_property( 'required', $field, false, 'bool' );
- $default = esc_html( self::get_property( 'default', $field, false ) );
+ $html = '';
+ $name = self::get_property( 'element_id', $field );
+ $id = self::get_field_id( $name );
+ $required = self::get_property( 'required', $field, false, 'bool' );
+ // create_textarea() applies esc_textarea(); do not pre-escape HTML entities here.
+ $default = self::get_property( 'default', $field, false );
$placeholder = $this->sanitize_value( self::get_property( 'placeholder', $field ) );
$label = esc_html( self::get_property( 'field_label', $field, '' ) );
$description = self::get_property( 'description', $field, '' );
@@ -172,8 +173,10 @@
}
if ( isset( $draft_value['value'] ) ) {
-
- $default = wp_kses_post( $draft_value['value'] );
+ // Keep draft HTML for the rich editor; create_textarea() escapes for the text context.
+ $default = true === $editor_type
+ ? forminator_sanitize_rich_textarea_widget_hooks( $draft_value['value'] )
+ : forminator_sanitize_textarea( $draft_value['value'] );
} elseif ( $this->has_prefill( $field ) ) {
// We have pre-fill parameter, use its value or $value.
--- a/forminator/library/helpers/helper-addon.php
+++ b/forminator/library/helpers/helper-addon.php
@@ -1314,7 +1314,7 @@
*/
function forminator_lead_form_data( $submitted_data ) {
$entry_data = null;
- $data_entry = isset( $submitted_data['entry_id'] ) ? $submitted_data['entry_id'] : 0;
+ $data_entry = isset( $submitted_data['entry_id'] ) ? absint( $submitted_data['entry_id'] ) : 0;
$entries = new Forminator_Form_Entry_Model( $data_entry );
if ( ! empty( $entries ) ) {
$entry_data = $entries;
--- a/forminator/library/helpers/helper-core.php
+++ b/forminator/library/helpers/helper-core.php
@@ -893,11 +893,7 @@
}
$form_type = '';
- $page = Forminator_Core::sanitize_text_field( 'page', null );
-
- if ( is_null( $page ) ) {
- return null;
- }
+ $page = substr( $screen->id, strpos( $screen->id, '_page_' ) + 6 );
switch ( $page ) {
case 'forminator-quiz-view':
@@ -2119,8 +2115,9 @@
*/
$cap = apply_filters( 'forminator_permission_cap', $cap, $page_slug, $default_cap, $permission_map );
- $user_allowed = false;
- $role_allowed = false;
+ $user_allowed = false;
+ $role_allowed = false;
+ $role_excluded = false;
// Check permissions for excluded users.
foreach ( $permissions as $permission ) {
@@ -2136,7 +2133,7 @@
// If current user is in excluded users, return the default admin cap.
if ( in_array( intval( $user->ID ), array_map( 'intval', $permission['exclude_users'] ), true ) ) {
- $role_allowed = false;
+ $role_excluded = true;
} else {
$role_allowed = true;
}
@@ -2153,6 +2150,11 @@
}
}
+ // Other role rules can't undo an exclusion.
+ if ( $role_excluded ) {
+ $role_allowed = false;
+ }
+
if (
( $user_allowed || $role_allowed ) ||
( $user_allowed && ! $role_allowed )
@@ -2309,8 +2311,8 @@
// Get roles.
$roles = get_editable_roles();
- // Allow all roles if the user is a super admin or has the administrator role.
- if ( ( is_multisite() && is_super_admin() ) || in_array( 'administrator', $current_user->roles, true ) ) {
+ // Allow all roles if the user is a super admin, or an administrator who can promote users.
+ if ( ( is_multisite() && is_super_admin() ) || ( in_array( 'administrator', $current_user->roles, true ) && current_user_can( 'promote_users' ) ) ) {
return $roles;
}
--- a/forminator/library/helpers/helper-fields.php
+++ b/forminator/library/helpers/helper-fields.php
@@ -3595,12 +3595,12 @@
continue;
}
- $form = $form->load( absint( $shortcode_attr['id'] ) );
- if ( ! is_object( $form ) ) {
+ $form_model = $form->load( absint( $shortcode_attr['id'] ) );
+ if ( ! is_object( $form_model ) ) {
continue;
}
- $form_fields = $form->get_fields();
+ $form_fields = $form_model->get_fields();
foreach ( $form_fields as $field ) {
if ( false !== strpos( $field->slug, $field_type ) ) {
@@ -3753,7 +3753,7 @@
$mimes = get_allowed_mime_types();
}
if ( ! $allow ) {
- $blocked_extensions = array( 'htm', 'html', 'js', 'jse', 'jar', 'php', 'php3', 'php4', 'php5', 'phtml', 'svg', 'swf', 'exe', 'shtml', 'xhtml', 'xml', 'css', 'asp', 'aspx', 'jsp', 'sql', 'hta', 'dll', 'bat', 'com', 'sh', 'bash', 'py', 'pl', 'dfxp', 'rar' );
+ $blocked_extensions = array( 'htm', 'html', 'js', 'jse', 'jar', 'php', 'php3', 'php4', 'php5', 'phtml', 'svg', 'swf', 'exe', 'shtml', 'xhtml', 'xml', 'css', 'asp', 'aspx', 'jsp', 'sql', 'hta', 'dll', 'bat', 'com', 'sh', 'bash', 'py', 'pl', 'dfxp', 'rar', 'rtx' );
foreach ( array_keys( $mimes ) as $mime_key ) {
$alternatives = explode( '|', strtolower( (string) $mime_key ) );
--- a/forminator/library/helpers/helper-forms.php
+++ b/forminator/library/helpers/helper-forms.php
@@ -1295,6 +1295,13 @@
function forminator_get_rich_textarea_allowed_html() {
$allowed_html = wp_kses_allowed_html( 'post' );
+ // Form-interactive tags can break out of a parent <textarea> context when
+ // stored draft HTML is rendered back into a textarea without esc_textarea().
+ $disallowed_tags = array( 'textarea', 'input', 'select', 'option', 'optgroup', 'button', 'form' );
+ foreach ( $disallowed_tags as $tag ) {
+ unset( $allowed_html[ $tag ] );
+ }
+
// Validate URL attributes so entity-encoded markup cannot ride in them.
$url_attributes = wp_kses_uri_attributes();
@@ -1339,6 +1346,11 @@
if ( preg_match( '/^(sui|fui)-/i', $class_name ) ) {
return false;
}
+
+ // Reserved Forminator frontend hooks must not come from public submissions.
+ if ( 0 === stripos( $class_name, 'forminator-' ) ) {
+ return false;
+ }
}
return true;
--- a/forminator/library/model/class-form-entry-model.php
+++ b/forminator/library/model/class-form-entry-model.php
@@ -576,25 +576,39 @@
/**
* Updated status
*
- * @param string $status The new status.
+ * @since 1.59.0 Added `$expected_status` parameter.
+ *
+ * @param string $status The new status.
+ * @param string|null $expected_status Update only if the current status matches.
* @return bool
*/
- public function update_status( $status ) {
+ public function update_status( $status, $expected_status = null ) {
global $wpdb;
if ( empty( $this->entry_id ) ) {
return false;
}
+ $where = array( 'entry_id' => $this->entry_id );
+ if ( ! is_null( $expected_status ) ) {
+ // Update only if the status still matches, so concurrent requests cannot both change it.
+ $where['status'] = $expected_status;
+ }
+
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
$result = $wpdb->update(
$this->table_name,
array(
'status' => $status,
),
- array( 'entry_id' => $this->entry_id )
+ $where
);
if ( ! $result ) {
+ if ( ! is_null( $expected_status ) ) {
+ // Reload the status changed by another request.
+ // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
+ $this->status = (string) $wpdb->get_var( $wpdb->prepare( "SELECT `status` FROM {$this->table_name} WHERE `entry_id` = %d", $this->entry_id ) );
+ }
return false;
}
$this->status = $status;
@@ -3204,13 +3218,39 @@
* @param string $field_name - Field name.
* @param string $field_type - Field type.
* @param array $option Option settings.
- * @param bool $freeze Optional. Should it save transient option for the current request or not. False by default.
+ * @param bool $freeze Optional. Should it reserve the option for the current request or not. False by default.
* @return bool
*/
public static function is_option_limit_reached( $module_id, $field_name, $field_type, $option, $freeze = false ) {
+ global $wpdb;
+
if ( empty( $option['limit'] ) ) {
return false;
}
+
+ $reserved = 0;
+ if ( $freeze ) {
+ /**
+ * Filter the time interval (in seconds) after which transient option for limited Select Option for submissions in process will be expired.
+ *
+ * @param int $seconds Second amount. 10 by default.
+ * @param string $module_id Module ID.
+ */
+ $expiration = apply_filters( 'forminator_form_select_option_limit_interval', 10, $module_id );
+ // Use md5 hash to handle special characters in the option value.
+ $key_prefix = 'forminator_select_option_limit_in_process' . $module_id . $field_name . md5( $option['value'] ) . '_';
+ $key_like = $wpdb->esc_like( $key_prefix ) . '%';
+ $reservation_key = $key_prefix . wp_generate_password( 12, false );
+ // Delete expired reservations.
+ // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
+ $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->options} WHERE `option_name` LIKE %s AND `option_value` < %d", $key_like, time() ) );
+ // Reserve before counting, so concurrent requests see each other.
+ add_option( $reservation_key, time() + $expiration, '', 'no' );
+ // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
+ $reserved = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->options} WHERE `option_name` LIKE %s AND `option_name` <> %s", $key_like, $reservation_key ) );
+ }
+
+ // Count entries after reservations, so none are missed.
$entries = self::select_count_entries_by_meta_field(
$module_id,
$field_name,
@@ -3219,48 +3259,28 @@
$field_type
);
- if ( $option['limit'] <= $entries ) {
+ if ( $option['limit'] <= $entries + $reserved ) {
+ if ( $freeze ) {
+ delete_option( $reservation_key );
+ }
return true;
}
if ( $freeze ) {
- /**
- * Filter the time interval (in seconds) after which transient option for limited Select Option for submissions in process will be expired.
- *
- * @param int $seconds Second amount. 10 by default.
- * @param string $module_id Module ID.
- */
- $expiration = apply_filters( 'forminator_form_select_option_limit_interval', 10, $module_id );
- do {
- // Use md5 hash to handle special characters in the option value.
- $transient_key = 'forminator_select_option_limit_in_process' . $module_id . $field_name . md5( $option['value'] ) . '_' . $entries;
- $is_set = set_transient( $transient_key, true, $expiration );
- if ( ! $is_set ) {
- ++$entries;
- }
- } while ( ! $is_set && $entries < $option['limit'] );
-
- // Only register cleanup filters if transient was successfully set.
- if ( $is_set ) {
- add_filter(
- 'forminator_submission_success',
- function ( $response ) use ( $transient_key ) {
- delete_transient( $transient_key );
- return $response;
- }
- );
- add_filter(
- 'forminator_submission_error',
- function ( $response ) use ( $transient_key ) {
- delete_transient( $transient_key );
- return $response;
- }
- );
- }
-
- if ( $option['limit'] <= $entries ) {
- return true;
- }
+ add_filter(
+ 'forminator_submission_success',
+ function ( $response ) use ( $reservation_key ) {
+ delete_option( $reservation_key );
+ return $response;
+ }
+ );
+ add_filter(
+ 'forminator_submission_error',
+ function ( $response ) use ( $reservation_key ) {
+ delete_option( $reservation_key );
+ return $response;
+ }
+ );
}
return false;
--- a/forminator/library/model/class-poll-form-model.php
+++ b/forminator/library/model/class-poll-form-model.php
@@ -183,10 +183,13 @@
$interval = 'year';
break;
}
- $cookie_value = date_i18n( 'Y-m-d H:i:s', strtotime( sanitize_text_field( wp_unslash( $_COOKIE[ $poll_cookie ] ) ) ) );
- $cookie_expire = $cookie_value . ' +' . $duration . ' ' . $interval;
- $current_date = date_i18n( 'Y-m-d H:i:s' );
- if ( strtotime( $current_date ) < strtotime( $cookie_expire ) ) {
+ $cookie_value = sanitize_text_field( wp_unslash( $_COOKIE[ $poll_cookie ] ) );
+ $voted_at = (int) $cookie_value;
+ // If the cookie is invalid, block voting until it expires.
+ if ( ! hash_equals( $this->get_vote_cookie_value( $voted_at ), $cookie_value ) ) {
+ return false;
+ }
+ if ( time() < strtotime( '+' . $duration . ' ' . $interval, $voted_at ) ) {
return false;
} else {
return true;
@@ -201,6 +204,18 @@
/**
+ * Get the signed vote cookie value.
+ *
+ * @since 1.59.0
+ *
+ * @param int $voted_at Vote timestamp.
+ * @return string
+ */
+ public function get_vote_cookie_value( $voted_at ) {
+ return $voted_at . '|' . wp_hash( 'forminator_poll_vote_' . $this->id . '|' . $voted_at );
+ }
+
+ /**
* Check user can vote by user IP
*
* @return bool
--- a/forminator/library/modules/custom-forms/front/front-action.php
+++ b/forminator/library/modules/custom-forms/front/front-action.php
@@ -828,10 +828,12 @@
}
// Ignore CAPTCHA re-check (only for the v2 checkbox option) during two-factor authentication.
+ // The login token proves the CAPTCHA already passed.
if ( isset( self::$prepared_data['g-recaptcha-response'] )
&& isset( self::$module_settings['form-type'] ) && 'login' === self::$module_settings['form-type']
&& ! empty( self::$prepared_data['auth_method'] )
- && 'v2_checkbox' === self::$info['captcha_settings']['captcha_type'] ) {
+ && 'v2_checkbox' === self::$info['captcha_settings']['captcha_type']
+ && Forminator_CForm_Front_User_Login::is_valid_two_fa_token( self::$module_settings, self::$info['field_data_array'], self::$prepared_data['auth_token'] ?? '' ) ) {
return '';
}
@@ -855,23 +857,23 @@
*
* @since 1.58.0
*
- * @param bool $require_token Whether a missing token should fail. Early amount updates
- * run before one exists and take no payment.
+ * @param bool $require_token Whether the captcha is checked. Amount updates outside the
+ * submission take no payment, so they are not.
*
* @return string Empty when the form has no captcha or the token is good, the error message otherwise.
*/
private static function verify_payment_captcha( $require_token = true ) {
- if ( empty( self::$info['captcha_settings'] ) ) {
+ if ( empty( self::$info['captcha_settings'] ) || ! $require_token ) {
return '';
}
$token = self::get_captcha_user_response();
if ( ! is_string( $token ) || '' === $token ) {
- return $require_token ? __( 'Captcha verification failed. Please try again.', 'forminator' ) : '';
+ return __( 'Captcha verification failed. Please try again.', 'forminator' );
}
- $cache_key = 'forminator_captcha_' . md5( self::$module_id . '|' . $token );
+ $cache_key = self::get_payment_captcha_cache_key( $token );
$cached = get_transient( $cache_key );
if ( false !== $cached ) {
@@ -887,6 +889,37 @@
}
/**
+ * Get the cache key of a payment captcha verdict.
+ *
+ * @since 1.58.5
+ *
+ * @param string $token Captcha token.
+ *
+ * @return string
+ */
+ private static function get_payment_captcha_cache_key( $token ) {
+ return 'forminator_captcha_' . md5( self::$module_id . '|' . $token );
+ }
+
+ /**
+ * Use up the cached payment captcha verdict once it let a submission through.
+ *
+ * @since 1.58.5
+ *
+ * @return void
+ */
+ private static function consume_payment_captcha() {
+ if ( empty( self::$info['captcha_settings'] ) || self::$is_draft ) {
+ return;
+ }
+
+ $token = self::get_captcha_user_response();
+ if ( is_string( $token ) && '' !== $token ) {
+ delete_transient( self::get_payment_captcha_cache_key( $token ) );
+ }
+ }
+
+ /**
* Check if field is in $hidden_fields array
*
* @param string $field Field slug excluding the iterator.
@@ -2158,11 +2191,14 @@
if ( false === $event_data['is_session'] || ( 'paid' === $session->payment_status || 'no_payment_required' === $session->payment_status ) ) {
if ( self::$is_leads ) {
- // Update the entry status to active.
- if ( $entry->update_status( 'active' ) ) {
- self::fire_checkout_after_stripe_charge( $stripe_data );
+ // Update the entry status to active, if not already processed.
+ if ( ! $entry->update_status( 'active', 'pending' ) ) {
+ // Already processed, nothing to retry.
+ return 'pending' !== $entry->status;
}
+ self::fire_checkout_after_stripe_charge( $stripe_data );
+
// Process integrated add-ons and emails for quizzes.
$form_action = new Forminator_Quiz_Front_Action();
$form_action->run_post_submission_process( $entry );
@@ -2206,11 +2242,14 @@
}
}
- // Update the entry status to active.
- if ( $entry->update_status( 'active' ) ) {
- self::fire_checkout_after_stripe_charge( $stripe_data );
+ // Update the entry status to active, if not already processed.
+ if ( ! $entry->update_status( 'active', 'pending' ) ) {
+ // Already processed, nothing to retry.
+ return 'pending' !== $entry->status;
}
+ self::fire_checkout_after_stripe_charge( $stripe_data );
+
// Update hidden fields with submission ID if they exist in the prepared data.
$this->maybe_update_hidden_fields( $entry );
@@ -2327,8 +2366,11 @@
// Update stripe data in entry meta.
$this->update_stripe_meta( $entry, $stripe_data );
}
- // Update the entry status to failed.
- $entry->update_status( 'failed' );
+ // Update the entry status to failed, if not already processed.
+ if ( ! $entry->update_status( 'failed', 'pending' ) ) {
+ // Already processed, nothing to retry.
+ return 'pending' !== $entry->status;
+ }
// Remove the user registration data from entry fields, as the payment failed and it is no longer needed.
if ( isset( self::$module_settings['form-type'] ) && 'registration' === self::$module_settings['form-type'] ) {
@@ -2876,6 +2918,9 @@
$response = self::get_response( $entry );
$response['entry_id'] = absint( $entry->entry_id );
+ // A solved captcha lets one submission through.
+ self::consume_payment_captcha();
+
// If is lead, and storing in database is disabled, then store the $entry object temporarily in transient.
if ( self::$is_leads && self::prevent_store() && 0 === $response['entry_id'] ) {
$random_id = uniqid( $entry->form_id . '_' );
@@ -3946,6 +3991,19 @@
if ( true === self::$is_fields_visibility_checked ) {
return;
}
+
+ // Never trust a client-supplied post image; it is set from the uploaded file.
+ foreach ( array_keys( self::$prepared_data ) as $key ) {
+ if ( 0 !== strpos( (string) $key, 'postdata-' ) ) {
+ continue;
+ }
+ if ( false !== strpos( $key, '-post-image' ) ) {
+ unset( self::$prepared_data[ $key ] );
+ } elseif ( is_array( self::$prepared_data[ $key ] ) ) {
+ unset( self::$prepared_data[ $key ]['post-image'] );
+ }
+ }
+
$fields = self::$module_object->get_fields();
$visible_fields = array(); // Visible fields with calculable values.
$unspecified = array(); // it's not clear these fields are hidden or visible.
@@ -4959,7 +5017,11 @@
// Must guarantee alphanumeric.
$draft_id = wp_rand( 0, 9 );
$draft_id .= substr( str_shuffle( 'abcdefghijklmnopqrstvwxyz' ), 0, 1 );
- $draft_id .= substr( str_replace( '-', '', wp_generate_uuid4() ), 0, 10 );
+ // Use secure random characters, as the ID is the only key to the draft.
+ $chars = 'abcdefghijklmnopqrstuvwxyz0123456789';
+ for ( $i = 0; $i < 10; $i++ ) {
+ $draft_id .= $chars[ wp_rand( 0, 35 ) ];
+ }
return apply_filters( 'forminator_create_draft_id', $draft_id, $form_id );
}
--- a/forminator/library/modules/custom-forms/front/front-assets.php
+++ b/forminator/library/modules/custom-forms/front/front-assets.php
@@ -59,10 +59,9 @@
$this->load_phone_scripts();
}
- // FIELD: HTML.
- if ( $render_obj->has_field_type( 'html' ) ) {
- self::load_dompurify_scripts();
- }
+ // HTML merge-tag output always goes through DOMPurify, including forms
+ // without an HTML field (rich-text drafts can inject merge-tag markup).
+ self::load_dompurify_scripts();
// FIELD: Date picker.
if ( $render_obj->has_field_type( 'date' ) ) {
--- a/forminator/library/modules/custom-forms/front/front-render.php
+++ b/forminator/library/modules/custom-forms/front/front-render.php
@@ -704,9 +704,10 @@
// Ensure TinyMCE toolbar and WP link dialog appear above
// modal/popup overlays by setting a high z-index.
+ // .ui-autocomplete is the link search list, appended to body.
wp_add_inline_style(
'buttons',
- 'div.mce-inline-toolbar-grp, #wp-link-wrap { z-index: 999991 !important; }'
+ 'div.mce-inline-toolbar-grp, #wp-link-wrap, .ui-autocomplete { z-index: 999991 !important; }'
);
}
@@ -3083,6 +3084,13 @@
}
$has_stripe = $this->has_stripe();
+ $form_field_ids = array();
+ foreach ( $this->get_fields() as $form_field ) {
+ if ( ! empty( $form_field['element_id'] ) ) {
+ $form_field_ids[] = $form_field['element_id'];
+ }
+ }
+
$options = array(
'form_type' => $this->get_form_type(),
'inline_validation' => filter_var( $form_properties['inline_validation'], FILTER_VALIDATE_BOOLEAN ),
@@ -3098,6 +3106,7 @@
'pagination_config' => $form_properties['pagination'],
'paypal_config' => $form_properties['paypal_payment'],
'forminator_fields' => Forminator_Core::get_field_types(),
+ 'form_field_ids' => $form_field_ids,
'general_messages' => array(
'calculation_error' => Forminator_Calculation::default_error_message(),
'payment_require_ssl_error' => apply_filters(
--- a/forminator/library/modules/custom-forms/front/front-user-login.php
+++ b/forminator/library/modules/custom-forms/front/front-user-login.php
@@ -170,16 +170,17 @@
$two_fa_component = new $defender_data['two_fa_component']();
if ( ! is_wp_error( $sign_on ) ) {
$available_providers = $two_fa_component->get_available_providers_for_user( $sign_on );
- $token = uniqid();
- // create and store a login token so we can query this user again.
- update_user_meta( $sign_on->ID, 'defender_two_fa_token', $token );
- $enable_otp = $two_fa_component->is_user_enabled_otp( $sign_on->ID );
+ $enable_otp = $two_fa_component->is_user_enabled_otp( $sign_on->ID );
if ( $enable_otp && ! empty( $available_providers ) ) {
$auth_method = isset( Forminator_CForm_Front_Action::$prepared_data['auth_method'] ) ? Forminator_CForm_Front_Action::$prepared_data['auth_method'] : '';
if ( empty( $auth_method ) ) {
$auth_method = $two_fa_component->get_default_provider_slug_for_user( $sign_on->ID );
}
if ( ! isset( Forminator_CForm_Front_Action::$prepared_data['auth_method'] ) ) {
+ // Store a short-lived login token for the 2FA step.
+ $token = wp_generate_password( 32, false );
+ set_transient( self::get_two_fa_token_key( $sign_on->ID ), $token, 10 * MINUTE_IN_SECONDS );
+
$response['authentication'] = 'show';
$response['user'] = $sign_on;
$response['username'] = $sign_on->user_login;
@@ -193,7 +194,7 @@
if ( ! is_wp_error( $provider ) ) {
$result = $provider->validate_authentication( $sign_on );
if ( ! empty( $result ) && ! is_wp_error( $result ) ) {
- delete_user_meta( $sign_on->ID, 'defender_two_fa_token' );
+ delete_transient( self::get_two_fa_token_key( $sign_on->ID ) );
$response['authentication'] = 'valid';
} else {
$response['authentication'] = 'invalid';
@@ -260,6 +261,55 @@
}
/**
+ * Check the 2FA login token issued to the submitted user.
+ *
+ * @since 1.58.5
+ *
+ * @param array $settings Form settings.
+ * @param array $field_data_array Field data.
+ * @param string $token Submitted login token.
+ *
+ * @return bool
+ */
+ public static function is_valid_two_fa_token( $settings, $field_data_array, $token ) {
+ if ( empty( $settings['login-username-field'] ) || ! is_string( $token ) || '' === $token ) {
+ return false;
+ }
+
+ // Same value the sign on uses.
+ $values = array_column( $field_data_array, 'value', 'name' );
+ $username = $values[ $settings['login-username-field'] ] ?? '';
+ if ( ! is_string( $username ) || '' === $username ) {
+ return false;
+ }
+
+ $user = get_user_by( 'login', $username );
+ if ( ! $user && is_email( $username ) ) {
+ $user = get_user_by( 'email', $username );
+ }
+ if ( ! $user ) {
+ return false;
+ }
+
+ $stored = get_transient( self::get_two_fa_token_key( $user->ID ) );
+
+ return is_string( $stored ) && '' !== $stored && hash_equals( $stored, $token );
+ }
+
+ /**
+ * Get the transient key of a user's 2FA login token.
+ *
+ * @since 1.58.5
+ *
+ * @param int $user_id User ID.
+ *
+ * @return string
+ */
+ private static function get_two_fa_token_key( $user_id ) {
+ return 'forminator_two_fa_token_' . $user_id;
+ }
+
+ /**
* Check the credentials in process_login() without signing on.
*
* @since 1.58.4
--- a/forminator/library/modules/polls/front/front-action.php
+++ b/forminator/library/modules/polls/front/front-action.php
@@ -454,8 +454,9 @@
break;
}
}
- $current_date = date_i18n( 'Y-m-d H:i:s' );
+ // Sign the vote time to prevent tampering.
+ $cookie_value = $poll->get_vote_cookie_value( time() );
$secure = ( 'https' === wp_parse_url( wp_login_url(), PHP_URL_SCHEME ) );
- setcookie( $cookie_name, $current_date, $expire, COOKIEPATH, COOKIE_DOMAIN, $secure, true );
+ setcookie( $cookie_name, $cookie_value, $expire, COOKIEPATH, COOKIE_DOMAIN, $secure, true );
}
}
--- a/forminator/library/modules/quizzes/front/front-action.php
+++ b/forminator/library/modules/quizzes/front/front-action.php
@@ -688,12 +688,26 @@
$wrong_counter = 0;
$index_counter = 0; // We need this because $id is not an index.
+ $valid_answer_keys = ! empty( $question['answers'] ) ? array_keys( $question['answers'] ) : array();
foreach ( $user_answers as $id => $pick ) {
$question_id = preg_replace( '/(-d+$)/', '', $id );
if ( $question_slug !== $question_id ) {
continue; }
+ // Check if the picked answer is valid for the current question.
+ // If it is, remove it from the list of valid answers to prevent duplicates.
+ if ( is_scalar( $pick ) && in_array( intval( $pick ), $valid_answer_keys, true ) ) {
+ $key = array_search( intval( $pick ), $valid_answer_keys, true );
+ unset( $valid_answer_keys[ $key ] );
+ } else {
+ wp_send_json_error(
+ array(
+ 'error' => apply_filters( 'forminator_quizzes_process_knowledge_submit_invalid_answer_error', esc_html__( 'Invalid answer.', 'forminator' ) ),
+ )
+ );
+ }
+
$is_correct = $model->is_correct_answer_for_question( $question_id, $pick );
$user_answer = $model->getAnswer( $question_id, $pick );