CVE-2022-3966 (published 2022-11-13T08:15Z)

A vulnerability, which was classified as critical, has been found in Ultimate Member Plugin up to 2.5.0. This issue affects the function load_template of the file includes/core/class-shortcodes.php of the component Template Handler. The manipulation of the argument tpl leads to pathname traversal. The attack may be initiated remotely. Upgrading to version 2.5.1 is able to address this issue. The name of the patch is e1bc94c1100f02a129721ba4be5fbc44c3d78ec4. It is recommended to upgrade the affected component. The identifier VDB-213545 was assigned to this vulnerability.

CVSS v3 base score: 7.5, HIGH (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N)

Weakness information:
cwe_id: CWE-22
cwe_name: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
description: The product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the restricted directory.
extended_description: 
            Many file operations are intended to take place within a restricted directory. By using special elements such as ".." and "/" separators, attackers can escape outside of the restricted location to access files or directories that are elsewhere on the system. One of the most common special elements is the "../" sequence, which in most modern operating systems is interpreted as the parent directory of the current location. This is referred to as relative path traversal. Path traversal also covers the use of absolute pathnames such as "/usr/local/bin" to access unexpected files. This is referred to as absolute path traversal.
         
         

Fix information:
repo_url: https://github.com/ultimatemember/ultimatemember
commit_details: repo_url: https://github.com/ultimatemember/ultimatemember
author: Nikita Sinelnikov
author_date: 2022-09-27 15:13:35+03:00
msg: - fixed Directory Traversal vulnerability. Using realpath for that;
repository: repo_url: https://github.com/ultimatemember/ultimatemember
repo_name: ultimatemember/ultimatemember
description: The easiest way to create powerful online communities and beautiful user profiles with WordPress
repo_language: PHP
owner: ultimatemember
file_changes: filename: class-shortcodes.php
change_type: ModificationType.MODIFY
diff: @@ -276,9 +276,6 @@ if ( ! class_exists( 'um\core\Shortcodes' ) ) {
 				extract( $args );
 			}
 
-			// Avoid Directory Traversal vulnerability.
-			$tpl = trim( $tpl, "./\\" );
-
 			$file = um_path . "templates/{$tpl}.php";
 			$theme_file = get_stylesheet_directory() . "/ultimate-member/templates/{$tpl}.php";
 			if ( file_exists( $theme_file ) ) {
@@ -286,7 +283,12 @@ if ( ! class_exists( 'um\core\Shortcodes' ) ) {
 			}
 
 			if ( file_exists( $file ) ) {
-				include $file;
+				// Avoid Directory Traversal vulnerability by the checking the realpath.
+				// Templates can be situated only in the get_stylesheet_directory() or plugindir templates.
+				$real_file = realpath( $file );
+				if ( 0 === strpos( $real_file, um_path . "templates" . DIRECTORY_SEPARATOR ) || 0 === strpos( $real_file, get_stylesheet_directory() . DIRECTORY_SEPARATOR . 'ultimate-member' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR ) ) {
+					include $file;
+				}
 			}
 		}
 

programming_language: PHP