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 @@
## 2025-03-01 - Path Traversal in API Files Get Endpoint
**Vulnerability:** Found a critical path traversal vulnerability in `api/api_files_get.py` where user-provided paths (like `../../../etc/passwd`) were directly used to read and return file contents without verifying if they were within the application's base directory.
**Learning:** `files.get_abs_path()` uses `os.path.join` which resolves `..` paths naturally. But `os.path.join` on its own doesn't restrict paths to a specific root directory. Thus, absolute path resolution does not inherently prevent path traversal.
**Prevention:** Always validate resolved paths using `helpers.files.is_in_base_dir()` before performing file reading or writing operations based on user input.
5 changes: 5 additions & 0 deletions api/api_files_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ async def process(self, input: dict, request: Request) -> dict | Response:
external_path = path
filename = os.path.basename(path)

# Security check: ensure path is within base directory to prevent path traversal
if not files.is_in_base_dir(external_path):
PrintStyle.warning(f"Access denied: path traversal detected for {path}")
continue

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