CVE-2022-38301 (published 2022-09-14T21:15Z)

Onedev v7.4.14 contains a path traversal vulnerability which allows attackers to access restricted files and directories via uploading a crafted JAR file into the directory /opt/onedev/lib.

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

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/theonedev/onedev
commit_details: repo_url: https://github.com/theonedev/onedev
author: Robin Shen
author_date: 2022-08-09 16:02:48+08:00
msg: Fix issue #842 - A security vulnerability relating to path traversal
repository: repo_url: https://github.com/theonedev/onedev
repo_name: theonedev/onedev
description: Git Server with CI/CD, Kanban, and Packages. Seamless integration. Unparalleled experience.
repo_language: Java
owner: theonedev
file_changes: filename: ArtifactUploadPanel.java
change_type: ModificationType.MODIFY
diff: @@ -78,30 +78,35 @@ public abstract class ArtifactUploadPanel extends Panel {
 			protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
 				super.onSubmit(target, form);
 				
-				LockUtils.write(getBuild().getArtifactsLockKey(), new Callable<Void>() {
+				if (directory.contains("..")) {
+					error("'..' is not allowed in the directory");
+					target.add(feedback);
+				} else {
+					LockUtils.write(getBuild().getArtifactsLockKey(), new Callable<Void>() {
 
-					@Override
-					public Void call() throws Exception {
-						File artifactsDir = getBuild().getArtifactsDir();
-						for (FileUpload upload: uploads) {
-							String filePath = FilenameUtils.sanitizeFilename(upload.getFileName());
-							if (directory != null)
-								filePath = directory + "/" + filePath;
-							File file = new File(artifactsDir, filePath);
-							FileUtils.createDir(file.getParentFile());
-							try (	InputStream is = upload.getInputStream();
-									OutputStream os = new FileOutputStream(file)) {
-								IOUtils.copy(is, os);
-							} finally {
-								upload.release();
+						@Override
+						public Void call() throws Exception {
+							File artifactsDir = getBuild().getArtifactsDir();
+							for (FileUpload upload: uploads) {
+								String filePath = FilenameUtils.sanitizeFilename(upload.getFileName());
+								if (directory != null)
+									filePath = directory + "/" + filePath;
+								File file = new File(artifactsDir, filePath);
+								FileUtils.createDir(file.getParentFile());
+								try (	InputStream is = upload.getInputStream();
+										OutputStream os = new FileOutputStream(file)) {
+									IOUtils.copy(is, os);
+								} finally {
+									upload.release();
+								}
 							}
+							return null;
 						}
-						return null;
-					}
+						
+					});
 					
-				});
-				
-				onUploaded(target);
+					onUploaded(target);
+				}
 			}
 
 			@Override

programming_language: Java