Compare commits
1 Commits
alert-auto
...
alert-auto
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a4e2122382 |
@@ -942,20 +942,9 @@ async def serve_product_avatar(
|
||||
if current_user_id != user_id:
|
||||
raise HTTPException(status_code=403, detail="Access denied")
|
||||
|
||||
# Restrict to a filename only (no nested paths)
|
||||
requested_name = Path(filename)
|
||||
if requested_name.is_absolute() or requested_name.name != filename:
|
||||
raise HTTPException(status_code=400, detail="Invalid filename")
|
||||
|
||||
# Locate and validate video file path within user's avatar directory
|
||||
# Locate video file
|
||||
base_dir = Path(__file__).parent.parent.parent
|
||||
user_root = (base_dir / "product_avatars" / current_user_id).resolve()
|
||||
video_path = (user_root / requested_name).resolve()
|
||||
|
||||
try:
|
||||
video_path.relative_to(user_root)
|
||||
except ValueError:
|
||||
raise HTTPException(status_code=400, detail="Invalid filename")
|
||||
video_path = base_dir / "product_avatars" / user_id / filename
|
||||
|
||||
if not video_path.exists():
|
||||
raise HTTPException(status_code=404, detail="Video not found")
|
||||
@@ -963,7 +952,7 @@ async def serve_product_avatar(
|
||||
return FileResponse(
|
||||
path=str(video_path),
|
||||
media_type="video/mp4",
|
||||
filename=requested_name.name
|
||||
filename=filename
|
||||
)
|
||||
|
||||
except HTTPException:
|
||||
|
||||
@@ -40,29 +40,25 @@ async def serve_video_studio_video(
|
||||
video_studio_videos_dir = base_dir / "video_studio_videos"
|
||||
video_path = video_studio_videos_dir / user_id / video_filename
|
||||
|
||||
# Security: Ensure path is within video_studio_videos directory
|
||||
# Security: Resolve and ensure path is within video_studio_videos directory
|
||||
try:
|
||||
resolved_path = video_path.resolve()
|
||||
resolved_base = video_studio_videos_dir.resolve()
|
||||
if not str(resolved_path).startswith(str(resolved_base)):
|
||||
raise HTTPException(
|
||||
status_code=403,
|
||||
detail="Invalid video path"
|
||||
)
|
||||
resolved_path = video_path.resolve()
|
||||
resolved_path.relative_to(resolved_base)
|
||||
except (OSError, ValueError) as e:
|
||||
logger.error(f"[VideoStudio] Path resolution error: {e}")
|
||||
raise HTTPException(status_code=403, detail="Invalid video path")
|
||||
|
||||
# Check if file exists
|
||||
if not video_path.exists() or not video_path.is_file():
|
||||
if not resolved_path.exists() or not resolved_path.is_file():
|
||||
raise HTTPException(
|
||||
status_code=404,
|
||||
detail=f"Video not found: {video_filename}"
|
||||
)
|
||||
|
||||
logger.info(f"[VideoStudio] Serving video: {video_path}")
|
||||
logger.info(f"[VideoStudio] Serving video: {resolved_path}")
|
||||
return FileResponse(
|
||||
path=str(video_path),
|
||||
path=str(resolved_path),
|
||||
media_type="video/mp4",
|
||||
filename=video_filename,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user