CVE-2023-28459 (published 2023-04-20T21:15Z)

pretalx 2.3.1 before 2.3.2 allows path traversal in HTML export (a non-default feature). Users were able to upload crafted HTML documents that trigger the reading of arbitrary files.

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/pretalx/pretalx
commit_details: repo_url: https://github.com/pretalx/pretalx
author: Tobias Kunze
author_date: 2023-03-07 13:04:03+01:00
msg: Fix path traversal in static HTML export

This vulnerability was discovered by Sonar,
https://www.sonarsource.com/, who provided a detailled description of
the vulnerability, and also the fix as it is applied here.

The fix will be backported to the last release, v2.3.1, and released as
v2.3.2. A blog post will be published on pretalx.com.
repository: repo_url: https://github.com/pretalx/pretalx
repo_name: pretalx/pretalx
description: Conference planning tool: CfP, scheduling, speaker management
repo_language: Python
owner: pretalx
file_changes: filename: export_schedule_html.py
change_type: ModificationType.MODIFY
diff: @@ -115,7 +115,9 @@ def dump_content(destination, path, getter):
     if path.endswith("/"):
         path = path + "index.html"
 
-    path = Path(destination) / path.lstrip("/")
+    path = (Path(destination) / path.lstrip("/")).resolve()
+    if not Path(destination) in path.parents:
+        raise CommandError("Path traversal detected, aborting.")
     path.parent.mkdir(parents=True, exist_ok=True)
 
     with open(path, "wb") as f:
@@ -131,6 +133,14 @@ def get_mediastatic_content(url):
     else:
         raise FileNotFoundError()
 
+    # Prevent directory traversal, make sure the path is inside the media or static root
+    local_path = local_path.resolve(strict=True)
+    if not any(
+        path in local_path.parents
+        for path in (settings.MEDIA_ROOT, settings.STATIC_ROOT)
+    ):
+        raise FileNotFoundError()
+
     with open(local_path, "rb") as f:
         return f.read()
 

programming_language: Python