Description of the Bug
In backend/app/routes/profile.py, the avatar upload endpoint has no file size limit:
@router.post("/avatar", response_model=UserResponse)
def upload_avatar(
file: UploadFile = File(...),
...
):
allowed_extensions = [".png", ".jpg", ".jpeg"]
extension = Path(file.filename).suffix.lower()
if extension not in allowed_extensions:
raise ValidationException("Invalid image format")
filename = f"{uuid.uuid4()}{extension}"
filepath = UPLOAD_DIR / filename
with open(filepath, "wb") as buffer:
shutil.copyfileobj(file.file, buffer)
Only the file extension is validated. There is no:
- Content-length check
max_length parameter on UploadFile
- Size validation before writing to disk
- Disk quota enforcement
An attacker could upload a multi-gigabyte file, consuming all available disk space on the server. This is a denial-of-service vulnerability.
The document upload endpoint has proper size validation via MAX_UPLOAD_SIZE_MB but the avatar endpoint lacks any such protection.
Steps to Reproduce
- Authenticate as any user
- Send a POST request to
/profile/avatar with a very large image file (e.g., 10GB)
- The server writes the entire file to disk without checking its size
- Disk space is consumed
Expected Behavior
The avatar upload should reject files exceeding a reasonable size (e.g., 5MB) before writing to disk. Add a configurable MAX_AVATAR_SIZE_MB setting.
Affected File
backend/app/routes/profile.py (lines ~36-52)
Suggested Fix
Add size validation:
MAX_AVATAR_SIZE = 5 * 1024 * 1024 # 5MB
if file.size and file.size > MAX_AVATAR_SIZE:
raise ValidationException("Avatar image must be under 5MB")
Or use file = File(..., max_length=5_000_000) to have FastAPI enforce the limit.
GSSoC '26
Description of the Bug
In
backend/app/routes/profile.py, the avatar upload endpoint has no file size limit:Only the file extension is validated. There is no:
max_lengthparameter onUploadFileAn attacker could upload a multi-gigabyte file, consuming all available disk space on the server. This is a denial-of-service vulnerability.
The document upload endpoint has proper size validation via
MAX_UPLOAD_SIZE_MBbut the avatar endpoint lacks any such protection.Steps to Reproduce
/profile/avatarwith a very large image file (e.g., 10GB)Expected Behavior
The avatar upload should reject files exceeding a reasonable size (e.g., 5MB) before writing to disk. Add a configurable
MAX_AVATAR_SIZE_MBsetting.Affected File
backend/app/routes/profile.py(lines ~36-52)Suggested Fix
Add size validation:
Or use
file = File(..., max_length=5_000_000)to have FastAPI enforce the limit.GSSoC '26