Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
@@ -234,28 +234,28 @@ async def startup_event():
|
|
234 |
# import sys
|
235 |
# sys.exit(1) # Consider exiting if questions are critical
|
236 |
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
#
|
242 |
-
|
243 |
-
#
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
async def get_task_file(task_id: str):
|
260 |
"""
|
261 |
Serves the file associated with a specific task ID.
|
|
|
234 |
# import sys
|
235 |
# sys.exit(1) # Consider exiting if questions are critical
|
236 |
|
237 |
+
|
238 |
+
# --- Your Endpoints ---
|
239 |
+
@app.get("/files/{task_id}", ...)
|
240 |
+
async def get_task_file(task_id: str):
|
241 |
+
# ... (endpoint logic) ...
|
242 |
+
try:
|
243 |
+
# --- Ensure it uses the globally defined variable ---
|
244 |
+
abs_base_path = ALLOWED_CACHE_BASE # Uses the variable defined above
|
245 |
+
abs_file_path = os.path.abspath(local_file_path)
|
246 |
+
|
247 |
+
# Add extra debug logging right before the check
|
248 |
+
logger.debug(f"Security Check - Comparing: file='{abs_file_path}' against base='{abs_base_path}'")
|
249 |
+
|
250 |
+
if not abs_file_path.startswith(abs_base_path):
|
251 |
+
logger.error(f"SECURITY FAILURE: Path mismatch. File '{abs_file_path}' is NOT within allowed base '{abs_base_path}'.")
|
252 |
+
raise HTTPException(status_code=403, detail="File access denied.")
|
253 |
+
# ... rest of the endpoint ...
|
254 |
+
except Exception as e:
|
255 |
+
# ... error handling ...
|
256 |
+
# Log the base path again in case of error context
|
257 |
+
logger.error(f"Error during file access. Base path check was against: {ALLOWED_CACHE_BASE}")
|
258 |
+
raise e # Or handle appropriately
|
259 |
async def get_task_file(task_id: str):
|
260 |
"""
|
261 |
Serves the file associated with a specific task ID.
|