Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix(docat): Icon-Upload Mime Type Check #290

Merged
merged 1 commit into from
Oct 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion docat/docat/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from pathlib import Path
from typing import Optional

import magic
from fastapi import Depends, FastAPI, File, Header, Response, UploadFile, status
from fastapi.staticfiles import StaticFiles
from pydantic import BaseModel
Expand Down Expand Up @@ -129,7 +130,10 @@ def upload_icon(
response.status_code = status.HTTP_404_NOT_FOUND
return ApiResponse(message=f"Project {project} not found")

if not file.content_type.startswith("image/"):
mime_type_checker = magic.Magic(mime=True)
mime_type = mime_type_checker.from_buffer(file.file.read())

if not mime_type.startswith("image/"):
response.status_code = status.HTTP_400_BAD_REQUEST
return ApiResponse(message="Icon must be an image")

Expand Down
Loading