CVE-2022-31506 (published 2022-07-11T01:15Z)

The cmusatyalab/opendiamond repository through 10.1.1 on GitHub allows absolute path traversal because the Flask send_file function is used unsafely.

Severity: MEDIUM
CVSS v2 base score: 6.4 (AV:N/AC:L/Au:N/C:P/I:N/A:P)
CVSS v3 base score: 9.3, CRITICAL (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:N/A:L)

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/cmusatyalab/opendiamond
commit_details: repo_url: https://github.com/cmusatyalab/opendiamond
author: Jan Harkes
author_date: 2022-05-04 09:57:21-04:00
msg: Fix path traversal issues in all dataretriever backends
repository: repo_url: https://github.com/cmusatyalab/opendiamond
repo_name: cmusatyalab/opendiamond
description: Interactive search of non-indexed data
repo_language: Python
owner: cmusatyalab
file_changes: filename: augment_store.py
change_type: ModificationType.MODIFY
diff: @@ -24,7 +24,7 @@ from itertools import cycle
 from flask import Blueprint, url_for, Response, stream_with_context, send_file, \
     jsonify
 from werkzeug.datastructures import Headers
-from werkzeug.utils import safe_join
+from werkzeug.security import safe_join
 from opendiamond.dataretriever.util import read_file_list, write_data
 
 

programming_language: Python
filename: diamond_store.py
change_type: ModificationType.MODIFY
diff: @@ -17,6 +17,7 @@ from xml.sax.saxutils import quoteattr
 from flask import Blueprint, url_for, Response, stream_with_context, send_file, \
     jsonify
 from werkzeug.datastructures import Headers
+from werkzeug.security import safe_join
 
 from opendiamond.dataretriever.util import ATTR_SUFFIX
 
@@ -120,11 +121,11 @@ def _get_object_src_uri(object_path):
 
 
 def _get_obj_absolute_path(obj_path):
-    return os.path.join(DATAROOT, obj_path)
+    return safe_join(DATAROOT, obj_path)
 
 
 def _get_index_absolute_path(index):
-    return os.path.join(INDEXDIR, index)
+    return safe_join(INDEXDIR, index)
 
 
 @scope_blueprint.route('/obj/<path:obj_path>')

programming_language: Python
filename: mixer_store.py
change_type: ModificationType.MODIFY
diff: @@ -24,6 +24,7 @@ from itertools import cycle
 from flask import Blueprint, url_for, Response, stream_with_context, send_file, \
     jsonify
 from werkzeug.datastructures import Headers
+from werkzeug.security import safe_join
 
 BASEURL = 'cocktail'
 STYLE = False
@@ -249,11 +250,11 @@ def _get_obj_path(obj_path):
     return obj_path.replace(DATAROOT+'/', '')
 
 def _get_obj_absolute_path(obj_path):
-    return os.path.join(DATAROOT, obj_path)
+    return safe_join(DATAROOT, obj_path)
 
 
 def _get_index_absolute_path(index):
-    return os.path.join(INDEXDIR, index)
+    return safe_join(INDEXDIR, index)
 
 
 @scope_blueprint.route('/obj/<path:obj_path>')

programming_language: Python
filename: test_store.py
change_type: ModificationType.MODIFY
diff: @@ -24,6 +24,8 @@ from itertools import cycle
 from flask import Blueprint, url_for, Response, stream_with_context, send_file, \
     jsonify
 from werkzeug.datastructures import Headers
+from werkzeug.security import safe_join
+
 from opendiamond.dataretriever.test_utils import *
 
 
@@ -279,11 +281,11 @@ def _get_obj_path(obj_path):
     return obj_path.replace(DATAROOT+'/', '')
 
 def _get_obj_absolute_path(obj_path):
-    return os.path.join(DATAROOT, obj_path)
+    return safe_join(DATAROOT, obj_path)
 
 
 def _get_index_absolute_path(index):
-    return os.path.join(INDEXDIR, index)
+    return safe_join(INDEXDIR, index)
 
 
 @scope_blueprint.route('/obj/<path:obj_path>')

programming_language: Python
filename: video_store.py
change_type: ModificationType.MODIFY
diff: @@ -21,6 +21,7 @@ from math import ceil
 from flask import Blueprint, Response, request, stream_with_context, url_for
 from opendiamond.dataretriever.util import DiamondTextAttr
 from werkzeug.datastructures import Headers
+from werkzeug.security import safe_join
 
 # IMPORTANT: requires ffmpeg >= 3.3. Lower versions produce incorrect clipping.
 
@@ -122,11 +123,11 @@ def _get_object_element(start, span, video):
 
 
 def _get_obj_absolute_path(obj_path):
-    return os.path.join(DATAROOT, obj_path)
+    return safe_join(DATAROOT, obj_path)
 
 
 def _get_index_absolute_path(index):
-    return os.path.join(INDEXDIR, index)
+    return safe_join(INDEXDIR, index)
 
 
 def _ffprobe(video_path):

programming_language: Python
filename: yfcc100m_mysql_store.py
change_type: ModificationType.MODIFY
diff: @@ -29,6 +29,7 @@ from flask import Blueprint, url_for, Response, \
 import logging
 import mysql.connector
 from werkzeug.datastructures import Headers
+from werkzeug.security import safe_join
 from xml.sax.saxutils import quoteattr
 
 BASEURL = 'yfcc100m_mysql'
@@ -124,7 +125,7 @@ def get_object_id(dataset, seq_no):
 
 @scope_blueprint.route('/obj/<dataset>/<path:rel_path>')
 def get_object_src_http(dataset, rel_path):
-    path = _get_obj_abosolute_path(dataset, rel_path)
+    path = _get_obj_absolute_path(dataset, rel_path)
     response = send_file(path,
                          cache_timeout=datetime.timedelta(
                              days=365).total_seconds(),
@@ -133,8 +134,8 @@ def get_object_src_http(dataset, rel_path):
     return response
 
 
-def _get_obj_abosolute_path(dataset, rel_path):
-    return os.path.join(DATAROOT, dataset, rel_path)
+def _get_obj_absolute_path(dataset, rel_path):
+    return safe_join(DATAROOT, dataset, rel_path)
 
 
 def _get_object_element(dataset, seq_no, rel_path, download_link):
@@ -162,7 +163,7 @@ def _get_object_element(dataset, seq_no, rel_path, download_link):
         rel_path, download_link = row[0], row[1]
 
     if LOCAL_OBJ_URI:
-        src_uri = 'file://' + os.path.join(DATAROOT, dataset, rel_path)
+        src_uri = 'file://' + _get_obj_absolute_path(dataset, rel_path)
     else:
         src_uri = url_for('.get_object_src_http', dataset=dataset, rel_path=rel_path)
 

programming_language: Python