Force .pdf extension on uploaded files regardless of user input

The file content is already validated as PDF, so the user-supplied
extension should not be trusted or written to disk.
This commit is contained in:
Pier-Jean Malandrino 2026-04-03 13:03:21 +02:00
parent c28f734e71
commit 8856daf3c9

View file

@ -32,7 +32,7 @@ async def upload(filename: str, content_type: str, file_content: bytes) -> Docum
os.makedirs(UPLOAD_DIR, exist_ok=True)
ext = os.path.splitext(filename)[1] or ".pdf"
ext = ".pdf" # Content already validated as PDF
safe_name = f"{uuid.uuid4()}{ext}"
file_path = os.path.join(UPLOAD_DIR, safe_name)