Below is a differential between the unpatched vulnerable code and the patched update, for reference.
--- a/cf7-multi-step/cf7-multi-step.php
+++ b/cf7-multi-step/cf7-multi-step.php
@@ -4,7 +4,7 @@
* Plugin Name: Multi Step for Contact Form 7 (Lite)
* Plugin URI: https://ninjateam.org/contact-form-7-multi-step/
* Description: Break your long form into user-friendly steps.
- * Version: 2.9.1
+ * Version: 2.9.2
* Author: NinjaTeam
* Author URI: http://ninjateam.org
* Text Domain: cf7-multi-step
@@ -35,7 +35,7 @@
define( 'CF7MLS_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
}
if ( ! defined( 'CF7MLS_NTA_VERSION' ) ) {
- define( 'CF7MLS_NTA_VERSION', '2.9.1' );
+ define( 'CF7MLS_NTA_VERSION', '2.9.2' );
}
spl_autoload_register(
@@ -60,6 +60,26 @@
if ( ! function_exists( 'cf7mls_plugin_init' ) ) {
function cf7mls_plugin_init() {
+ if ( ! class_exists( 'WPCF7' ) ) {
+ add_action( 'admin_notices', function() {
+ ?>
+ <div class="notice notice-error">
+ <p>
+ <?php
+ printf(
+ /* translators: 1: Contact Form 7, 2: Contact Form 7 Multi Step */
+ esc_html__( 'Please activate %1$s to use %2$s.', 'cf7-multi-step' ),
+ '<strong>Contact Form 7</strong>',
+ '<strong>Contact Form 7 Multi Step</strong>'
+ );
+ ?>
+ </p>
+ </div>
+ <?php
+ } );
+ return;
+ }
+
// language load text domain
require_once plugin_dir_path( __FILE__ ) . 'inc/I18n.php';
// CF7DB
--- a/cf7-multi-step/inc/cf7db.php
+++ b/cf7-multi-step/inc/cf7db.php
@@ -9,7 +9,7 @@
if ( cf7mls_is_active_cf7db() ) {
add_filter( 'cf7d_no_save_fields', 'cf7mls_cf7d_no_save_fields' );
function cf7mls_cf7d_no_save_fields( $fields ) {
- // $fields[] = '_cf7mls_db_form_data_id';
+ $fields[] = '_cf7mls_db_form_data_id';
$fields[] = '_wpnonce';
$fields[] = 'cf7mls_back';
$fields[] = 'cf7mls_next';
@@ -23,9 +23,13 @@
add_action( 'cf7d_after_insert_db', 'cf7mls_cf7d_after_insert_db', 10, 3 );
function cf7mls_cf7d_after_insert_db( $contact_form, $form_id, $data_id ) {
global $wpdb;
- $data_id_be_delete = $wpdb->get_results( 'SELECT `value` FROM ' . $wpdb->prefix . "cf7_data_entry WHERE `cf7_id` = '" . $form_id . "' AND `name` = '_cf7mls_db_form_data_id'" );
+ $data_id_be_delete = $wpdb->get_results( $wpdb->prepare( "SELECT `value` FROM {$wpdb->prefix}cf7_data_entry WHERE `cf7_id` = %d AND `name` = %s", (int) $form_id, '_cf7mls_db_form_data_id' ) );
if ( isset( $data_id_be_delete[0] ) ) {
- $data_id_be_delete = $data_id_be_delete[0]->value;
+ $data_id_be_delete = (int) $data_id_be_delete[0]->value;
+ $owns = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->prefix}cf7_data_entry WHERE `cf7_id` = %d AND `data_id` = %d", (int) $form_id, $data_id_be_delete ) );
+ if ( ! $owns ) {
+ return;
+ }
// delele data_id
$wpdb->delete( $wpdb->prefix . 'cf7_data', array( 'id' => $data_id_be_delete ) );
// delete entry
--- a/cf7-multi-step/inc/frontend/init.php
+++ b/cf7-multi-step/inc/frontend/init.php
@@ -147,6 +147,19 @@
return $code;
}
+add_filter( 'wpcf7_form_class_attr', 'cf7mls_add_multistep_class' );
+/**
+ * Mark forms that use steps, so the frontend CSS leaves all other forms alone.
+ * Added server-side so the styles apply before the frontend script runs.
+ */
+function cf7mls_add_multistep_class( $class ) {
+ $contact_form = wpcf7_get_current_contact_form();
+ if ( $contact_form && $contact_form->scan_form_tags( array( 'type' => array( 'cf7mls_step', 'cf7mls_step*' ) ) ) ) {
+ $class .= ' cf7mls';
+ }
+ return $class;
+}
+
add_filter( 'wpcf7_form_class_attr', 'cf7mls_add_auto_scroll_class' );
function cf7mls_add_auto_scroll_class( $class ) {
if ( $contact_form = wpcf7_get_current_contact_form() ) {
--- a/cf7-multi-step/inc/frontend/validation.php
+++ b/cf7-multi-step/inc/frontend/validation.php
@@ -103,6 +103,12 @@
if ( cf7mls_is_active_cf7db() ) {
if ( get_post_meta( $id, '_cf7mls_db_save_every_step', true ) == 'yes' ) {
$_cf7mls_db_form_data_id = ( isset( $_POST['_cf7mls_db_form_data_id'] ) ? intval( $_POST['_cf7mls_db_form_data_id'] ) : '' );
+ if ( ! empty( $_cf7mls_db_form_data_id ) ) {
+ $owns = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->prefix}cf7_data_entry WHERE `cf7_id` = %d AND `data_id` = %d AND `name` = %s", (int) $id, (int) $_cf7mls_db_form_data_id, '_cf7mls_db_form_data_id' ) );
+ if ( ! $owns ) {
+ $_cf7mls_db_form_data_id = '';
+ }
+ }
if ( empty( $_cf7mls_db_form_data_id ) ) {
$wpdb->insert( $wpdb->prefix . 'cf7_data', array( 'created' => date( 'Y-m-d H:i:s' ) ), array( '%s' ) );
$_cf7mls_db_form_data_id = $wpdb->insert_id;
@@ -128,7 +134,9 @@
$posted_data = $_POST;
$posted_data = $this->cf7mls_cf7d_add_more_fields( $posted_data );
+ $allowed_names = array( 'submit_time', 'submit_ip', 'submit_user_id' );
foreach ( $tags as $k => $v ) {
+ $allowed_names[] = $v['name'];
if ( isset( $posted_data[ $v['name'] ] ) ) {
$posted_data[ $v['name'] ] = $this->cf7mls_sanitize_posted_data( $posted_data[ $v['name'] ] );
} else {
@@ -138,6 +146,9 @@
// install to database
$cf7d_no_save_fields = cf7d_no_save_fields();
foreach ( $posted_data as $k => $v ) {
+ if ( ! in_array( $k, $allowed_names, true ) ) {
+ continue;
+ }
if ( in_array( $k, $cf7d_no_save_fields ) ) {
continue;
} else {
@@ -218,7 +229,7 @@
$contact_form->validate_schema(
array(
'text' => true,
- 'file' => false,
+ 'file' => version_compare( WPCF7_VERSION, '6.2', '>=' ),
'field' => array(),
),
$result
@@ -240,7 +251,7 @@
$this->invalid_fields = $result->get_invalid_fields();
- $upload_files = $this->unship_uploaded_files( $contact_form );
+ $upload_files = $this->unship_uploaded_files( $contact_form, $result );
$success = false;
$this->invalid_fields = array_merge( $this->invalid_fields, $upload_files['invalid_fields'] );
if ( false === $result->is_valid() ) {
@@ -266,6 +277,12 @@
if ( cf7mls_is_active_cf7db() ) {
if ( get_post_meta( $id, '_cf7mls_db_save_every_step', true ) == 'yes' ) {
$_cf7mls_db_form_data_id = ( isset( $_POST['_cf7mls_db_form_data_id'] ) ? intval( $_POST['_cf7mls_db_form_data_id'] ) : '' );
+ if ( ! empty( $_cf7mls_db_form_data_id ) ) {
+ $owns = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->prefix}cf7_data_entry WHERE `cf7_id` = %d AND `data_id` = %d AND `name` = %s", (int) $id, (int) $_cf7mls_db_form_data_id, '_cf7mls_db_form_data_id' ) );
+ if ( ! $owns ) {
+ $_cf7mls_db_form_data_id = '';
+ }
+ }
if ( empty( $_cf7mls_db_form_data_id ) ) {
$wpdb->insert( $wpdb->prefix . 'cf7_data', array( 'created' => date( 'Y-m-d H:i:s' ) ), array( '%s' ) );
$_cf7mls_db_form_data_id = $wpdb->insert_id;
@@ -291,7 +308,9 @@
$posted_data = $_POST;
$posted_data = $this->cf7mls_cf7d_add_more_fields( $posted_data );
+ $allowed_names = array( 'submit_time', 'submit_ip', 'submit_user_id' );
foreach ( $tags as $k => $v ) {
+ $allowed_names[] = $v['name'];
if ( isset( $posted_data[ $v['name'] ] ) ) {
$posted_data[ $v['name'] ] = $this->cf7mls_sanitize_posted_data( $posted_data[ $v['name'] ] );
} else {
@@ -301,6 +320,9 @@
// install to database
$cf7d_no_save_fields = cf7d_no_save_fields();
foreach ( $posted_data as $k => $v ) {
+ if ( ! in_array( $k, $allowed_names, true ) ) {
+ continue;
+ }
if ( in_array( $k, $cf7d_no_save_fields ) ) {
continue;
} else {
@@ -364,7 +386,7 @@
}
return $posted_data;
}
- private function unship_uploaded_files( $contact_form ) {
+ private function unship_uploaded_files( $contact_form, $schema_result ) {
$file_result = new WPCF7_Validation();
$file_tags = $contact_form->scan_form_tags(
@@ -374,7 +396,7 @@
);
foreach ( $file_tags as $tag ) {
- if ( empty( $_FILES[ $tag->name ] ) ) {
+ if ( empty( $_FILES[ $tag->name ] ) || ! $schema_result->is_valid( $tag->name ) ) {
continue;
}
$file = $_FILES[ $tag->name ];
@@ -393,12 +415,13 @@
$args['schema'] = $contact_form->get_schema();
}
- $new_files = wpcf7_unship_uploaded_file( $file, $args );
+ $new_files = array();
+ $unshipped = wpcf7_unship_uploaded_file( $file, $args, $new_files );
- if ( (float) WPCF7_VERSION >= 5.6 ) {
- if ( is_wp_error( $new_files ) ) {
- $file_result->invalidate( $tag, $new_files );
- }
+ if ( is_wp_error( $unshipped ) && (float) WPCF7_VERSION >= 5.6 ) {
+ $file_result->invalidate( $tag, $unshipped );
+ } elseif ( true !== $unshipped ) {
+ $new_files = $unshipped;
}
$file_result = apply_filters(