Below is a differential between the unpatched vulnerable code and the patched update, for reference.
--- a/tablesome/includes/actions.php
+++ b/tablesome/includes/actions.php
@@ -980,11 +980,16 @@
'get_access_token' => get_rest_url( null, 'tablesome/v1/workflow/get-access-token' ),
'get-spreadsheet-data' => get_rest_url( null, 'tablesome/v1/workflow/get-spreadsheet-data' ),
'hubspot_deal_pipelines' => get_rest_url( null, 'tablesome/v1/workflow/get-hubspot-deal-pipelines' ),
+ 'hubspot_deal_properties' => get_rest_url( null, 'tablesome/v1/workflow/get-hubspot-deal-properties' ),
'oauth_status' => get_rest_url( null, 'tablesome/v1/oauth/status' ),
'oauth_status_by_integration' => get_rest_url( null, 'tablesome/v1/oauth/status/' ),
'oauth_refresh' => get_rest_url( null, 'tablesome/v1/oauth/refresh/' ),
'oauth_health_check' => get_rest_url( null, 'tablesome/v1/oauth/health-check' ),
),
+ 'feature_flags' => array(
+ 'hubspot_upsert_deal' => pauple_is_feature_active( 'hubspot_upsert_deal' ),
+ ),
+ 'smart_fields' => ( function_exists( 'get_tablesome_action_smart_fields' ) ? get_tablesome_action_smart_fields() : array() ),
"site_domain" => $_SERVER['SERVER_NAME'],
);
// Use the redirect token that was generated and set as a cookie
--- a/tablesome/includes/functions.php
+++ b/tablesome/includes/functions.php
@@ -446,6 +446,30 @@
}
}
+/**
+ * Source of truth for the smart-fields list shown in workflow-action
+ * source dropdowns. Mirrors the runtime values produced by
+ * get_tablesome_smart_field_values(). Pipe this into tablesome_ajax_object
+ * so each Svelte action consumes one shared list rather than its own
+ * hardcoded copy (Conventions §18).
+ *
+ * @return array[] {
+ * @type string $id Runtime value key (matches get_tablesome_smart_field_values()).
+ * @type string $label Human label.
+ * }
+ */
+if (!function_exists('get_tablesome_action_smart_fields')) {
+ function get_tablesome_action_smart_fields()
+ {
+ return array(
+ array('id' => 'created_at_datetime', 'label' => 'Submission Date'),
+ array('id' => 'created_by', 'label' => 'Current User'),
+ array('id' => 'page_source_url', 'label' => 'Page Source URL'),
+ array('id' => 'ip_address', 'label' => 'IP Address'),
+ );
+ }
+}
+
if (!function_exists('get_tablesome_smart_field_info_by_field_name')) {
function get_tablesome_smart_field_info_by_field_name($field_name)
{
--- a/tablesome/includes/modules/tablesomedb-rest-api/routes.php
+++ b/tablesome/includes/modules/tablesomedb-rest-api/routes.php
@@ -282,6 +282,15 @@
'permission_callback' => array($tablesome_db, 'api_backend_permission'),
),
),
+ /** HubSpot deal properties catalogue for Create Deal action UI */
+ array(
+ 'url' => '/workflow/get-hubspot-deal-properties',
+ 'args' => array(
+ 'methods' => WP_REST_Server::READABLE,
+ 'callback' => array($workflow_api, 'get_hubspot_deal_properties'),
+ 'permission_callback' => array($tablesome_db, 'api_backend_permission'),
+ ),
+ ),
array(
'url' => '/workflow/get-spreadsheet-data',
'args' => array(
--- a/tablesome/includes/modules/tablesomedb-rest-api/tablesomedb-rest-api.php
+++ b/tablesome/includes/modules/tablesomedb-rest-api/tablesomedb-rest-api.php
@@ -74,19 +74,17 @@
public function api_nonce_check($request)
{
- // error_log('api_nonce_check()');
$params = $request->get_params();
- // error_log('api_nonce_check() params: ' . print_r($params, true));
$nonce = isset($params['client_wp_nonce']) ? $params['client_wp_nonce'] : '';
-
- // Check nonce
+
$stored_nonce = get_transient('tablesome_workflow_nonce');
-
- // error_log('api_nonce_check() verified: ' . $verified);
+
if (!empty($nonce) && $stored_nonce == $nonce) {
- // error_log('api_access_permission() nonce verified');
+ // Single-use: invalidate immediately so the same redirect
+ // URL cannot be replayed within the transient TTL.
+ delete_transient('tablesome_workflow_nonce');
return true;
- }
+ }
$error_code = "UNAUTHORIZED";
return new WP_Error($error_code, $this->get_error_message($error_code));
}
@@ -660,6 +658,10 @@
}
// CRUD Records (update table records)
+ if (isset($params['origin_location']) && !isset($params['recordsData']['origin_location'])) {
+ $params['recordsData']['origin_location'] = $params['origin_location'];
+ }
+
$params['recordsData']['table_id'] = $params['table_id'];
$update_result = $this->update_table_records($params['recordsData']);
--- a/tablesome/includes/modules/tablesomedb-rest-api/workflow-rest-api.php
+++ b/tablesome/includes/modules/tablesomedb-rest-api/workflow-rest-api.php
@@ -450,18 +450,30 @@
$connector_domain = tablesome_get_connector_domain($integration);
$connector_url = $connector_domain . "/wp-json/tablesome-connector/v1/oauth/install?integration=" . $integration;
$client_redirect_url = get_rest_url(null, 'tablesome/v1/workflow/set-oauth-data');
- $client_redirect_url = $pluginator_security_agent->add_query_arg(array('integration' => $integration), $client_redirect_url, 'raw');
$wp_nonce = wp_create_nonce('tablesome_workflow_nonce');
// Store in transient for 5 minutes
set_transient('tablesome_workflow_nonce', $wp_nonce, 5 * 60);
-
+
+ // Embed client_wp_nonce inside client_redirect_url so the value
+ // survives the connector's redirect leg as a normal preserved
+ // URL parameter — independent of whether the connector
+ // forwards `wp_nonce` separately.
+ $client_redirect_url = $pluginator_security_agent->add_query_arg(array(
+ 'integration' => $integration,
+ 'client_wp_nonce' => $wp_nonce,
+ ), $client_redirect_url, 'raw');
+
$connector_url = $pluginator_security_agent->add_query_arg(array('wp_nonce' => $wp_nonce), $connector_url, 'raw');
- // Should be last
- $connector_url = $pluginator_security_agent->add_query_arg(array('client_redirect_url' => $client_redirect_url), $connector_url, 'raw');
+ // urlencode so the embedded URL's own `?` and `&` separators are
+ // not parsed as outer-level query args by the connector. WordPress's
+ // add_query_arg does NOT URL-encode the values of newly added args,
+ // so without this the connector receives a truncated client_redirect_url
+ // and any embedded params (including client_wp_nonce) leak to the
+ // outer query and never make the round trip back.
+ $connector_url = $pluginator_security_agent->add_query_arg(array('client_redirect_url' => urlencode($client_redirect_url)), $connector_url, 'raw');
- // error_log('get_oauth_redirect_url $connector_url: ' . print_r($connector_url, true));
return $connector_url;
}
@@ -504,6 +516,23 @@
]);
}
+ /**
+ * REST handler: GET /workflow/get-hubspot-deal-properties
+ *
+ * Called by the Create Deal action Svelte UI to populate the
+ * deal-property destination Select. Same degrade-to-empty contract
+ * as get_hubspot_deal_pipelines.
+ */
+ public function get_hubspot_deal_properties($request)
+ {
+ $properties = $this->library->integrations['hubspot']->hubspot_api->get_deal_properties();
+ return rest_ensure_response([
+ 'status' => 'success',
+ 'message' => 'Successfully fetched HubSpot deal properties.',
+ 'data' => is_array($properties) ? $properties : [],
+ ]);
+ }
+
public function get_sheets_by_spreadsheet_id($request)
{
$params = $request->get_query_params();
--- a/tablesome/includes/modules/upload-file-validator.php
+++ b/tablesome/includes/modules/upload-file-validator.php
@@ -0,0 +1,155 @@
+<?php
+
+namespace TablesomeIncludesModules;
+
+if (!defined('ABSPATH')) {
+ exit;
+}
+
+if (!class_exists('TablesomeIncludesModulesUpload_File_Validator')) {
+ class Upload_File_Validator
+ {
+ protected $dangerous_extensions = array(
+ 'php',
+ 'php3',
+ 'php4',
+ 'php5',
+ 'php7',
+ 'phtml',
+ 'phar',
+ 'cgi',
+ 'pl',
+ 'py',
+ 'rb',
+ 'asp',
+ 'aspx',
+ 'jsp',
+ 'sh',
+ 'bash',
+ 'zsh',
+ 'ksh',
+ 'csh',
+ 'ps1',
+ 'bat',
+ 'cmd',
+ 'com',
+ 'exe',
+ 'dll',
+ 'so',
+ 'dylib',
+ 'scr',
+ 'msi',
+ 'jar',
+ 'class',
+ 'swf',
+ 'htm',
+ 'html',
+ 'js',
+ );
+
+ public function validate($file, $filename, $args = array())
+ {
+ if (!file_exists($file) || !is_readable($file)) {
+ return new WP_Error('tablesome_upload_file_not_accessible', __('Source file is not accessible.', 'tablesome'));
+ }
+
+ $safe_filename = sanitize_file_name($filename);
+ if (empty($safe_filename)) {
+ return new WP_Error('tablesome_upload_empty_filename', __('Filename is empty after sanitization.', 'tablesome'));
+ }
+
+ $extension = strtolower(pathinfo($safe_filename, PATHINFO_EXTENSION));
+ if (empty($extension)) {
+ return new WP_Error('tablesome_upload_missing_extension', __('File extension is missing.', 'tablesome'));
+ }
+
+ if ($this->is_dangerous_extension($extension)) {
+ return new WP_Error('tablesome_upload_dangerous_extension', __('This file extension is not allowed.', 'tablesome'));
+ }
+
+ $context = isset($args['context']) ? $args['context'] : 'local_upload';
+ $integration = isset($args['integration']) ? $args['integration'] : '';
+ $allowed_mimes = $this->get_allowed_mimes($context, $integration, $file, $safe_filename);
+
+ $wp_filetype = $this->check_filetype_and_ext($file, $safe_filename, $allowed_mimes);
+ if ($wp_filetype['type'] === false || empty($wp_filetype['ext'])) {
+ return new WP_Error('tablesome_upload_invalid_filetype', __('File type validation failed.', 'tablesome'));
+ }
+
+ $validated_extension = strtolower($wp_filetype['ext']);
+ if ($this->is_dangerous_extension($validated_extension)) {
+ return new WP_Error('tablesome_upload_dangerous_validated_extension', __('This validated file extension is not allowed.', 'tablesome'));
+ }
+
+ if (!$this->is_mime_type_allowed($wp_filetype['type'], $allowed_mimes)) {
+ return new WP_Error('tablesome_upload_mime_not_allowed', __('MIME type is not allowed by site policy.', 'tablesome'));
+ }
+
+ return array(
+ 'ext' => $validated_extension,
+ 'type' => $wp_filetype['type'],
+ 'proper_filename' => isset($wp_filetype['proper_filename']) ? $wp_filetype['proper_filename'] : false,
+ 'filename' => $safe_filename,
+ );
+ }
+
+ public function get_allowed_mimes($context = 'local_upload', $integration = '', $file = '', $filename = '')
+ {
+ $allowed_mimes = get_allowed_mime_types();
+ $allowed_mimes = apply_filters('tablesome/upload_allowed_mimes', $allowed_mimes, $context, $integration, $file, $filename);
+
+ if (!is_array($allowed_mimes)) {
+ $allowed_mimes = array();
+ }
+
+ return $this->remove_dangerous_mimes($allowed_mimes);
+ }
+
+ protected function remove_dangerous_mimes($mimes)
+ {
+ foreach ($mimes as $extension_pattern => $mime_type) {
+ if ($this->pattern_matches_dangerous_extension($extension_pattern)) {
+ unset($mimes[$extension_pattern]);
+ }
+ }
+
+ return $mimes;
+ }
+
+ protected function check_filetype_and_ext($file, $filename, $allowed_mimes)
+ {
+ $mime_filter = function ($mimes = array(), $user = null) use ($allowed_mimes) {
+ return $allowed_mimes;
+ };
+
+ add_filter('upload_mimes', $mime_filter, PHP_INT_MAX, 2);
+
+ try {
+ return wp_check_filetype_and_ext($file, $filename, $allowed_mimes);
+ } finally {
+ remove_filter('upload_mimes', $mime_filter, PHP_INT_MAX);
+ }
+ }
+
+ protected function pattern_matches_dangerous_extension($extension_pattern)
+ {
+ foreach ($this->dangerous_extensions as $extension) {
+ if (preg_match('!.(' . $extension_pattern . ')$!i', 'file.' . $extension)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ protected function is_mime_type_allowed($mime_type, $allowed_mimes)
+ {
+ return in_array($mime_type, array_values($allowed_mimes), true);
+ }
+
+ protected function is_dangerous_extension($extension)
+ {
+ return in_array(strtolower($extension), $this->dangerous_extensions, true);
+ }
+ }
+}
--- a/tablesome/tablesome.php
+++ b/tablesome/tablesome.php
@@ -5,7 +5,7 @@
Plugin URI: https://tablesomewp.com/
Description: Powerful Tables + Form Automations. Save, Edit, Display (frontend) & Export Form entries, integrate with Notion, Redirection for Forms. Supports Contact Form 7, WPForms, Gravity Forms, Fluent, Elementor and more
Author: Pauple
-Version: 1.2.9
+Version: 1.2.11
Author URI: http://pauple.com
Network: False
Text Domain: tablesome
@@ -46,7 +46,7 @@
{
$constants = [
- 'TABLESOME_VERSION' => '1.2.9',
+ 'TABLESOME_VERSION' => '1.2.11',
'TABLESOME_DOMAIN' => 'tablesome',
'TABLESOME_CPT' => 'tablesome_cpt',
'TABLESOME__FILE__' => __FILE__,
--- a/tablesome/vendor/autoload.php
+++ b/tablesome/vendor/autoload.php
@@ -22,4 +22,4 @@
require_once __DIR__ . '/composer/autoload_real.php';
-return ComposerAutoloaderInit5d1d6a0d1749ccab2c9743351df878a5::getLoader();
+return ComposerAutoloaderInit7d4429fc5519964b98d4207651d23b5e::getLoader();
--- a/tablesome/vendor/composer/autoload_classmap.php
+++ b/tablesome/vendor/composer/autoload_classmap.php
@@ -108,6 +108,7 @@
'Tablesome\Includes\Modules\TablesomeDB_Rest_Api\Routes' => $baseDir . '/includes/modules/tablesomedb-rest-api/routes.php',
'Tablesome\Includes\Modules\TablesomeDB_Rest_Api\TablesomeDB_Rest_Api' => $baseDir . '/includes/modules/tablesomedb-rest-api/tablesomedb-rest-api.php',
'Tablesome\Includes\Modules\TablesomeDB_Rest_Api\Workflow_Rest_Api' => $baseDir . '/includes/modules/tablesomedb-rest-api/workflow-rest-api.php',
+ 'Tablesome\Includes\Modules\Upload_File_Validator' => $baseDir . '/includes/modules/upload-file-validator.php',
'Tablesome\Includes\Modules\WP_Media_File_Handler' => $baseDir . '/includes/modules/wp-media-file-handler.php',
'Tablesome\Includes\Modules\Workflow\Abstract_Trigger' => $baseDir . '/includes/modules/workflow/abstract-trigger.php',
'Tablesome\Includes\Modules\Workflow\Action' => $baseDir . '/includes/modules/workflow/action.php',
--- a/tablesome/vendor/composer/autoload_real.php
+++ b/tablesome/vendor/composer/autoload_real.php
@@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
-class ComposerAutoloaderInit5d1d6a0d1749ccab2c9743351df878a5
+class ComposerAutoloaderInit7d4429fc5519964b98d4207651d23b5e
{
private static $loader;
@@ -22,12 +22,12 @@
return self::$loader;
}
- spl_autoload_register(array('ComposerAutoloaderInit5d1d6a0d1749ccab2c9743351df878a5', 'loadClassLoader'), true, true);
+ spl_autoload_register(array('ComposerAutoloaderInit7d4429fc5519964b98d4207651d23b5e', 'loadClassLoader'), true, true);
self::$loader = $loader = new ComposerAutoloadClassLoader(dirname(__DIR__));
- spl_autoload_unregister(array('ComposerAutoloaderInit5d1d6a0d1749ccab2c9743351df878a5', 'loadClassLoader'));
+ spl_autoload_unregister(array('ComposerAutoloaderInit7d4429fc5519964b98d4207651d23b5e', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
- call_user_func(ComposerAutoloadComposerStaticInit5d1d6a0d1749ccab2c9743351df878a5::getInitializer($loader));
+ call_user_func(ComposerAutoloadComposerStaticInit7d4429fc5519964b98d4207651d23b5e::getInitializer($loader));
$loader->register(true);
--- a/tablesome/vendor/composer/autoload_static.php
+++ b/tablesome/vendor/composer/autoload_static.php
@@ -4,7 +4,7 @@
namespace ComposerAutoload;
-class ComposerStaticInit5d1d6a0d1749ccab2c9743351df878a5
+class ComposerStaticInit7d4429fc5519964b98d4207651d23b5e
{
public static $prefixLengthsPsr4 = array (
'P' =>
@@ -131,6 +131,7 @@
'Tablesome\Includes\Modules\TablesomeDB_Rest_Api\Routes' => __DIR__ . '/../..' . '/includes/modules/tablesomedb-rest-api/routes.php',
'Tablesome\Includes\Modules\TablesomeDB_Rest_Api\TablesomeDB_Rest_Api' => __DIR__ . '/../..' . '/includes/modules/tablesomedb-rest-api/tablesomedb-rest-api.php',
'Tablesome\Includes\Modules\TablesomeDB_Rest_Api\Workflow_Rest_Api' => __DIR__ . '/../..' . '/includes/modules/tablesomedb-rest-api/workflow-rest-api.php',
+ 'Tablesome\Includes\Modules\Upload_File_Validator' => __DIR__ . '/../..' . '/includes/modules/upload-file-validator.php',
'Tablesome\Includes\Modules\WP_Media_File_Handler' => __DIR__ . '/../..' . '/includes/modules/wp-media-file-handler.php',
'Tablesome\Includes\Modules\Workflow\Abstract_Trigger' => __DIR__ . '/../..' . '/includes/modules/workflow/abstract-trigger.php',
'Tablesome\Includes\Modules\Workflow\Action' => __DIR__ . '/../..' . '/includes/modules/workflow/action.php',
@@ -229,9 +230,9 @@
public static function getInitializer(ClassLoader $loader)
{
return Closure::bind(function () use ($loader) {
- $loader->prefixLengthsPsr4 = ComposerStaticInit5d1d6a0d1749ccab2c9743351df878a5::$prefixLengthsPsr4;
- $loader->prefixDirsPsr4 = ComposerStaticInit5d1d6a0d1749ccab2c9743351df878a5::$prefixDirsPsr4;
- $loader->classMap = ComposerStaticInit5d1d6a0d1749ccab2c9743351df878a5::$classMap;
+ $loader->prefixLengthsPsr4 = ComposerStaticInit7d4429fc5519964b98d4207651d23b5e::$prefixLengthsPsr4;
+ $loader->prefixDirsPsr4 = ComposerStaticInit7d4429fc5519964b98d4207651d23b5e::$prefixDirsPsr4;
+ $loader->classMap = ComposerStaticInit7d4429fc5519964b98d4207651d23b5e::$classMap;
}, null, ClassLoader::class);
}
--- a/tablesome/vendor/composer/installed.php
+++ b/tablesome/vendor/composer/installed.php
@@ -3,7 +3,7 @@
'name' => 'pauple/tablesome',
'pretty_version' => 'dev-develop',
'version' => 'dev-develop',
- 'reference' => '45762b3ce6087c127e4bd6af0cdb6daceb506c6b',
+ 'reference' => '30013804ebc8267e69101e7ae35486e1d4676f0d',
'type' => 'library',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
@@ -31,7 +31,7 @@
'pauple/tablesome' => array(
'pretty_version' => 'dev-develop',
'version' => 'dev-develop',
- 'reference' => '45762b3ce6087c127e4bd6af0cdb6daceb506c6b',
+ 'reference' => '30013804ebc8267e69101e7ae35486e1d4676f0d',
'type' => 'library',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
--- a/tablesome/workflow-library/actions/hubspot-add-contact.php
+++ b/tablesome/workflow-library/actions/hubspot-add-contact.php
@@ -24,10 +24,14 @@
public function get_config()
{
+ $label = pauple_is_feature_active('hubspot_upsert_deal')
+ ? __('Add or Update Contact', 'tablesome')
+ : __('Add Contact', 'tablesome');
+
return array(
'id' => 10,
'name' => 'hubspot_add_contact',
- 'label' => __('Add Contact', 'tablesome'),
+ 'label' => $label,
'integration' => 'hubspot',
'is_premium' => true,
);
--- a/tablesome/workflow-library/external-apis/hubspot.php
+++ b/tablesome/workflow-library/external-apis/hubspot.php
@@ -153,6 +153,50 @@
* @type array[] $stages [[id, label], ...] ordered as HubSpot returns them.
* }
*/
+ /**
+ * Fetch deal properties from HubSpot, formatted for the Create Deal
+ * action's destination Select. Mirrors `get_properties()` (contacts)
+ * but degrades to an empty list on any error rather than leaking
+ * error bodies into the UI.
+ *
+ * @return array[] {
+ * @type string $id Property name (e.g., 'dealname').
+ * @type string $label Display label (e.g., 'Deal Name').
+ * @type string $type HubSpot fieldType.
+ * @type array[] $options Optional, for enumerated properties.
+ * }
+ */
+ public function get_deal_properties()
+ {
+ $access_token = maybe_refresh_access_token_by_integration($this->integration);
+ $url = "https://api.hubapi.com/crm/v3/properties/deals?archived=false";
+
+ $response = wp_remote_request($url, [
+ 'method' => 'GET',
+ 'headers' => [
+ 'Authorization' => 'Bearer ' . $access_token,
+ 'Content-Type' => 'application/json',
+ ],
+ ]);
+
+ if (is_wp_error($response)) {
+ error_log('Tablesome Hubspot get_deal_properties wp_error: ' . $response->get_error_message());
+ return [];
+ }
+
+ $code = wp_remote_retrieve_response_code($response);
+ $body = json_decode(wp_remote_retrieve_body($response), true);
+
+ if ($code >= 400 || !is_array($body) || empty($body['results'])) {
+ if ($code >= 400) {
+ error_log('Tablesome Hubspot get_deal_properties API error: ' . print_r($body, true));
+ }
+ return [];
+ }
+
+ return $this->get_formated_properties($body['results']);
+ }
+
public function get_pipelines()
{
$access_token = maybe_refresh_access_token_by_integration($this->integration);
--- a/tablesome/workflow-library/triggers/cf7.php
+++ b/tablesome/workflow-library/triggers/cf7.php
@@ -25,6 +25,7 @@
public $trigger_source_id = 0;
public $trigger_source_data = array();
+ public $upload_file_validator;
public function get_config()
{
@@ -321,6 +322,18 @@
return 0;
}
+ $filename = basename($file);
+ $safe_filename = sanitize_file_name($filename);
+ $validation = $this->get_upload_file_validator()->validate($file, $safe_filename, array(
+ 'context' => 'local_upload',
+ 'integration' => 'cf7',
+ ));
+
+ if (is_wp_error($validation)) {
+ error_log('Tablesome CF7: ' . $validation->get_error_message() . ' File: ' . $safe_filename);
+ return 0;
+ }
+
// Deduplication: check if this exact file content was already uploaded
$file_hash = md5_file($file);
if ($file_hash !== false) {
@@ -337,54 +350,8 @@
}
}
- $filename = basename($file);
-
- // Security: Define allowed file extensions and MIME types
- $allowed_extensions = array(
- // Images
- 'jpg', 'jpeg', 'jpe', 'gif', 'png', 'bmp', 'tiff', 'tif', 'ico', 'webp',
- // Safe documents
- 'pdf', 'doc', 'docx', 'txt', 'csv', 'xls', 'xlsx', 'ppt', 'pptx',
- // Video
- 'mp4', 'mov', 'wmv', 'avi', 'mpg', 'mpeg', 'ogv', '3gp', '3g2',
- // Audio
- 'mp3', 'ogg', 'wav', 'm4a',
- // Archives
- 'zip', 'rar', '7z', 'tar', 'gz'
- );
-
- $allowed_mime_types = array(
- // Images
- 'image/jpeg', 'image/gif', 'image/png', 'image/bmp', 'image/tiff', 'image/x-icon', 'image/webp',
- // Documents
- 'application/pdf', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
- 'text/plain', 'text/csv',
- 'application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
- 'application/vnd.ms-powerpoint', 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
- // Video
- 'video/mp4', 'video/quicktime', 'video/x-ms-wmv', 'video/avi', 'video/mpeg', 'video/ogg', 'video/3gpp', 'video/3gpp2',
- // Audio
- 'audio/mpeg', 'audio/ogg', 'audio/wav', 'audio/mp4',
- // Archives
- 'application/zip', 'application/x-rar-compressed', 'application/x-7z-compressed', 'application/x-tar', 'application/gzip'
- );
-
- // Security: Validate file type from filename BEFORE copying
- $wp_filetype_pre = wp_check_filetype($filename, null);
- if ($wp_filetype_pre['type'] === false || empty($wp_filetype_pre['ext'])) {
- error_log('Tablesome CF7: Invalid file type from filename: ' . $filename);
- return 0;
- }
-
- // Security: Check if extension is in allowed list
- if (!in_array(strtolower($wp_filetype_pre['ext']), $allowed_extensions, true)) {
- error_log('Tablesome CF7: File extension not allowed: ' . $wp_filetype_pre['ext']);
- return 0;
- }
-
$media_dir = wp_upload_dir();
$time_now = time();
- $safe_filename = sanitize_file_name($filename);
$dest_file = $media_dir['path'] . '/' . $time_now . '-' . $safe_filename;
// Copy the file to destination
@@ -394,22 +361,21 @@
}
// Security: Validate actual file content after copying
- $wp_filetype = wp_check_filetype_and_ext($dest_file, $safe_filename, null);
+ $post_copy_validation = $this->get_upload_file_validator()->validate($dest_file, $safe_filename, array(
+ 'context' => 'local_upload',
+ 'integration' => 'cf7',
+ ));
// If validation fails, delete the file immediately
- if ($wp_filetype['type'] === false ||
- empty($wp_filetype['ext']) ||
- !in_array(strtolower($wp_filetype['ext']), $allowed_extensions, true) ||
- !in_array($wp_filetype['type'], $allowed_mime_types, true)) {
-
+ if (is_wp_error($post_copy_validation)) {
@unlink($dest_file);
- error_log('Tablesome CF7: File content validation failed, file deleted: ' . $safe_filename);
+ error_log('Tablesome CF7: ' . $post_copy_validation->get_error_message() . ' File deleted: ' . $safe_filename);
return 0;
}
// Create attachment with validated file type
$attachment = array(
- 'post_mime_type' => $wp_filetype['type'],
+ 'post_mime_type' => $post_copy_validation['type'],
'post_title' => sanitize_file_name(pathinfo($safe_filename, PATHINFO_FILENAME)),
'post_content' => '',
'post_status' => 'inherit',
@@ -444,6 +410,16 @@
return (int) $attachment_id;
}
+ public function get_upload_file_validator()
+ {
+ if (empty($this->upload_file_validator)) {
+ require_once TABLESOME_PATH . 'includes/modules/upload-file-validator.php';
+ $this->upload_file_validator = new TablesomeIncludesModulesUpload_File_Validator();
+ }
+
+ return $this->upload_file_validator;
+ }
+
/**
* Resolve a Polylang {string} tag to its translated value.
*
@@ -457,7 +433,7 @@
*/
private function resolve_polylang_string($value)
{
- if (is_string($value) && preg_match('/^{([ws-]+)}$/u', $value, $matches)) {
+ if (function_exists('pll__') && is_string($value) && preg_match('/^{([ws-]+)}$/u', $value, $matches)) {
return pll__($matches[1]);
}
return $value;