Skip to content

Commit e5e6c4d

Browse files
committed
modify browse endpoint according to github security check
1 parent 960b021 commit e5e6c4d

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

cli/medperf/web_ui/api/routes.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ def browse_directory(
2121
):
2222
full_path = os.path.abspath(os.path.join(BASE_DIR, path))
2323

24-
if not os.path.exists(full_path) or not os.path.isdir(full_path):
25-
raise HTTPException(status_code=404, detail="Directory not found")
26-
2724
# Ensure path is within the base directory
28-
if not os.path.commonpath([BASE_DIR, full_path]) == BASE_DIR:
25+
if not full_path.startswith(BASE_DIR):
2926
raise HTTPException(status_code=403, detail="Access denied")
3027

28+
if not os.path.exists(full_path) or not os.path.isdir(full_path):
29+
raise HTTPException(status_code=404, detail="Directory not found")
30+
3131
# List directories inside the path and sort them
3232
sorted_folders = []
3333
sorted_files = []

0 commit comments

Comments
 (0)