CVE-2019-13343 (published 2019-10-02T16:15Z)

Butor Portal before 1.0.27 is affected by a Path Traversal vulnerability leading to a pre-authentication arbitrary file download. Effectively, a remote anonymous user can download any file on servers running Butor Portal. WhiteLabelingServlet is responsible for this vulnerability. It does not properly sanitize user input on the theme t parameter before reusing it in a path. This path is then used without validation to fetch a file and return its raw content to the user via the /wl?t=../../...&h= substring followed by a filename.

Severity: MEDIUM
CVSS v2 base score: 5.0 (AV:N/AC:L/Au:N/C:N/I:P/A:N)
CVSS v3 base score: 7.5, HIGH (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:H/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://bitbucket.org/butor-team/portal
commit_details: repo_url: https://bitbucket.org/butor-team/portal
author: Aiman Sawan
author_date: 2019-07-05 07:59:31-04:00
msg: better check for theme exists!
repository: repo_url: https://bitbucket.org/butor-team/portal
repo_name: visit repo url
description: visit repo url
repo_language: visit repo url
owner: butor-team
file_changes: filename: WhiteLabelingServlet.java
change_type: ModificationType.MODIFY
diff: @@ -49,6 +49,7 @@ public class WhiteLabelingServlet extends HttpServlet {
 	private String themesByDomain;
 	private String defaultTheme = "default";
 	private String applyCommonByDomain;
+	private Pattern themePattern = Pattern.compile("^[a-zA-Z0-9]+$"); 
 
 	@Override
 	public void init(ServletConfig config) {
@@ -96,6 +97,18 @@ public class WhiteLabelingServlet extends HttpServlet {
 		if (t == null) {
 			t = defaultTheme;
 		}
+		
+		// check theme name. must be simple alphanum (no file path allowed or special chars)
+		if (!themePattern.matcher(t).find()) {
+			logger.warn("requested theme name is not valid! theme={}", t);
+			return;
+		}
+			
+		// check theme exists
+		if (!new File(resDir, "theme/" +t).exists()) {
+			logger.warn("requested theme does not exists! theme={}", t);
+			return;
+		}
 
 		File comFile = null;
 		File file = null;

programming_language: Java