diff --git a/.jules/sentinel.md b/.jules/sentinel.md new file mode 100644 index 0000000000..ccec0563fc --- /dev/null +++ b/.jules/sentinel.md @@ -0,0 +1,4 @@ +## 2024-05-24 - [Path Traversal in API Files Get] + **Vulnerability:** Unrestricted file path loading in `/api/files/get` allowing users to read any file on the machine like `/etc/passwd`. + **Learning:** Paths weren't validated against the application's base directory before reading them to standard response outputs. + **Prevention:** Use explicit checks like `files.is_in_base_dir(external_path)` to ensure paths cannot traverse outside intended bounds. diff --git a/api/api_files_get.py b/api/api_files_get.py index b2533f4f4f..ec24d570b9 100644 --- a/api/api_files_get.py +++ b/api/api_files_get.py @@ -62,6 +62,11 @@ async def process(self, input: dict, request: Request) -> dict | Response: external_path = path filename = os.path.basename(path) + # Security: Prevent path traversal + if not files.is_in_base_dir(external_path): + PrintStyle.warning(f"Access denied to file outside base dir: {path}") + continue + # Check if file exists if not os.path.exists(external_path): PrintStyle.warning(f"File not found: {path}")