CVE-2021-21248 (published 2021-01-15T21:15Z)

OneDev is an all-in-one devops platform. In OneDev before version 4.0.3, there is a critical vulnerability involving the build endpoint parameters. InputSpec is used to define parameters of a Build spec. It does so by using dynamically generated Groovy classes. A user able to control job parameters can run arbitrary code on OneDev's server by injecting arbitrary Groovy code. The ultimate result is in the injection of a static constructor that will run arbitrary code. For a full example refer to the referenced GHSA. This issue was addressed in 4.0.3 by escaping special characters such as quote from user input.

Severity: MEDIUM
CVSS v2 base score: 6.5 (AV:N/AC:L/Au:S/C:P/I:P/A:P)
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-94
cwe_name: Improper Control of Generation of Code ('Code Injection')
description: The product constructs all or part of a code segment using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the syntax or behavior of the intended code segment.
extended_description: 
            When a product allows a user's input to contain code syntax, it might be possible for an attacker to craft the code in such a way that it will alter the intended control flow of the product. Such an alteration could lead to arbitrary code execution.
            Injection problems encompass a wide variety of issues -- all mitigated in very different ways. For this reason, the most effective way to discuss these weaknesses is to note the distinct features which classify them as injection weaknesses. The most important issue to note is that all injection problems share one thing in common -- i.e., they allow for the injection of control plane data into the user-controlled data plane. This means that the execution of the process may be altered by sending code in through legitimate data channels, using no other mechanism. While buffer overflows, and many other flaws, involve the use of some further issue to gain execution, injection problems need only for the data to be parsed. The most classic instantiations of this category of weakness are SQL injection and format string vulnerabilities.
         
         

Fix information:
repo_url: https://github.com/theonedev/onedev
commit_details: repo_url: https://github.com/theonedev/onedev
author: Robin Shen
author_date: 2020-11-20 14:52:30+08:00
msg: Escape pattern field of build job param to prevent security vulnerability
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: InputSpec.java
change_type: ModificationType.MODIFY
diff: @@ -105,7 +105,7 @@ public abstract class InputSpec implements Serializable {
 		return Lists.newArrayList();
 	}
 
-	protected String escape(String string) {
+	public static String escape(String string) {
 		String escaped = JavaEscape.escapeJava(string);
 		// escape $ character since it has special meaning in groovy string
 		escaped = escaped.replace("$", "\\$");

programming_language: Java
filename: TextInput.java
change_type: ModificationType.MODIFY
diff: @@ -15,6 +15,7 @@ public class TextInput {
 
 	public static String getPropertyDef(InputSpec inputSpec, Map<String, Integer> indexes, 
 			String pattern, DefaultValueProvider defaultValueProvider) {
+		pattern = InputSpec.escape(pattern);
 		int index = indexes.get(inputSpec.getName());
 		StringBuffer buffer = new StringBuffer();
 		inputSpec.appendField(buffer, index, "String");
@@ -24,7 +25,7 @@ public class TextInput {
 		if (pattern != null)
 			buffer.append("    @Pattern(regexp=\"" + pattern + "\", message=\"Should match regular expression: " + pattern + "\")\n");
 		inputSpec.appendMethods(buffer, index, "String", null, defaultValueProvider);
-		
+
 		return buffer.toString();
 	}
 

programming_language: Java
filename: Test.java
change_type: ModificationType.MODIFY
diff: @@ -5,5 +5,5 @@ public class Test {
 	@org.junit.Test
 	public void test() {
 	}		
-	
+
 }
\ No newline at end of file

programming_language: Java