Below is a differential between the unpatched vulnerable code and the patched update, for reference.
--- a/ultimate-addons-for-contact-form-7/addons/database/database.php
+++ b/ultimate-addons-for-contact-form-7/addons/database/database.php
@@ -876,6 +876,9 @@
if ( ! file_exists( $uacf7_dirname ) ) {
wp_mkdir_p( $uacf7_dirname );
}
+ if ( function_exists( 'uacf7_protect_uploads_directory' ) ) {
+ uacf7_protect_uploads_directory( $uacf7_dirname );
+ }
// CF7 already validates and normalizes uploaded files for the current submission.
foreach ( $files as $file_key => $file ) {
@@ -892,12 +895,15 @@
continue;
}
- $dir_link = '/uacf7-uploads/' . $time_now . '-' . $file_key;
+ $filename = wp_basename( $file );
+ $ext = strtolower( pathinfo( $filename, PATHINFO_EXTENSION ) );
+ $ext_part = ! empty( $ext ) ? '.' . sanitize_key( $ext ) : '';
if ( in_array( $file_key, $uacf7_signature_tag ) ) {
$dir_link = '/uacf7-uploads/' . $time_now . '-' . $file_key . '.enc';
$this->encrypt_file( $file, $dir . $dir_link, $encryptionKey );
} else {
+ $dir_link = '/uacf7-uploads/' . $time_now . '-' . $file_key . $ext_part;
copy( $file, $dir . $dir_link );
}
array_push( $data_file, [ $file_key => $dir_link ] );
--- a/ultimate-addons-for-contact-form-7/addons/pdf-generator/pdf-generator.php
+++ b/ultimate-addons-for-contact-form-7/addons/pdf-generator/pdf-generator.php
@@ -389,7 +389,8 @@
'format' => 'A4',
'margin_left' => 0,
'margin_right' => 0,
- 'margin_top' => 25
+ 'margin_top' => 25,
+ 'curlAllowUnsafeSslRequests' => false,
] );
@@ -567,11 +568,21 @@
}
$value = $data;
}
+ if ( ! in_array( $key, $uacf7_signature_tag ) && is_string( $value ) ) {
+ $value = $this->sanitize_pdf_template_value( $value );
+ }
$replace_value[] = $value;
}
// Repeater value
if ( ! empty( $repeaters ) && is_array( $repeaters ) ) {
$repeater_data = apply_filters( 'uacf7_pdf_generator_replace_data', $repeater_value, $repeaters, $customize_pdf );
+ if ( ! empty( $repeater_data['replace_re_value'] ) && is_array( $repeater_data['replace_re_value'] ) ) {
+ foreach ( $repeater_data['replace_re_value'] as $r_idx => $r_val ) {
+ if ( is_string( $r_val ) ) {
+ $repeater_data['replace_re_value'][ $r_idx ] = $this->sanitize_pdf_template_value( $r_val );
+ }
+ }
+ }
$customize_pdf = str_replace( $repeater_data['replace_re_key'], $repeater_data['replace_re_value'], $customize_pdf );
}
@@ -683,6 +694,7 @@
'margin_left' => 0,
'margin_right' => 0,
'margin_top' => 25,
+ 'curlAllowUnsafeSslRequests' => false,
] );
$replace_key = [];
@@ -805,6 +817,9 @@
}
$value = $data;
}
+ if ( is_string( $value ) ) {
+ $value = $this->sanitize_pdf_template_value( $value );
+ }
$replace_value[] = $value;
}
@@ -942,7 +957,13 @@
if ( is_array( $repeaters ) || is_object( $repeaters ) ) {
$repeater_data = apply_filters( 'uacf7_pdf_generator_replace_data', $repeater_value, $repeaters, $customize_pdf );
-
+ if ( ! empty( $repeater_data['replace_re_value'] ) && is_array( $repeater_data['replace_re_value'] ) ) {
+ foreach ( $repeater_data['replace_re_value'] as $r_idx => $r_val ) {
+ if ( is_string( $r_val ) ) {
+ $repeater_data['replace_re_value'][ $r_idx ] = $this->sanitize_pdf_template_value( $r_val );
+ }
+ }
+ }
$customize_pdf = str_replace( $repeater_data['replace_re_key'], $repeater_data['replace_re_value'], $customize_pdf );
}
}
@@ -978,6 +999,29 @@
}
+ /**
+ * Sanitize user-submitted form values before PDF template replacement.
+ * Neutralizes mPDF control markers, dangerous stream wrappers, and HTML/SVG markup.
+ *
+ * @param mixed $value
+ * @return string
+ */
+ public function sanitize_pdf_template_value( $value ) {
+ if ( ! is_string( $value ) ) {
+ return $value;
+ }
+
+ // 1. Strip mPDF internal object markers
+ $clean_val = str_replace( array( "xbbxa4xac", "xc2xbbxc2xa4xc2xac", '»¤¬' ), '', $value );
+ $clean_val = preg_replace( '/bobjattrs*=/i', '', $clean_val );
+
+ // 2. Strip dangerous stream wrappers and protocols (defense-in-depth against file read/SSRF)
+ $clean_val = preg_replace( '#(?::/)?(?:php|file|phar|data|expect|ftp)://#i', '', $clean_val );
+
+ // 3. Entity-encode HTML tags (Neutralizes <svg>, <image>, and arbitrary tags)
+ return esc_html( $clean_val );
+ }
+
public function makeLinksClickable($text) {
$pattern = '/(https?://[^s]+)/';
--- a/ultimate-addons-for-contact-form-7/inc/functions.php
+++ b/ultimate-addons-for-contact-form-7/inc/functions.php
@@ -1751,6 +1751,57 @@
return false;
}
+ /*
+ * Inspect text-based and ambiguous uploads for HTML and script signatures.
+ * Attackers can upload text files containing HTML event handlers like <BODY onload=...>
+ * which MIME-type detectors classify as text/plain.
+ */
+ $text_extensions = array( 'txt', 'csv', 'vtt', 'srt', 'asc' );
+ if ( in_array( $extension, $text_extensions, true ) || 0 === strpos( strtolower( $file_type['type'] ), 'text/' ) ) {
+ $handle = @fopen( $file, 'rb' );
+ if ( $handle ) {
+ $chunk = fread( $handle, 4096 );
+ fclose( $handle );
+ if ( false !== $chunk ) {
+ if ( preg_match( '/<s*(?:!doctype|html|head|body|script|svg|iframe|embed|object|?xml)/i', $chunk ) ||
+ preg_match( '/b(?:onload|onerror|onmouseover|autofocus)s*=/i', $chunk ) ) {
+ return false;
+ }
+ }
+ }
+ }
+
return true;
}
+}
+
+/**
+ * Hardens the UACF7 uploads directory against script execution and MIME sniffing.
+ *
+ * @param string $dir The absolute directory path.
+ */
+if ( ! function_exists( 'uacf7_protect_uploads_directory' ) ) {
+ function uacf7_protect_uploads_directory( $dir ) {
+ if ( empty( $dir ) || ! is_dir( $dir ) ) {
+ return;
+ }
+
+ // Prevent directory browsing with an empty index.php
+ $index_file = rtrim( $dir, '/\' ) . '/index.php';
+ if ( ! file_exists( $index_file ) ) {
+ @file_put_contents( $index_file, "<?phpn// Silence is golden.n" );
+ }
+
+ // Place an .htaccess to prevent MIME sniffing and force safe handling
+ $htaccess_file = rtrim( $dir, '/\' ) . '/.htaccess';
+ if ( ! file_exists( $htaccess_file ) ) {
+ $rules = "<IfModule mod_headers.c>n"
+ . "Header set X-Content-Type-Options "nosniff"n"
+ . "</IfModule>n"
+ . "<FilesMatch "\.(?i:txt|csv|vtt|srt|asc)$">n"
+ . "Header set Content-Disposition "attachment"n"
+ . "</FilesMatch>n";
+ @file_put_contents( $htaccess_file, $rules );
+ }
+ }
}
No newline at end of file
--- a/ultimate-addons-for-contact-form-7/third-party/vendor/mpdf/mpdf/src/File/StreamWrapperChecker.php
+++ b/ultimate-addons-for-contact-form-7/third-party/vendor/mpdf/mpdf/src/File/StreamWrapperChecker.php
@@ -21,15 +21,16 @@
*/
public function hasBlacklistedStreamWrapper($filename)
{
- if (strpos($filename, '://') > 0) {
+ if (strpos($filename, '://') !== false) {
$wrappers = stream_get_wrappers();
$whitelistStreamWrappers = $this->getWhitelistedStreamWrappers();
+ $normalized = ltrim($filename, ':/\ ');
foreach ($wrappers as $wrapper) {
if (in_array($wrapper, $whitelistStreamWrappers)) {
continue;
}
- if (stripos($filename, $wrapper . '://') === 0) {
+ if (stripos($filename, $wrapper . '://') === 0 || stripos($normalized, $wrapper . '://') === 0) {
return true;
}
}
--- a/ultimate-addons-for-contact-form-7/third-party/vendor/mpdf/mpdf/src/Mpdf.php
+++ b/ultimate-addons-for-contact-form-7/third-party/vendor/mpdf/mpdf/src/Mpdf.php
@@ -9110,7 +9110,7 @@
$sp[$v[0]] = trim($v[1], Mpdf::OBJECT_IDENTIFIER);
}
- return (unserialize($sp['objattr']));
+ return (unserialize($sp['objattr'], array('allowed_classes' => false)));
}
function inlineObject($type, $x, $y, $objattr, $Lmargin, $widthUsed, $maxWidth, $lineHeight, $paint = false, $is_table = false)
--- a/ultimate-addons-for-contact-form-7/ultimate-addons-for-contact-form-7.php
+++ b/ultimate-addons-for-contact-form-7/ultimate-addons-for-contact-form-7.php
@@ -3,7 +3,7 @@
* Plugin Name: Ultra Addons for Contact Form 7
* Plugin URI: https://cf7addons.com/
* Description: 50+ Essential Addons for Contact Form 7 - Conditional Fields, Multi Step Forms, Redirection, Form Templates, Columns, WooCommerce, Mailchimp and more, all in one.
- * Version: 3.5.54
+ * Version: 3.5.55
* Author: Themefic
* Author URI: https://themefic.com/
* License: GPL-2.0+
@@ -30,7 +30,7 @@
define( 'UACF7_URL', plugin_dir_url( __FILE__ ) );
define( 'UACF7_ADDONS', UACF7_URL . 'addons' );
define( 'UACF7_PATH', plugin_dir_path( __FILE__ ) );
- define( 'UACF7_VERSION', '3.5.54' );
+ define( 'UACF7_VERSION', '3.5.55' );
/*
* ---------------------------------------------------------