CVE-2021-41185 (published 2021-10-26T15:15Z)

Mycodo is an environmental monitoring and regulation system. An exploit in versions prior to 8.12.7 allows anyone with access to endpoints to download files outside the intended directory. A patch has been applied and a release made. Users should upgrade to version 8.12.7. As a workaround, users may manually apply the changes from the fix commit.

Severity: MEDIUM
CVSS v2 base score: 4.0 (AV:N/AC:L/Au:S/C:P/I:N/A:N)
CVSS v3 base score: 6.5, MEDIUM (CVSS:3.1/AV:N/AC:L/PR:L/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/kizniche/Mycodo
commit_details: repo_url: https://github.com/kizniche/Mycodo
author: Kyle Gabriel
author_date: 2021-10-25 21:46:10-04:00
msg: Fix file exploit vulnerability (#1105)
repository: repo_url: https://github.com/kizniche/Mycodo
repo_name: kizniche/Mycodo
description: An environmental monitoring and regulation system
repo_language: Python
owner: kizniche
file_changes: filename: CHANGELOG.md
change_type: ModificationType.MODIFY
diff: @@ -1,4 +1,6 @@
-## 8.12.7 (Unreleased)
+## 8.12.7 (2021-10-25)
+
+This is a bugfix release that includes a fix to a severe security vulnerability. It is recommended that all users that have Mycodo exposed to the internet and allow guest access upgrade to patch this vulnerability. Users that only run Mycodo on a local network and/or don't allow unknown user (i.e. guest) access likely won't be affected.
 
 ### Bugfixes
 
@@ -7,6 +9,7 @@
  - Fix error when unauthenticated users attempting to land on the home page
  - Fix Gauge Widget dependencies ([#1100](https://github.com/kizniche/mycodo/issues/1100))
  - Fix installation of pigpiod
+ - Fix file exploit vulnerability ([#1105](https://github.com/kizniche/mycodo/issues/1105))
 
 ### Features
 

programming_language: Markdown
filename: routes_general.py
change_type: ModificationType.MODIFY
diff: @@ -117,7 +117,8 @@ def send_note_attachment(filename):
     file_path = os.path.join(PATH_NOTE_ATTACHMENTS, filename)
     if file_path is not None:
         try:
-            return send_file(file_path, as_attachment=True)
+            if os.path.abspath(file_path).startswith(PATH_NOTE_ATTACHMENTS):
+                return send_file(file_path, as_attachment=True)
         except Exception:
             logger.exception("Send note attachment")
 
@@ -149,7 +150,8 @@ def camera_img_return_path(camera_unique_id, img_type, filename):
         files = []
     if filename in files:
         path_file = os.path.join(path, filename)
-        return send_file(path_file, mimetype='image/jpeg')
+        if os.path.abspath(path_file).startswith(path):
+            return send_file(path_file, mimetype='image/jpeg')
 
     return "Image not found"
 

programming_language: Python