diff --git a/cleantalk.php b/cleantalk.php index 2d49bd553..44588c39c 100644 --- a/cleantalk.php +++ b/cleantalk.php @@ -2361,7 +2361,7 @@ function apbct_rc__insert_auth_key($key, $plugin) require_once(ABSPATH . '/wp-admin/includes/plugin.php'); if ( is_plugin_active($plugin) ) { - $key = trim($key); + $key = trim($key, " \n\r\t\v\x00"); if ( $key && preg_match('/^[a-z\d]{3,30}$/', $key) ) { $result = API::methodNoticePaidTill( diff --git a/inc/cleantalk-common.php b/inc/cleantalk-common.php index d60727c53..4f4e8609f 100644 --- a/inc/cleantalk-common.php +++ b/inc/cleantalk-common.php @@ -744,7 +744,7 @@ function apbct_get_pixel_url($direct_call = false) */ function apbct_email_check_before_post() { - $email = trim(TT::toString(Post::get('email'))); + $email = trim(TT::toString(Post::get('email')), " \n\r\t\v\x00"); if ( $email ) { $result = \Cleantalk\ApbctWP\API::methodEmailCheck($email); @@ -762,7 +762,7 @@ function apbct_email_check_before_post() function apbct_email_check_exist_post() { global $apbct; - $email = trim(TT::toString(Post::get('email'))); + $email = trim(TT::toString(Post::get('email')), " \n\r\t\v\x00"); $api_key = $apbct->api_key; $brandname = $apbct->data['wl_mode_enabled'] ? $apbct->data['wl_brandname'] : 'Anti-Spam by CleanTalk'; if ( $email && $api_key ) { @@ -1152,7 +1152,7 @@ function ct_get_fields_any($arr, $email = '', $nickname = '') foreach ( $nickname as $value ) { $nickname_str .= ($value ? $value . " " : ""); } - $nickname = trim($nickname_str); + $nickname = trim($nickname_str, " \n\r\t\v\x00"); } return ct_gfa($arr, TT::toString($email), TT::toString($nickname)); diff --git a/inc/cleantalk-public-integrations.php b/inc/cleantalk-public-integrations.php index b22c6df36..ace1bd880 100644 --- a/inc/cleantalk-public-integrations.php +++ b/inc/cleantalk-public-integrations.php @@ -178,7 +178,7 @@ function ct_woocommerce_wishlist_check($args) $subject = ''; $email = $args['wishlist_owner_email']; if ( $args['wishlist_first_name'] !== '' || $args['wishlist_last_name'] !== '' ) { - $nickname = trim($args['wishlist_first_name'] . " " . $args['wishlist_last_name']); + $nickname = trim($args['wishlist_first_name'] . " " . $args['wishlist_last_name'], " \n\r\t\v\x00"); } else { $nickname = ''; } diff --git a/inc/cleantalk-public.php b/inc/cleantalk-public.php index c9a1bb273..795af8253 100644 --- a/inc/cleantalk-public.php +++ b/inc/cleantalk-public.php @@ -982,7 +982,7 @@ function apbct_js_test($check_js_value = '', $is_cookie = false) ) { $js_key = $is_cookie && $apbct->data['cookies_type'] === 'alternative' ? Cookie::get('ct_checkjs') - : trim($check_js_value); + : trim($check_js_value, " \n\r\t\v\x00"); // Check static key if ( diff --git a/inc/cleantalk-settings.php b/inc/cleantalk-settings.php index cea88f860..6271b665d 100644 --- a/inc/cleantalk-settings.php +++ b/inc/cleantalk-settings.php @@ -2450,7 +2450,7 @@ function apbct_settings__validate($incoming_settings) $predefined_key = Constant::getValue(Constant::APBCT_SERVICE__SELF_OWNED_ACCESS_KEY, false); - $incoming_settings['apikey'] = ! empty($incoming_settings['apikey']) ? trim($incoming_settings['apikey']) : ''; + $incoming_settings['apikey'] = ! empty($incoming_settings['apikey']) ? trim($incoming_settings['apikey'], " \n\r\t\v\x00") : ''; $incoming_settings['apikey'] = $predefined_key !== false ? $predefined_key : $incoming_settings['apikey']; $incoming_settings['apikey'] = ! is_main_site() && $apbct->white_label && $apbct->settings['apikey'] ? $apbct->settings['apikey'] : $incoming_settings['apikey']; $incoming_settings['apikey'] = is_main_site() || $apbct->allow_custom_key || $apbct->white_label ? $incoming_settings['apikey'] : $apbct->network_settings['apikey']; @@ -2470,7 +2470,7 @@ function apbct_settings__validate($incoming_settings) // Sanitize setting values foreach ( $incoming_settings as &$setting ) { if ( is_string($setting) ) { - $setting = preg_replace('/[<"\'>]/', '', trim($setting)); + $setting = preg_replace('/[<"\'>]/', '', trim($setting, " \n\r\t\v\x00")); } // Make HTML code inactive } @@ -2666,7 +2666,7 @@ function apbct_settings__validate($incoming_settings) // compare non-main site blog key with the validating key $blog_settings = get_option('cleantalk_settings'); $key_from_blog_settings = !empty($blog_settings['apikey']) ? $blog_settings['apikey'] : ''; - if ( isset($incoming_settings['apikey']) && (trim($incoming_settings['apikey']) !== trim($key_from_blog_settings)) ) { + if ( isset($incoming_settings['apikey']) && (trim($incoming_settings['apikey'], " \n\r\t\v\x00") !== trim($key_from_blog_settings, " \n\r\t\v\x00")) ) { $blog_key_changed = true; } $apbct->data['key_changed'] = empty($blog_key_changed) ? false : $blog_key_changed; @@ -2910,7 +2910,7 @@ function apbct_settings__save_key($apikey = '', $direct_call = false) } } - $apikey = trim($apikey); + $apikey = trim($apikey, " \n\r\t\v\x00"); $apikey = preg_match('/^[a-z\d]*$/', $apikey) ? $apikey : $apbct->settings['apikey']; if ( APBCT_WPMS && ! is_main_site() && (int) $apbct->network_settings['multisite__work_mode'] === 2 ) { @@ -3024,8 +3024,8 @@ function apbct_settings__get_key_auto($direct_call = false) } if ( ! empty($result['auth_key']) && apbct_api_key__is_correct($result['auth_key']) ) { - $apbct->data['key_changed'] = trim($result['auth_key']) !== $apbct->settings['apikey']; - $apbct->settings['apikey'] = trim($result['auth_key']); + $apbct->data['key_changed'] = trim($result['auth_key'], " \n\r\t\v\x00") !== $apbct->settings['apikey']; + $apbct->settings['apikey'] = trim($result['auth_key'], " \n\r\t\v\x00"); } $templates = ''; @@ -3187,7 +3187,7 @@ function apbct_settings__sanitize__exclusions($exclusions, $regexp = false, $url foreach ($exclusions as $exclusion) { //Cut exclusion if more than 128 symbols gained $sanitized_exclusion = substr($exclusion, 0, 128); - $sanitized_exclusion = trim($sanitized_exclusion); + $sanitized_exclusion = trim($sanitized_exclusion, " \n\r\t\v\x00"); if ( ! empty($sanitized_exclusion) ) { if ( $regexp ) { diff --git a/inc/cleantalk-wpcli.php b/inc/cleantalk-wpcli.php index b5336e3cc..d232f4138 100755 --- a/inc/cleantalk-wpcli.php +++ b/inc/cleantalk-wpcli.php @@ -108,8 +108,8 @@ public function create($args, $params) } if (isset($result['data']) && !empty($result['data']['auth_key']) && apbct_api_key__is_correct($result['data']['auth_key'])) { - $apbct->data['key_changed'] = trim($result['data']['auth_key']) !== $apbct->settings['apikey']; - $apbct->settings['apikey'] = trim($result['data']['auth_key']); + $apbct->data['key_changed'] = trim($result['data']['auth_key'], " \n\r\t\v\x00") !== $apbct->settings['apikey']; + $apbct->settings['apikey'] = trim($result['data']['auth_key'], " \n\r\t\v\x00"); $apbct->api_key = $apbct->settings['apikey']; $this->prompt(__('Api key installed: ', 'cleantalk-spam-protect') . $apbct->settings['apikey']); } diff --git a/lib/Cleantalk/Antispam/Integrations/AmemberRegister.php b/lib/Cleantalk/Antispam/Integrations/AmemberRegister.php index bb1ded204..18c442044 100644 --- a/lib/Cleantalk/Antispam/Integrations/AmemberRegister.php +++ b/lib/Cleantalk/Antispam/Integrations/AmemberRegister.php @@ -14,16 +14,16 @@ public function getDataForChecking($argument) $form_data = array(); $form_data['email'] = isset($_POST['email']) && is_string($_POST['email']) - ? trim($_POST['email']) + ? trim($_POST['email'], " \n\r\t\v\x00") : ''; $form_data['username'] = isset($_POST['login']) && is_string($_POST['login']) - ? trim($_POST['login']) + ? trim($_POST['login'], " \n\r\t\v\x00") : ''; if ( ! empty($_POST['name_f']) && is_string($_POST['name_f']) ) { - $form_data['first_name'] = trim($_POST['name_f']); + $form_data['first_name'] = trim($_POST['name_f'], " \n\r\t\v\x00"); } if ( ! empty($_POST['name_l']) && is_string($_POST['name_l']) ) { - $form_data['last_name'] = trim($_POST['name_l']); + $form_data['last_name'] = trim($_POST['name_l'], " \n\r\t\v\x00"); } /** diff --git a/lib/Cleantalk/Antispam/Integrations/BookingCalendar.php b/lib/Cleantalk/Antispam/Integrations/BookingCalendar.php index 0e36ea65c..a8dd23b2c 100644 --- a/lib/Cleantalk/Antispam/Integrations/BookingCalendar.php +++ b/lib/Cleantalk/Antispam/Integrations/BookingCalendar.php @@ -132,7 +132,7 @@ private function extractFieldByPattern(array $parsed_formdata, $pattern, $expect { foreach ($parsed_formdata as $key => $field) { if (preg_match($pattern, $key)) { - $value = isset($field['value']) ? trim($field['value']) : ''; + $value = isset($field['value']) ? trim($field['value'], " \n\r\t\v\x00") : ''; $type = isset($field['type']) ? $field['type'] : ''; // If type filter specified, check it diff --git a/lib/Cleantalk/Antispam/Integrations/ClassifiedListingRegister.php b/lib/Cleantalk/Antispam/Integrations/ClassifiedListingRegister.php index 5ea9983e5..4554205e9 100644 --- a/lib/Cleantalk/Antispam/Integrations/ClassifiedListingRegister.php +++ b/lib/Cleantalk/Antispam/Integrations/ClassifiedListingRegister.php @@ -17,7 +17,7 @@ public function getDataForChecking($argument) return null; } - $form_data['username'] = isset($_POST['username']) && is_string($_POST['username']) ? trim($_POST['username']) : ''; + $form_data['username'] = isset($_POST['username']) && is_string($_POST['username']) ? trim($_POST['username'], " \n\r\t\v\x00") : ''; $form_data['email'] = isset($_POST['email']) ? $_POST['email'] : ''; if ( ! empty($_POST['first_name']) ) { $form_data['first_name'] = $_POST['first_name']; diff --git a/lib/Cleantalk/Antispam/Integrations/CleantalkWpDieOnComment.php b/lib/Cleantalk/Antispam/Integrations/CleantalkWpDieOnComment.php index 331fa0f5a..c3b93fce4 100644 --- a/lib/Cleantalk/Antispam/Integrations/CleantalkWpDieOnComment.php +++ b/lib/Cleantalk/Antispam/Integrations/CleantalkWpDieOnComment.php @@ -69,9 +69,9 @@ public function doPrepareActions($argument) // first call in the flow - collect data for further instance calling $comment_data = wp_unslash($_POST); $comment_content = TT::getArrayValueAsString($comment_data, 'comment'); - $comment_author = trim(strip_tags(TT::getArrayValueAsString($comment_data, 'author'))); - $comment_author_email = trim(TT::getArrayValueAsString($comment_data, 'email')); - $comment_author_url = trim(TT::getArrayValueAsString($comment_data, 'url')); + $comment_author = trim(strip_tags(TT::getArrayValueAsString($comment_data, 'author')), " \n\r\t\v\x00"); + $comment_author_email = trim(TT::getArrayValueAsString($comment_data, 'email'), " \n\r\t\v\x00"); + $comment_author_url = trim(TT::getArrayValueAsString($comment_data, 'url'), " \n\r\t\v\x00"); $user = function_exists('apbct_wp_get_current_user') ? apbct_wp_get_current_user() : null; diff --git a/lib/Cleantalk/Antispam/Integrations/ElementorPro.php b/lib/Cleantalk/Antispam/Integrations/ElementorPro.php index 0a7c37889..2207d112e 100644 --- a/lib/Cleantalk/Antispam/Integrations/ElementorPro.php +++ b/lib/Cleantalk/Antispam/Integrations/ElementorPro.php @@ -58,7 +58,7 @@ public function getDataForChecking($argument) foreach ( $matches as $match ) { $sender_nickname .= isset($match[0]) && isset($form_data[$match[0]]) ? $form_data[$match[0]] . ' ' : ''; } - $sender_nickname = trim($sender_nickname); + $sender_nickname = trim($sender_nickname, " \n\r\t\v\x00"); } } } diff --git a/lib/Cleantalk/Antispam/Integrations/ElfsightForm.php b/lib/Cleantalk/Antispam/Integrations/ElfsightForm.php index df38b40b4..35e586bd6 100644 --- a/lib/Cleantalk/Antispam/Integrations/ElfsightForm.php +++ b/lib/Cleantalk/Antispam/Integrations/ElfsightForm.php @@ -35,8 +35,8 @@ public function getDataForChecking($argument) if (!is_object($field) || !isset($field->name)) { continue; } - $value = isset($field->value) ? (is_string($field->value) ? trim($field->value) : $field->value) : ''; - $name = mb_strtolower(trim($field->name)); + $value = isset($field->value) ? (is_string($field->value) ? trim($field->value, " \n\r\t\v\x00") : $field->value) : ''; + $name = mb_strtolower(trim($field->name, " \n\r\t\v\x00")); if (strpos($name, 'first') !== false && strpos($name, 'name') !== false) { $result['nickname'] = $value; diff --git a/lib/Cleantalk/Antispam/Integrations/Forminator.php b/lib/Cleantalk/Antispam/Integrations/Forminator.php index 09e637e11..7df9ca4d2 100644 --- a/lib/Cleantalk/Antispam/Integrations/Forminator.php +++ b/lib/Cleantalk/Antispam/Integrations/Forminator.php @@ -19,7 +19,7 @@ public function getDataForChecking($argument) } // First non-empty email-* — empty email-2/3 from hidden multi-step pages must not win. if (is_string($key) && strpos($key, 'email-') === 0) { - $candidate = trim(str_replace(' ', '', TT::toString($value))); + $candidate = trim(str_replace(' ', '', TT::toString($value)), " \n\r\t\v\x00"); if ($candidate !== '' && $email === '') { $email = $candidate; } @@ -38,7 +38,7 @@ public function getDataForChecking($argument) is_array($tmp_data['emails_array']) ) { foreach ($tmp_data['emails_array'] as $emails_array_value) { - $candidate = trim(str_replace(' ', '', TT::toString($emails_array_value))); + $candidate = trim(str_replace(' ', '', TT::toString($emails_array_value)), " \n\r\t\v\x00"); if ($candidate !== '') { $email = $candidate; break; diff --git a/lib/Cleantalk/Antispam/Integrations/WordpressFileUpload.php b/lib/Cleantalk/Antispam/Integrations/WordpressFileUpload.php index d0a5b253d..5ec9491a1 100644 --- a/lib/Cleantalk/Antispam/Integrations/WordpressFileUpload.php +++ b/lib/Cleantalk/Antispam/Integrations/WordpressFileUpload.php @@ -16,7 +16,7 @@ public function getDataForChecking($argument) $userdata = explode(";", TT::toString(Request::get('userdata'))); $parsed_userdata = []; foreach ($userdata as $_user) { - $parsed_userdata[] = strip_tags(wfu_plugin_decode_string(trim(substr($_user, 1)))); + $parsed_userdata[] = strip_tags(wfu_plugin_decode_string(trim(substr($_user, 1), " \n\r\t\v\x00"))); } $input_array = apply_filters('apbct__filter_post', $parsed_userdata); diff --git a/lib/Cleantalk/Antispam/IntegrationsByClass/WPForms.php b/lib/Cleantalk/Antispam/IntegrationsByClass/WPForms.php index e54a75957..7f67e6bdc 100644 --- a/lib/Cleantalk/Antispam/IntegrationsByClass/WPForms.php +++ b/lib/Cleantalk/Antispam/IntegrationsByClass/WPForms.php @@ -98,7 +98,7 @@ public function gatherData($entry, $form) // add unique key if key exist if ($field_label) { - $field_label = mb_strtolower(trim($field_label)); + $field_label = mb_strtolower(trim($field_label, " \n\r\t\v\x00")); $field_label = str_replace(' ', '_', $field_label); $field_label = preg_replace('/\W/u', '', $field_label); diff --git a/lib/Cleantalk/Antispam/IntegrationsByClass/WPSearchForm.php b/lib/Cleantalk/Antispam/IntegrationsByClass/WPSearchForm.php index a6c51b426..574d62272 100644 --- a/lib/Cleantalk/Antispam/IntegrationsByClass/WPSearchForm.php +++ b/lib/Cleantalk/Antispam/IntegrationsByClass/WPSearchForm.php @@ -83,7 +83,7 @@ public function apbctFormSearchAddFields($form_html) preg_match('/form.*method="(.*?)"/', $form_html, $matches); $method = empty($matches[1]) ? 'get' - : trim($matches[1]); + : trim($matches[1], " \n\r\t\v\x00"); } $form_method = strtolower($method); $form_sign = sprintf( diff --git a/lib/Cleantalk/ApbctWP/ContactsEncoder/ContactsEncoder.php b/lib/Cleantalk/ApbctWP/ContactsEncoder/ContactsEncoder.php index 3184b2ace..3a597e464 100644 --- a/lib/Cleantalk/ApbctWP/ContactsEncoder/ContactsEncoder.php +++ b/lib/Cleantalk/ApbctWP/ContactsEncoder/ContactsEncoder.php @@ -496,7 +496,7 @@ public static function getPhonesEncodingLongDescription()
%s
'; $tmp = sprintf( - trim($tmp), + trim($tmp, " \n\r\t\v\x00"), __('Enable this option to encode contact phone numbers', 'cleantalk-spam-protect'), __('There are a few requirements to the number format:', 'cleantalk-spam-protect'), __('Should starting with "+" symbol or opening brace', 'cleantalk-spam-protect'), diff --git a/lib/Cleantalk/ApbctWP/ContactsEncoder/Integrations/CEIntegrationGridBuilder.php b/lib/Cleantalk/ApbctWP/ContactsEncoder/Integrations/CEIntegrationGridBuilder.php index 1133f1edc..d803fb9b0 100644 --- a/lib/Cleantalk/ApbctWP/ContactsEncoder/Integrations/CEIntegrationGridBuilder.php +++ b/lib/Cleantalk/ApbctWP/ContactsEncoder/Integrations/CEIntegrationGridBuilder.php @@ -421,7 +421,7 @@ private function appendCardCssChunk($css) return; } - $css = trim($css); + $css = trim($css, " \n\r\t\v\x00"); if ( $css === '' ) { return; @@ -454,7 +454,7 @@ private function mergeCardCssChunks($chunks) continue; } - $chunk = trim($chunk); + $chunk = trim($chunk, " \n\r\t\v\x00"); if ( $chunk !== '' ) { $merged[] = $chunk; @@ -463,7 +463,7 @@ private function mergeCardCssChunks($chunks) if ( $merged === array() ) { return $this->isCardCssChunk($this->card_inline_css) - ? trim($this->card_inline_css) + ? trim($this->card_inline_css, " \n\r\t\v\x00") : ''; } @@ -471,7 +471,7 @@ private function mergeCardCssChunks($chunks) $this->card_inline_css !== '' && $this->isCardCssChunk($this->card_inline_css) ) { - $merged[] = trim($this->card_inline_css); + $merged[] = trim($this->card_inline_css, " \n\r\t\v\x00"); } return implode("\n", array_unique($merged)); @@ -626,7 +626,7 @@ private function readCssFromSrc($url) return ''; } - return trim($css); + return trim($css, " \n\r\t\v\x00"); } /** @@ -668,7 +668,7 @@ private function extractCardCssFromHtml($content) continue; } - $css = trim($css); + $css = trim($css, " \n\r\t\v\x00"); if ( $css !== '' ) { $chunks[] = $css; @@ -713,7 +713,7 @@ private function collectInlineCssFromQueue() foreach ( $data as $piece ) { if ( is_string($piece) && $this->isCardCssChunk($piece) ) { - $chunks[] = trim($piece); + $chunks[] = trim($piece, " \n\r\t\v\x00"); } } } diff --git a/lib/Cleantalk/ApbctWP/ContactsEncoder/Shortcodes/ExcludedEncodeContentSC.php b/lib/Cleantalk/ApbctWP/ContactsEncoder/Shortcodes/ExcludedEncodeContentSC.php index a0a64980a..e05b13f11 100644 --- a/lib/Cleantalk/ApbctWP/ContactsEncoder/Shortcodes/ExcludedEncodeContentSC.php +++ b/lib/Cleantalk/ApbctWP/ContactsEncoder/Shortcodes/ExcludedEncodeContentSC.php @@ -589,7 +589,7 @@ protected function removeDuplicateContactsOutsideShortcodes($title) $protected_contacts = array(); foreach ( $matches[1] as $inner_match ) { - $inner = trim($inner_match[0]); + $inner = trim($inner_match[0], " \n\r\t\v\x00"); if ( $inner !== '' ) { $protected_contacts[$inner] = true; } @@ -613,7 +613,7 @@ protected function removeDuplicateContactsOutsideShortcodes($title) $result .= $this->stripProtectedContactsFromPlainText(substr($title, $offset), array_keys($protected_contacts)); - return trim(preg_replace('/\s+/', ' ', $result)); + return trim(preg_replace('/\s+/', ' ', $result), " \n\r\t\v\x00"); } /** @@ -911,7 +911,7 @@ public function processTitleString($title, $strip_html = true) if ( $strip_html ) { $result = wp_strip_all_tags($result); - $result = trim(preg_replace('/\s+/', ' ', $result)); + $result = trim(preg_replace('/\s+/', ' ', $result), " \n\r\t\v\x00"); } return $result; @@ -929,7 +929,7 @@ public static function stripShortcodesForSlug($title) $title = preg_replace('/\[apbct_skip_encoding\](.*?)\[\/apbct_skip_encoding\]/s', '$1', $title); $title = preg_replace('/\[\/?apbct_skip_encoding\]/', '', $title); - return trim(preg_replace('/\s+/', ' ', $title)); + return trim(preg_replace('/\s+/', ' ', $title), " \n\r\t\v\x00"); } /** diff --git a/lib/Cleantalk/ApbctWP/Cron.php b/lib/Cleantalk/ApbctWP/Cron.php index 10953ac2a..1ce365021 100644 --- a/lib/Cleantalk/ApbctWP/Cron.php +++ b/lib/Cleantalk/ApbctWP/Cron.php @@ -67,10 +67,10 @@ public function getTasks() } $unserialize_options = array('allowed_classes' => false); - $unserialized = @unserialize(trim($result), $unserialize_options); + $unserialized = @unserialize(trim($result, " \n\r\t\v\x00"), $unserialize_options); if ( is_string($unserialized) && is_serialized($unserialized) ) { - $unserialized = @unserialize(trim($unserialized), $unserialize_options); + $unserialized = @unserialize(trim($unserialized, " \n\r\t\v\x00"), $unserialize_options); } return is_array($unserialized) ? $unserialized : array(); diff --git a/lib/Cleantalk/ApbctWP/FindSpam/CommentsChecker.php b/lib/Cleantalk/ApbctWP/FindSpam/CommentsChecker.php index e8ffefeb7..e01b2c08c 100644 --- a/lib/Cleantalk/ApbctWP/FindSpam/CommentsChecker.php +++ b/lib/Cleantalk/ApbctWP/FindSpam/CommentsChecker.php @@ -162,8 +162,8 @@ private static function removeSkipRoles(array $comments, array $skip_roles) private static function removeCommentsWithoutIPEmail(array $comments) { foreach ($comments as $index => $comment) { - $comment_ip = ! empty($comment->comment_author_IP) ? trim($comment->comment_author_IP) : false; - $comment_email = ! empty($comment->comment_author_email) ? trim($comment->comment_author_email) : false; + $comment_ip = ! empty($comment->comment_author_IP) ? trim($comment->comment_author_IP, " \n\r\t\v\x00") : false; + $comment_email = ! empty($comment->comment_author_email) ? trim($comment->comment_author_email, " \n\r\t\v\x00") : false; // Validate IP and Email $comment_ip = filter_var($comment_ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4); diff --git a/lib/Cleantalk/ApbctWP/FindSpam/UsersChecker.php b/lib/Cleantalk/ApbctWP/FindSpam/UsersChecker.php index a43635606..7a7124ed4 100644 --- a/lib/Cleantalk/ApbctWP/FindSpam/UsersChecker.php +++ b/lib/Cleantalk/ApbctWP/FindSpam/UsersChecker.php @@ -175,7 +175,7 @@ private static function removeUsersWithoutIPEmail(array $users) ? $ip_from_keeper : false; $user_ip = $ip_from_keeper; - $user_email = ! empty($user->user_email) ? trim($user->user_email) : false; + $user_email = ! empty($user->user_email) ? trim($user->user_email, " \n\r\t\v\x00") : false; // Validate IP and Email $user_ip = filter_var($user_ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4); diff --git a/lib/Cleantalk/ApbctWP/Firewall/SFW.php b/lib/Cleantalk/ApbctWP/Firewall/SFW.php index a8d6b0c54..4a13f0121 100644 --- a/lib/Cleantalk/ApbctWP/Firewall/SFW.php +++ b/lib/Cleantalk/ApbctWP/Firewall/SFW.php @@ -606,7 +606,7 @@ public static function sendLog($db, $log_table, $ct_key) $ids_invalid = array(); $data = array(); foreach ($logs as $_key => &$value) { - $ip = isset($value['ip']) ? trim((string)$value['ip']) : ''; + $ip = isset($value['ip']) ? trim((string)$value['ip'], " \n\r\t\v\x00") : ''; // Do not send empty/invalid IPs — they break cloud collectors. if ( Helper::ipValidate($ip) === false ) { diff --git a/lib/Cleantalk/ApbctWP/GetFieldsAny.php b/lib/Cleantalk/ApbctWP/GetFieldsAny.php index f5855482c..37c0726e6 100644 --- a/lib/Cleantalk/ApbctWP/GetFieldsAny.php +++ b/lib/Cleantalk/ApbctWP/GetFieldsAny.php @@ -255,7 +255,7 @@ public function prepareFields($email, $nickname, $emails_array) foreach ($name_chunks as $value) { $this->dto->nickname .= ($value ? $value . " " : ""); } - $this->dto->nickname = trim($this->dto->nickname); + $this->dto->nickname = trim($this->dto->nickname, " \n\r\t\v\x00"); } } @@ -358,9 +358,9 @@ private function processRecursive($arr) } // Removes shortcodes to do better spam filtration on server side. - $value_for_email = trim($this->stripShortcodes($value)); + $value_for_email = trim($this->stripShortcodes($value), " \n\r\t\v\x00"); // Removes whitespaces - $value = urldecode(trim($this->stripShortcodes($value))); // Fully cleaned message + $value = urldecode(trim($this->stripShortcodes($value), " \n\r\t\v\x00")); // Fully cleaned message // Email $value_for_email = Validate::isUrlencoded($value_for_email) ? urldecode($value_for_email) : $value_for_email; diff --git a/lib/Cleantalk/ApbctWP/RemoteCalls.php b/lib/Cleantalk/ApbctWP/RemoteCalls.php index 9be3b865e..98b682cab 100644 --- a/lib/Cleantalk/ApbctWP/RemoteCalls.php +++ b/lib/Cleantalk/ApbctWP/RemoteCalls.php @@ -515,7 +515,7 @@ public static function action__post_api_key() // phpcs:ignore PSR1.Methods.Camel header("Content-Type: application/json"); } - $key = trim(Request::getString('api_key')); + $key = trim(Request::getString('api_key'), " \n\r\t\v\x00"); if ( ! apbct_api_key__is_correct($key) ) { die(json_encode(['FAIL' => ['error' => 'Api key is incorrect']])); } diff --git a/lib/Cleantalk/ApbctWP/ServerRequirementsChecker/ServerRequirementsChecker.php b/lib/Cleantalk/ApbctWP/ServerRequirementsChecker/ServerRequirementsChecker.php index 555ffebab..6c36a1fd3 100644 --- a/lib/Cleantalk/ApbctWP/ServerRequirementsChecker/ServerRequirementsChecker.php +++ b/lib/Cleantalk/ApbctWP/ServerRequirementsChecker/ServerRequirementsChecker.php @@ -197,7 +197,7 @@ public function checkRequirements() */ private function normalizeMemoryLimit($val) { - $val = trim($val); + $val = trim($val, " \n\r\t\v\x00"); $last = strtolower($val[strlen($val) - 1]); $val = (int)$val; switch ($last) { diff --git a/lib/Cleantalk/ApbctWP/UpdatePlugin/DbColumnCreator.php b/lib/Cleantalk/ApbctWP/UpdatePlugin/DbColumnCreator.php index 3ae812be2..dba8eb2ff 100644 --- a/lib/Cleantalk/ApbctWP/UpdatePlugin/DbColumnCreator.php +++ b/lib/Cleantalk/ApbctWP/UpdatePlugin/DbColumnCreator.php @@ -134,9 +134,9 @@ private function updateIndexes($schema_indexes_raw, $db_column_names, &$errors) if (!isset($match[1], $match[3])) { continue; } - $keyword = strtoupper(trim($match[1])); + $keyword = strtoupper(trim($match[1], " \n\r\t\v\x00")); $explicit_name = !empty($match[2]) ? $match[2] : ''; - $columns_raw = trim($match[3]); + $columns_raw = trim($match[3], " \n\r\t\v\x00"); // Skip PRIMARY KEY as it should already exist if table has primary key if (strpos($keyword, 'PRIMARY') !== false) { @@ -256,7 +256,7 @@ private function updateIndexes($schema_indexes_raw, $db_column_names, &$errors) if (isset($schema_indexes[$index_name])) { $index_def = $schema_indexes[$index_name]; if (preg_match('/\(([^)]+)\)/', $index_def, $col_match) && isset($col_match[1])) { - $columns = trim($col_match[1]); + $columns = trim($col_match[1], " \n\r\t\v\x00"); $add_type = (stripos($index_def, 'UNIQUE') !== false) ? 'UNIQUE INDEX' : 'INDEX'; $sql = "ALTER TABLE `$this->dbTableName` ADD $add_type `$index_name` ($columns)"; $result = $wpdb->query($sql); @@ -293,7 +293,7 @@ private function updateIndexes($schema_indexes_raw, $db_column_names, &$errors) // Create proper SQL: ALTER TABLE `table` ADD INDEX `name` (`column`) // Parse the index definition to extract columns if (preg_match('/\(([^)]+)\)/', $index_def, $col_match) && isset($col_match[1])) { - $columns = trim($col_match[1]); + $columns = trim($col_match[1], " \n\r\t\v\x00"); $add_type = (stripos($index_def, 'UNIQUE') !== false) ? 'UNIQUE INDEX' : 'INDEX'; $sql = "ALTER TABLE `$this->dbTableName` ADD $add_type `$diff_index_name` ($columns)"; $result = $wpdb->query($sql); diff --git a/lib/Cleantalk/Common/ContactsEncoder/ContactsEncoder.php b/lib/Cleantalk/Common/ContactsEncoder/ContactsEncoder.php index 991461442..6664d4d80 100644 --- a/lib/Cleantalk/Common/ContactsEncoder/ContactsEncoder.php +++ b/lib/Cleantalk/Common/ContactsEncoder/ContactsEncoder.php @@ -936,7 +936,11 @@ private function replaceAriaLabelWithPlaceholder($matches) */ private function isSecureAriaLabelPlaceholderAvailable() { - return function_exists('random_bytes') || function_exists('openssl_random_pseudo_bytes'); + if ( function_exists('random_bytes') ) { + return true; + } + + return function_exists('openssl_random_pseudo_bytes'); } /** @@ -945,38 +949,23 @@ private function isSecureAriaLabelPlaceholderAvailable() * @return string|null Null when no secure entropy source is available. */ private function generateAriaLabelPlaceholder() - { - $bytes = $this->getSecureRandomBytes(16); - if ( !is_string($bytes) || strlen($bytes) !== 16 ) { - return null; - } - - return '%%APBCT_ARIA_' . bin2hex($bytes) . '%%'; - } - - /** - * @param int $length - * - * @return string|null - */ - private function getSecureRandomBytes($length) { if ( function_exists('random_bytes') ) { try { - // phpcs:ignore PHPCompatibility.FunctionUse.NewFunctions.random_bytesFound - $bytes = random_bytes($length); - if ( is_string($bytes) && strlen($bytes) === $length ) { - return $bytes; + $bytes = random_bytes(16); + if ( is_string($bytes) && strlen($bytes) === 16 ) { + return '%%APBCT_ARIA_' . bin2hex($bytes) . '%%'; } } catch ( \Exception $e ) { - // Fall through to OpenSSL. + // fall through to openssl } } if ( function_exists('openssl_random_pseudo_bytes') ) { - $bytes = openssl_random_pseudo_bytes($length); - if ( is_string($bytes) && strlen($bytes) === $length ) { - return $bytes; + $crypto_strong = false; + $bytes = openssl_random_pseudo_bytes(16, $crypto_strong); + if ( $crypto_strong && is_string($bytes) && strlen($bytes) === 16 ) { + return '%%APBCT_ARIA_' . bin2hex($bytes) . '%%'; } } diff --git a/lib/Cleantalk/Common/Helper.php b/lib/Cleantalk/Common/Helper.php index 79e07925d..ee38aa92b 100644 --- a/lib/Cleantalk/Common/Helper.php +++ b/lib/Cleantalk/Common/Helper.php @@ -98,11 +98,11 @@ public static function ipGet($ip_type_to_get = 'real', $v4_only = true, $headers ? explode(',', $source) : (array)$source; if ( isset($tmp[0]) ) { - $ip_version = self::ipValidate(trim($tmp[0])); + $ip_version = self::ipValidate(trim($tmp[0], " \n\r\t\v\x00")); if ($ip_version) { $out = $ip_version === 'v6' && ! $v4_only - ? self::ipV6Normalize(trim($tmp[0])) - : trim($tmp[0]); + ? self::ipV6Normalize(trim($tmp[0], " \n\r\t\v\x00")) + : trim($tmp[0], " \n\r\t\v\x00"); } } } @@ -241,8 +241,8 @@ public static function ipGet($ip_type_to_get = 'real', $v4_only = true, $headers case 'x_forwarded_for': $headers = $headers ?: self::httpGetHeaders(); if (isset($headers['X-Forwarded-For'])) { - $tmp = explode(',', trim($headers['X-Forwarded-For'])); - $tmp = trim($tmp[0]); + $tmp = explode(',', trim($headers['X-Forwarded-For'], " \n\r\t\v\x00")); + $tmp = trim($tmp[0], " \n\r\t\v\x00"); $ip_version = self::ipValidate($tmp); if ($ip_version) { $out = $ip_version === 'v6' && ! $v4_only ? self::ipV6Normalize($tmp) : $tmp; @@ -254,8 +254,8 @@ public static function ipGet($ip_type_to_get = 'real', $v4_only = true, $headers case 'x_real_ip': $headers = $headers ?: self::httpGetHeaders(); if (isset($headers['X-Real-Ip'])) { - $tmp = explode(",", trim($headers['X-Real-Ip'])); - $tmp = trim($tmp[0]); + $tmp = explode(",", trim($headers['X-Real-Ip'], " \n\r\t\v\x00")); + $tmp = trim($tmp[0], " \n\r\t\v\x00"); $ip_version = self::ipValidate($tmp); if ($ip_version) { $out = $ip_version === 'v6' && ! $v4_only ? self::ipV6Normalize($tmp) : $tmp; @@ -489,7 +489,7 @@ public static function cidrValidate($cidr) */ public static function ipV6Normalize($ip) { - $ip = trim($ip); + $ip = trim($ip, " \n\r\t\v\x00"); // Searching for ::ffff:xx.xx.xx.xx patterns and turn it to IPv6 if (preg_match('/^::ffff:([0-9]{1,3}\.?){4}$/', $ip)) { $ip = dechex((int)sprintf("%u", ip2long(substr($ip, 7)))); @@ -914,7 +914,7 @@ public static function bufferTrimAndClearFromEmptyLines($buffer) { $buffer = (array)$buffer; foreach ($buffer as $indx => &$line) { - $line = trim($line); + $line = trim($line, " \n\r\t\v\x00"); if ($line === '') { unset($buffer[$indx]); } @@ -982,7 +982,7 @@ public static function bufferCsvGetMap(&$csv) */ public static function bufferCsvPopLineToArray(&$csv, $map = array()) { - $line = trim(static::bufferCsvPopLine($csv)); + $line = trim(static::bufferCsvPopLine($csv), " \n\r\t\v\x00"); $line = strpos($line, '\'') === 0 ? str_getcsv($line, ',', '\'', "\0") : explode(',', $line); diff --git a/lib/Cleantalk/Common/TextPlate.php b/lib/Cleantalk/Common/TextPlate.php index 970bafe3a..59cfc1bcd 100644 --- a/lib/Cleantalk/Common/TextPlate.php +++ b/lib/Cleantalk/Common/TextPlate.php @@ -33,7 +33,7 @@ public static function textPlateRender(string $_text, array $_plate, bool $trim { try { $search = []; - $_text = $trim ? trim($_text) : $_text; + $_text = $trim ? trim($_text, " \n\r\t\v\x00") : $_text; foreach ($_plate as $key => $value) { $key = self::validatePlateKey($key, $_text); $value = self::validatePlateValue($value, $key); diff --git a/tests/ApbctWP/ContactsEncoder/TestContactsEncoder.php b/tests/ApbctWP/ContactsEncoder/TestContactsEncoder.php index b108360a6..6d31823f9 100644 --- a/tests/ApbctWP/ContactsEncoder/TestContactsEncoder.php +++ b/tests/ApbctWP/ContactsEncoder/TestContactsEncoder.php @@ -42,7 +42,9 @@ private function clearDecoderPassedCookie(): void while ($ref) { if ($ref->hasProperty('variables')) { $prop = $ref->getProperty('variables'); - $prop->setAccessible(true); + if ( PHP_VERSION_ID < 80100 ) { + $prop->setAccessible(true); + } $variables = $prop->getValue($cookie_instance); unset($variables[$cookie_name]); $prop->setValue($cookie_instance, $variables); @@ -222,6 +224,55 @@ public function testModifyContentSkipsEmailsInsideOptionTags() $this->assertStringContainsString('apbct-email-encoder', $result); } + /** + * aria-label values must survive email encoding round-trip intact. + */ + public function testModifyContentPreservesAriaLabelWithEmail() + { + $email = 'info@example.com'; + $content = ''; + + $result = $this->contacts_encoder->modifyContent($content); + + $this->assertStringContainsString('aria-label="Contact us at ' . $email . '"', $result); + $this->assertStringNotContainsString('%%APBCT_ARIA_', $result); + $this->assertStringNotContainsString('ct_temp_aria_', $result); + } + + /** + * CVE-2026-77830: planted ct_temp_aria_0 must not be rewritten during aria-label restore. + */ + public function testModifyContentDoesNotRestorePlantedCtTempAriaToken() + { + $payload = 'test' + . 'ct_temp_aria_0' + . 'test'; + + $result = $this->contacts_encoder->modifyContent($payload); + + $this->assertStringContainsString('ct_temp_aria_0', $result); + $this->assertNotRegExp('/>\s*aria-label\s*=/', $result); + } + + /** + * CVE-2026-77830: Wordfence PoC must not produce aria-label markup breakout after encoding. + */ + public function testModifyContentWordfenceAriaLabelXssPayloadDoesNotBreakOut() + { + $payload = '
test' . "\n" + . 'ct_temp_aria_0' + . 'test'; + + $result = $this->contacts_encoder->modifyContent($payload); + + $planted_token_preserved = strpos($result, 'ct_temp_aria_0') !== false; + $breakout_injected = (bool) preg_match('/>\s*aria-label\s*=/', $result); + + $this->assertTrue($planted_token_preserved, 'Planted ct_temp_aria_0 token must survive encoder round-trip.'); + $this->assertFalse($breakout_injected, 'Encoder must not inject aria-label markup via token substitution.'); + } + public function testEncodingPhoneNumbers() { global $apbct;