From 4a5e4e8ca2e1d56ea2984661d40a402104834171 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sun, 20 Jun 2021 09:38:01 -0700 Subject: [PATCH] Safer cover image naming --- bookwyrm/models/fields.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bookwyrm/models/fields.py b/bookwyrm/models/fields.py index 4ec46504c..b59b61072 100644 --- a/bookwyrm/models/fields.py +++ b/bookwyrm/models/fields.py @@ -408,7 +408,8 @@ class ImageField(ActivitypubFieldMixin, models.ImageField): return None image_content = ContentFile(response.content) - image_name = str(uuid4()) + "." + imghdr.what(None, image_content.read()) + extension = imghdr.what(None, image_content.read()) or "" + image_name = "{:s}.{:s}".format(str(uuid4()), extension) return [image_name, image_content] def formfield(self, **kwargs):