Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .jules/sentinel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## 2024-07-02 - [Fix Path Traversal in ApiFilesGet]
**Vulnerability:** The API endpoint `api_files_get.py` allowed arbitrary file reading via path traversal (e.g., `../../../etc/passwd`) and unrestricted absolute paths, because user-provided file paths were resolved without checking if they remained within the application's base directory.
**Learning:** User-provided file paths, even when authenticated or considered "internal" by the frontend, must never be trusted. They must be validated against the application's intended root directory after being resolved to their absolute form.
**Prevention:** Always use `files.is_in_base_dir(resolved_path)` (or equivalent boundary checks) to validate that any file path received from a client stays within the safe boundaries before reading, writing, or executing the file.
4 changes: 4 additions & 0 deletions api/api_files_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ async def process(self, input: dict, request: Request) -> dict | Response:
external_path = path
filename = os.path.basename(path)

if not files.is_in_base_dir(external_path):
PrintStyle.warning(f"Access denied. Path outside base directory: {path}")
continue

# Check if file exists
if not os.path.exists(external_path):
PrintStyle.warning(f"File not found: {path}")
Expand Down