CVE-2022-1721 (published 2022-05-16T15:15Z)

Path Traversal in WellKnownServlet in GitHub repository jgraph/drawio prior to 18.0.5. Read local files of the web application.

Severity: MEDIUM
CVSS v2 base score: 5.0 (AV:N/AC:L/Au:N/C:P/I:N/A:N)
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/jgraph/drawio
commit_details: repo_url: https://github.com/jgraph/drawio
author: David Benson
author_date: 2022-05-15 11:13:37+01:00
msg: Limit wellknown servlet to serve single file
repository: repo_url: https://github.com/jgraph/drawio
repo_name: jgraph/drawio
description: draw.io is a JavaScript, client-side editor for general diagramming.
repo_language: JavaScript
owner: jgraph
file_changes: filename: WellKnownServlet.java
change_type: ModificationType.MODIFY
diff: @@ -14,7 +14,7 @@ import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
 /**
- * Servlet to fake a .well-known directory
+ * Servlet to fake a .well-known directory, GAE does not directly support . prefixed directories
  */
 @SuppressWarnings("serial")
 public class WellKnownServlet extends HttpServlet
@@ -38,31 +38,41 @@ public class WellKnownServlet extends HttpServlet
 	{
         // GAE can't serve dot prefixed folders
         String uri = request.getRequestURI().replace("/.", "/");
-
-        if (uri.toLowerCase().contains(".json"))
-        {
-        	response.setContentType("application/json");
-        }
-
-        // Serve whatever was requested from .well-known
-        try (InputStream in = getServletContext().getResourceAsStream(uri))
+        
+        // Currently, there is only one file that this servlet serves. This is only
+        // needed if you want OneDrive integration. 
+        if (uri != null && uri.equals("/well-known/microsoft-identity-association.json"))
         {
-            if (in == null)
+            if (uri.toLowerCase().contains(".json"))
             {
-            	response.sendError(404);
-                return;
+                response.setContentType("application/json");
             }
-            
-            byte[] buffer = new byte[8192];
-            int count;
 
-            while ((count = in.read(buffer)) > 0)
+            // Serve whatever was requested from .well-known
+            try (InputStream in = getServletContext().getResourceAsStream(uri))
             {
-            	response.getOutputStream().write(buffer, 0, count);
+                if (in == null)
+                {
+                    response.sendError(404);
+                    return;
+                }
+                
+                byte[] buffer = new byte[8192];
+                int count;
+
+                while ((count = in.read(buffer)) > 0)
+                {
+                    response.getOutputStream().write(buffer, 0, count);
+                }
+                
+                response.getOutputStream().flush();
+                response.getOutputStream().close();
             }
-            
-            response.getOutputStream().flush();
-            response.getOutputStream().close();
+        }
+        else
+        {
+            response.sendError(404);
+            return;
         }
     }
 }

programming_language: Java