CVE-2020-5230 (published 2020-01-30T21:15Z)

Opencast before 8.1 and 7.6 allows almost arbitrary identifiers for media packages and elements to be used. This can be problematic for operation and security since such identifiers are sometimes used for file system operations which may lead to an attacker being able to escape working directories and write files to other locations. In addition, Opencast's Id.toString(…) vs Id.compact(…) behavior, the latter trying to mitigate some of the file system problems, can cause errors due to identifier mismatch since an identifier may unintentionally change. This issue is fixed in Opencast 7.6 and 8.1.

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-74
cwe_name: Improper Neutralization of Special Elements in Output Used by a Downstream Component ('Injection')
description: The product constructs all or part of a command, data structure, or record using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify how it is parsed or interpreted when it is sent to a downstream component.
extended_description: Software or other automated logic has certain assumptions about what constitutes data and control respectively. It is the lack of verification of these assumptions for user-controlled input that leads to injection problems. Injection problems encompass a wide variety of issues -- all mitigated in very different ways and usually attempted in order to alter the control flow of the process. For this reason, the most effective way to discuss these weaknesses is to note the distinct features that 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.
         

Fix information:
repo_url: https://github.com/opencast/opencast
commit_details: repo_url: https://github.com/opencast/opencast
author: Lars Kiesow
author_date: 2020-01-16 23:34:35+01:00
msg: Limit Characters Allowed In Ids

Opencast allows almost arbitrary identifiers for media packages and
elements to be used. This can be problematic for operation and security
since such identifiers are sometimes used for file system operations
which may lead to attacker being able to escape working directories and
write files to other locations.

In addition, Opencast's `Id.toString(…)` vs `Id.compact(…)` behavior,
the latter trying to mitigate some of the file system problems, can
cause errors due to identifier mismatch since an identifier may
unintentionally change.

This patch limits the characters allowed to be used in identifiers to
ensure no unsafe operations are possible and no mismatch may happen.
repository: repo_url: https://github.com/opencast/opencast
repo_name: opencast/opencast
description: The free and open source solution for automated video capture and distribution at scale.
repo_language: Java
owner: opencast
file_changes: filename: Id.java
change_type: ModificationType.MODIFY
diff: @@ -41,6 +41,7 @@ public interface Id {
    *
    * @return a path separator-free representation of the identifier
    */
+  @Deprecated
   String compact();
 
   class Adapter extends XmlAdapter<IdImpl, Id> {

programming_language: Java
filename: IdImpl.java
change_type: ModificationType.MODIFY
diff: @@ -22,6 +22,8 @@
 
 package org.opencastproject.mediapackage.identifier;
 
+import java.util.regex.Pattern;
+
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlType;
@@ -34,6 +36,8 @@ import javax.xml.bind.annotation.XmlValue;
 @XmlAccessorType(XmlAccessType.NONE)
 public class IdImpl implements Id {
 
+  private static final Pattern pattern = Pattern.compile("[\\w-_.:;()]+");
+
   /** The identifier */
   @XmlValue
   protected String id = null;
@@ -50,7 +54,10 @@ public class IdImpl implements Id {
    * @param id
    *          the identifier
    */
-  public IdImpl(String id) {
+  public IdImpl(final String id) {
+    if (!pattern.matcher(id).matches()) {
+      throw new IllegalArgumentException("Id must match " + pattern);
+    }
     this.id = id;
   }
 
@@ -60,7 +67,7 @@ public class IdImpl implements Id {
    * @see org.opencastproject.mediapackage.identifier.Id#compact()
    */
   public String compact() {
-    return id.replaceAll("/", "-").replaceAll("\\\\", "-");
+    return toString();
   }
 
   @Override

programming_language: Java
filename: IngestRestService.java
change_type: ModificationType.MODIFY
diff: @@ -837,11 +837,14 @@ public class IngestRestService extends AbstractJobProducerEndpoint {
           return Response.serverError().status(Status.BAD_REQUEST).build();
         }
 
-        WorkflowInstance workflow = (wdID == null) ? ingestService.ingest(mp) : ingestService.ingest(mp, wdID,
-                workflowProperties);
+        WorkflowInstance workflow = (wdID == null)
+            ? ingestService.ingest(mp)
+            : ingestService.ingest(mp, wdID, workflowProperties);
         return Response.ok(workflow).build();
       }
       return Response.serverError().status(Status.BAD_REQUEST).build();
+    } catch (IllegalArgumentException e) {
+      return Response.status(Status.BAD_REQUEST).entity(e.getMessage()).build();
     } catch (Exception e) {
       logger.warn(e.getMessage(), e);
       return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();

programming_language: Java