Below is a differential between the unpatched vulnerable code and the patched update, for reference.
--- a/unlimited-elements-for-elementor/inc_php/framework/functions.class.php
+++ b/unlimited-elements-for-elementor/inc_php/framework/functions.class.php
@@ -3016,7 +3016,118 @@
if(self::isEmptyColorString($color) == true)
return("");
- return($color);
+ return(self::sanitizeCssPropertyValue($color));
+ }
+
+ /**
+ * drop a CSS property value that can break a style element or inject extra rules
+ */
+ public static function sanitizeCssPropertyValue($value){
+
+ if(is_string($value) == false)
+ return("");
+
+ $value = trim($value);
+
+ if($value === "")
+ return("");
+
+ if(preg_match('/[<>{}\\"';x00-x1f]|/*/', $value))
+ return("");
+
+ if(preg_match('/(?:^|[^a-z0-9-])expressions*(/i', $value) || stripos($value, "javascript:") !== false)
+ return("");
+
+ return($value);
+ }
+
+ /**
+ * font-family may include quotes, spaces and commas
+ */
+ public static function sanitizeCssFontFamilyValue($value){
+
+ if(is_string($value) == false)
+ return("");
+
+ $value = trim($value);
+
+ if($value === "")
+ return("");
+
+ if(preg_match('/[<>{}\\x00-x1f]|/*/', $value))
+ return("");
+
+ if(stripos($value, "javascript:") !== false || stripos($value, "expression(") !== false)
+ return("");
+
+ return($value);
+ }
+
+ /**
+ * class names used in CSS selectors and HTML class attributes
+ */
+ public static function sanitizeCssClassName($value){
+
+ if(is_string($value) == false)
+ return("");
+
+ return(sanitize_html_class($value));
+ }
+
+ /**
+ * keep only a CSS size token (after normalizeSize)
+ */
+ public static function sanitizeCssSizeValue($value){
+
+ $value = self::normalizeSize($value);
+
+ if(is_string($value) == false)
+ return("");
+
+ $value = trim($value);
+
+ if($value === "")
+ return("");
+
+ if(preg_match('/^-?d+(.d+)?(px|em|rem|%|vh|vw|pt|ex|ch|vmin|vmax)?$/i', $value) != 1)
+ return("");
+
+ return($value);
+ }
+
+ /**
+ * custom font CSS: allowlisted declarations only, then drop style-tag breakout
+ */
+ public static function sanitizeCustomCssDeclarations($css){
+
+ if(is_string($css) == false)
+ return("");
+
+ $css = safecss_filter_attr($css);
+
+ if($css === "")
+ return("");
+
+ if(preg_match('/[<>{}]|</style/i', $css))
+ return("");
+
+ return($css);
+ }
+
+ /**
+ * CSS that will be printed inside a style element must not contain a closer
+ */
+ public static function sanitizeCssForStyleTag($css){
+
+ if(is_string($css) == false)
+ return("");
+
+ $css = preg_replace('/</style/i', '', $css);
+
+ if(is_string($css) == false)
+ return("");
+
+ return($css);
}
--- a/unlimited-elements-for-elementor/inc_php/unitecreator_helper.class.php
+++ b/unlimited-elements-for-elementor/inc_php/unitecreator_helper.class.php
@@ -2298,6 +2298,7 @@
$css = UniteCreatorOutput::$bufferBodyCss;
if(!empty($css)){
+ $css = UniteFunctionsUC::sanitizeCssForStyleTag($css);
echo "n<style type='text/css'> n";
echo "n/* Unlimited Elements Css */ nn";
uelm_echo($css . "n");
--- a/unlimited-elements-for-elementor/inc_php/unitecreator_output.class.php
+++ b/unlimited-elements-for-elementor/inc_php/unitecreator_output.class.php
@@ -2875,6 +2875,8 @@
$css = "/* {$widgetText}: $title */" . self::BR2 . $css . self::BR2;
+ $css = UniteFunctionsUC::sanitizeCssForStyleTag($css);
+
if(self::$isBufferingCssActive == true){
//add css to buffer
if(!empty(self::$bufferBodyCss))
@@ -2892,6 +2894,7 @@
//add css selectors
if($isAddSelectors == true){
$selectorsStyleID = "selectors_css_" . $this->generatedID;
+ $cssSelectors = UniteFunctionsUC::sanitizeCssForStyleTag($cssSelectors);
$output .= "n<style id="$selectorsStyleID" name="uc_selectors_css">$cssSelectors</style>";
}
--- a/unlimited-elements-for-elementor/inc_php/unitecreator_params_processor.class.php
+++ b/unlimited-elements-for-elementor/inc_php/unitecreator_params_processor.class.php
@@ -370,6 +370,10 @@
switch($styleName){
case "font-family":
+ $styleValue = UniteFunctionsUC::sanitizeCssFontFamilyValue($styleValue);
+ if($styleValue === "")
+ break;
+
if(strpos($styleValue, " ") !== false && strpos($styleValue, ",") === false)
$arrStyle[$styleName] = "'$styleValue'";
else
@@ -400,16 +404,26 @@
case "text-decoration":
case "color":
case "font-style":
+ $styleValue = UniteFunctionsUC::sanitizeCssPropertyValue($styleValue);
+ if($styleValue === "")
+ break;
+
$arrStyle[$styleName] = $styleValue;
break;
case "font-size":
- $arrStyle[$styleName] = UniteFunctionsUC::normalizeSize($styleValue);
+ $styleValue = UniteFunctionsUC::sanitizeCssSizeValue($styleValue);
+ if($styleValue === "")
+ break;
+
+ $arrStyle[$styleName] = $styleValue;
break;
case "font-size-mobile":
case "mobile-size":
case "font-size-tablet":
- $styleValue = UniteFunctionsUC::normalizeSize($styleValue);
+ $styleValue = UniteFunctionsUC::sanitizeCssSizeValue($styleValue);
+ if($styleValue === "")
+ break;
$isTablet = false;
if($styleName == "font-size-tablet")
@@ -417,6 +431,7 @@
$cssMobileSize = "{$mobileSizeClass}{font-size:{$styleValue} !important;}";
$cssMobileSize = HelperHtmlUC::wrapCssMobile($cssMobileSize, $isTablet);
+ $cssMobileSize = UniteFunctionsUC::sanitizeCssForStyleTag($cssMobileSize);
if($isReturnCss == false)
$this->addon->addToCSS($cssMobileSize);
@@ -424,13 +439,19 @@
break;
case "custom":
- $addStyles = safecss_filter_attr($styleValue);
+ $addStyles = UniteFunctionsUC::sanitizeCustomCssDeclarations($styleValue);
break;
case "template":
- $fontTemplate = $styleValue;
+ $fontTemplate = UniteFunctionsUC::sanitizeCssClassName($styleValue);
+ if($fontTemplate === "" || $fontTemplate !== $styleValue)
+ $fontTemplate = null;
break;
case "style-selector":
- $spanClass = $styleValue;
+ $spanClassSanitized = UniteFunctionsUC::sanitizeCssClassName($styleValue);
+ if($spanClassSanitized === "" || $spanClassSanitized !== $styleValue)
+ break;
+
+ $spanClass = $spanClassSanitized;
$mobileSizeClass = ".".$spanClass;
break;
@@ -450,7 +471,7 @@
if(!empty($cssMobileSize))
$css .= "n".$cssMobileSize;
- return($css);
+ return(UniteFunctionsUC::sanitizeCssForStyleTag($css));
}
@@ -470,7 +491,7 @@
if($this->processType == self::PROCESS_TYPE_OUTPUT_BACK){
$arrClasses[] = "uc-font-editable-field";
- $htmlAdd .= " data-uc_font_field="{$fontsKey}" ";
+ $htmlAdd .= " data-uc_font_field="" . esc_attr($fontsKey) . "" ";
$htmlAdd .= " contenteditable";
//UniteFunctionsUC::showTrace();exit();
--- a/unlimited-elements-for-elementor/inc_php/unitecreator_rss.class.php
+++ b/unlimited-elements-for-elementor/inc_php/unitecreator_rss.class.php
@@ -351,6 +351,7 @@
$value = wp_strip_all_tags($value);
$value = str_replace(array("<", ">"), "", $value);
+ $value = $this->stripRssShortcodes($value);
$value = preg_replace('/s+/', ' ', $value);
if(is_string($value) == false)
@@ -365,15 +366,58 @@
private function sanitizeRssHtml($value){
$value = $this->decodeRssTextEntities($value);
+ $value = $this->stripRssShortcodes($value);
$value = wp_kses_post($value);
if(is_string($value) == false)
$value = "";
+ // Tag removal can join a broken name into a real shortcode, so strip again.
+ $value = $this->stripRssShortcodes($value);
+
return(trim($value));
}
/**
+ * remove registered shortcodes from a feed string.
+ * the whole [[tag]] form goes too. strip_shortcodes() would turn that into [tag], and the page runs do_shortcode() later.
+ */
+ private function stripRssShortcodes($value){
+
+ if(is_string($value) == false || $value === "")
+ return("");
+
+ if(strpos($value, "[") === false)
+ return($value);
+
+ if(function_exists("get_shortcode_regex") == false)
+ return($value);
+
+ global $shortcode_tags;
+
+ if(empty($shortcode_tags) || is_array($shortcode_tags) == false)
+ return($value);
+
+ $pattern = get_shortcode_regex(array_keys($shortcode_tags));
+ $passes = 0;
+ $previous = null;
+
+ while($value !== $previous && $passes < 3){
+
+ $previous = $value;
+ $stripped = preg_replace("/".$pattern."/", "", $value);
+
+ if(is_string($stripped) == false)
+ return("");
+
+ $value = $stripped;
+ $passes++;
+ }
+
+ return($value);
+ }
+
+ /**
* http(s) and other browser-safe schemes only
*/
private function sanitizeRssUrl($value){
--- a/unlimited-elements-for-elementor/inc_php/unitecreator_template_engine.class.php
+++ b/unlimited-elements-for-elementor/inc_php/unitecreator_template_engine.class.php
@@ -1607,7 +1607,7 @@
break;
case "get_nextprev_post_data":
- $data = UniteFunctionsWPUC::getNextPrevPostData($arg1, $arg2);
+ $data = UniteFunctionsWPUC::getNextPrevPostData($arg1, $arg2, $arg3);
return($data);
break;
--- a/unlimited-elements-for-elementor/includes.php
+++ b/unlimited-elements-for-elementor/includes.php
@@ -12,7 +12,7 @@
if ( ! defined( 'ABSPATH' ) ) exit;
if(!defined("UNLIMITED_ELEMENTS_VERSION"))
- define("UNLIMITED_ELEMENTS_VERSION", "2.0.29");
+ define("UNLIMITED_ELEMENTS_VERSION", "2.0.30");
//disable elementor support for debugging purposes. keep it commented
--- a/unlimited-elements-for-elementor/provider/functions_wordpress.class.php
+++ b/unlimited-elements-for-elementor/provider/functions_wordpress.class.php
@@ -2934,25 +2934,91 @@
}
/**
+ * next or previous post in the same post type, ordered by menu_order
+ * next is the higher menu_order, previous is the lower one
+ */
+ private static function getAdjacentPostByMenuOrder($isNext){
+
+ $current = get_post();
+
+ if(empty($current) || empty($current->ID))
+ return(null);
+
+ global $wpdb;
+
+ $menuOrder = (int)$current->menu_order;
+ $postID = (int)$current->ID;
+ $postType = $current->post_type;
+ $orderCompare = $isNext ? ">" : "<";
+ $sort = $isNext ? "ASC" : "DESC";
+
+ $sql = $wpdb->prepare(
+ "SELECT ID FROM {$wpdb->posts}
+ WHERE post_type = %s
+ AND post_status = 'publish'
+ AND ID != %d
+ AND (
+ menu_order {$orderCompare} %d
+ OR (menu_order = %d AND ID {$orderCompare} %d)
+ )
+ ORDER BY menu_order {$sort}, ID {$sort}
+ LIMIT 1",
+ $postType,
+ $postID,
+ $menuOrder,
+ $menuOrder,
+ $postID
+ );
+
+ // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Adjacent lookup by the menu_order column. The comparison and sort direction are fixed strings, the values are placeholders.
+ $nextID = $wpdb->get_var($sql);
+
+ if(empty($nextID))
+ return(null);
+
+ return(get_post((int)$nextID));
+ }
+
+ /**
* get next or previous post
+ * orderBy: date (publish date) or menu_order
+ * the second argument used to be a taxonomy name
*/
- public static function getNextPrevPostData($type = "next", $taxonomy = "category"){
+ public static function getNextPrevPostData($type = "next", $orderBy = "date", $taxonomy = "category"){
+
+ if(empty($type))
+ $type = "next";
+
+ if(empty($orderBy))
+ $orderBy = "date";
+
+ if($orderBy != "date" && $orderBy != "menu_order"){
+ $taxonomy = $orderBy;
+ $orderBy = "date";
+ }
if(empty($taxonomy))
$taxonomy = "category";
- if(empty($type))
- $type = "next";
+ $isNext = ($type == "next");
+
+ if($orderBy == "menu_order"){
- $previous = !($type == "next");
+ $post = self::getAdjacentPostByMenuOrder($isNext);
- if($previous && is_attachment()){
- $post = get_post(get_post()->post_parent);
}else{
- $in_same_term = false;
- $excluded_terms = '';
- $post = get_adjacent_post($in_same_term, $excluded_terms, $previous, $taxonomy);
+ $previous = !$isNext;
+
+ if($previous && is_attachment()){
+ $post = get_post(get_post()->post_parent);
+ }else{
+ $in_same_term = false;
+ $excluded_terms = '';
+
+ $post = get_adjacent_post($in_same_term, $excluded_terms, $previous, $taxonomy);
+ }
+
}
if(empty($post))
--- a/unlimited-elements-for-elementor/provider/provider_params_processor.class.php
+++ b/unlimited-elements-for-elementor/provider/provider_params_processor.class.php
@@ -1619,6 +1619,121 @@
/**
+ * split a requested post type value into a list. "any" follows WP_Query and means types that are not excluded from search.
+ */
+ private function normalizeRequestedPostTypes($postType){
+
+ if(is_string($postType)){
+
+ $postType = trim($postType);
+
+ if($postType === "")
+ return(array());
+
+ if(strpos($postType, ",") !== false)
+ $postType = array_map("trim", explode(",", $postType));
+ else
+ $postType = array($postType);
+ }
+
+ if(is_array($postType) == false)
+ return(array());
+
+ $types = array();
+
+ foreach($postType as $type){
+
+ if(is_string($type) == false)
+ continue;
+
+ $type = trim($type);
+
+ if($type === "")
+ continue;
+
+ if($type === "any"){
+ $types = array_merge($types, array_values(get_post_types(array("exclude_from_search" => false), "names")));
+ continue;
+ }
+
+ $types[] = $type;
+ }
+
+ return($types);
+ }
+
+
+ /**
+ * a viewable type is allowed. a private type is allowed only when the user has that type's own edit_posts capability, or a type-specific read capability.
+ * cap->read on a normal type is the shared "read" capability, which every logged-in user has, so it does not authorize a private type.
+ */
+ private function isPostTypeAllowedForCurrentUser($type){
+
+ $type = sanitize_key($type);
+
+ if($type === "" || post_type_exists($type) == false)
+ return(false);
+
+ $objType = get_post_type_object($type);
+
+ if(empty($objType))
+ return(false);
+
+ if(is_post_type_viewable($objType) == true)
+ return(true);
+
+ if(empty($objType->cap))
+ return(false);
+
+ $editPosts = "";
+
+ if(isset($objType->cap->edit_posts))
+ $editPosts = $objType->cap->edit_posts;
+
+ if($editPosts !== "" && current_user_can($editPosts) == true)
+ return(true);
+
+ $readCap = "";
+
+ if(isset($objType->cap->read))
+ $readCap = $objType->cap->read;
+
+ if($readCap !== "" && $readCap !== "read" && current_user_can($readCap) == true)
+ return(true);
+
+ return(false);
+ }
+
+
+ /**
+ * drop post types the current user may not query. an empty result falls back to post.
+ */
+ private function filterQueryPostTypesForCurrentUser($postType){
+
+ $types = $this->normalizeRequestedPostTypes($postType);
+ $allowed = array();
+
+ foreach($types as $type){
+
+ if($this->isPostTypeAllowedForCurrentUser($type) == false)
+ continue;
+
+ $allowed[] = $type;
+ }
+
+ $allowed = array_values(array_unique($allowed));
+
+ if(empty($allowed))
+ return("post");
+
+ if(count($allowed) == 1)
+ return($allowed[0]);
+
+ return($allowed);
+ }
+
+
+ /**
* get post list data custom from filters
*/
private function getPostListData_custom($value, $name, $processType, $param, $data, $nameListing = null){
@@ -2069,6 +2184,9 @@
//add debug for further use
HelperUC::addDebug("Post Filters", $filters);
+ $postType = $this->filterQueryPostTypesForCurrentUser(UniteFunctionsUC::getVal($filters, "posttype", "post"));
+ $filters["posttype"] = $postType;
+
//run custom query if available
$args = UniteFunctionsWPUC::getPostsArgs($filters);
@@ -2816,7 +2934,8 @@
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Legacy hook name kept for existing callbacks.
$args = apply_filters("ue_modify_posts_query_args", $args, $value, $name);
- $args["post_status"] = $this->limitPostStatusesForCurrentUser(UniteFunctionsUC::getVal($args, "post_status", "publish"), UniteFunctionsUC::getVal($args, "post_type"));
+ $args["post_type"] = $this->filterQueryPostTypesForCurrentUser(UniteFunctionsUC::getVal($args, "post_type", "post"));
+ $args["post_status"] = $this->limitPostStatusesForCurrentUser(UniteFunctionsUC::getVal($args, "post_status", "publish"), $args["post_type"]);
//set debug errors
if($showDebugQuery == true && $debugType == "show_query"){
@@ -3197,6 +3316,9 @@
$postType = UniteFunctionsUC::getVal($value, $name."_posttype_current");
+ if(!empty($postType))
+ $postType = $this->filterQueryPostTypesForCurrentUser($postType);
+
//enable filters
$nameForFilter = $name;
if(!empty($nameListing))
--- a/unlimited-elements-for-elementor/unlimited_elements.php
+++ b/unlimited-elements-for-elementor/unlimited_elements.php
@@ -4,7 +4,7 @@
* Plugin URI: http://unlimited-elements.com
* Description: Elementor all-in-one addons pack with the best widgets for Elementor, offering 100+ free widgets, templates, and tools to create stunning websites!
* Author: Unlimited Elements
-* Version: 2.0.29
+* Version: 2.0.30
* Author URI: http://unlimited-elements.com
* Text Domain: unlimited-elements-for-elementor
* Domain Path: /languages