Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
thumbnail: Properly re-derive Content-Disposition for original uploads.
Alex Vandiverb53a33a5bcff
diff --git a/zerver/migrations/0544_copy_avatar_images.py b/zerver/migrations/0544_copy_avatar_images.pyindex a0b8bfcb0f8..8a0c3ce7406 100644--- a/zerver/migrations/0544_copy_avatar_images.py+++ b/zerver/migrations/0544_copy_avatar_images.py@@ -48,6 +48,19 @@ def old_hash(user_profile: Any) -> str:return hashlib.sha1(user_key.encode()).hexdigest()+# Just the image types from zerver.lib.upload.INLINE_MIME_TYPES+INLINE_IMAGE_MIME_TYPES = [+ "image/apng",+ "image/avif",+ "image/gif",+ "image/jpeg",+ "image/png",+ "image/webp",+ # To avoid cross-site scripting attacks, DO NOT add types such+ # as image/svg+xml.+]++def thumbnail_s3_avatars(users: QuerySet[Any]) -> None:avatar_bucket = boto3.resource("s3",@@ -81,13 +94,21 @@ def thumbnail_s3_avatars(users: QuerySet[Any]) -> None:print(f"Failed to fetch {old_base}")continue+ # INLINE_IMAGE_MIME_TYPES changing (e.g. adding+ # "image/avif") means this may not match the old+ # content-disposition.+ inline_type = old_data["ContentType"] in INLINE_IMAGE_MIME_TYPES+ extra_params = {}+ if not inline_type:+ extra_params["ContentDisposition"] = "attachment"+avatar_bucket.Object(new_base + ".original").copy_from(CopySource=f"{settings.S3_AVATAR_BUCKET}/{old_base}.original",MetadataDirective="REPLACE",Metadata=metadata,- ContentDisposition=old_data["ContentDisposition"],ContentType=old_data["ContentType"],CacheControl="public, max-age=31536000, immutable",+ **extra_params, # type: ignore[arg-type] # The dynamic kwargs here confuse mypy.)small = resize_avatar(original_bytes, DEFAULT_AVATAR_SIZE)