fix: handle permission errors when browsing directories
Deploy Dashboard (Dev) / deploy-dev (push) Failing after 2m11s
Run Tests / Backend Tests (push) Failing after 5m47s
Run Tests / Frontend Tests (push) Failing after 1m30s
Run Tests / Test Summary (push) Failing after 14s
Run Tests / Frontend Tests (pull_request) Failing after 2m20s
Run Tests / Test Summary (pull_request) Failing after 18s
Run Tests / Backend Tests (pull_request) Failing after 4m9s

This commit is contained in:
Gan, Jimmy
2026-04-11 14:06:15 +08:00
parent 6ad885044b
commit 67c4394c2d
+11 -1
View File
@@ -66,8 +66,18 @@ def browse(path: str = ""):
target = _safe_path(path) target = _safe_path(path)
except ValueError: except ValueError:
raise HTTPException(status_code=403, detail="Access denied") raise HTTPException(status_code=403, detail="Access denied")
# Check if we have permission to read the directory
try:
items = list(target.iterdir())
except PermissionError:
raise HTTPException(status_code=403, detail="Permission denied")
except OSError as e:
logger.error(f"Error reading directory {target}: {e}")
raise HTTPException(status_code=500, detail="Error reading directory")
entries = [] entries = []
for item in sorted(target.iterdir()): for item in sorted(items):
try: try:
if not _is_safe_symlink(item): if not _is_safe_symlink(item):
continue continue