Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

fix: use resizable image MIME types in Accept header for external image fetch (#5599)

kyrisu847ab5e0cde0
diff --git a/apps/builder/app/routes/rest.assets_.$name.tsx b/apps/builder/app/routes/rest.assets_.$name.tsx
index c7f348b8ed..d59fa8f171 100644
--- a/apps/builder/app/routes/rest.assets_.$name.tsx
+++ b/apps/builder/app/routes/rest.assets_.$name.tsx
@@ -3,7 +3,7 @@ import type { ActionFunctionArgs } from "@remix-run/server-runtime";
import { uploadFile } from "@webstudio-is/asset-uploader/index.server";
import {
isAllowedMimeCategory,
- IMAGE_MIME_TYPES,
+ RESIZABLE_IMAGE_MIME_TYPES,
ALLOWED_FILE_TYPES,
} from "@webstudio-is/sdk";
import type { AssetActionResponse } from "~/builder/shared/assets";
@@ -50,7 +50,7 @@ export const action = async (
const imageRequest = await fetch(url, {
method: "GET",
headers: {
- Accept: IMAGE_MIME_TYPES.join(","),
+ Accept: RESIZABLE_IMAGE_MIME_TYPES.join(","),
},
});
diff --git a/packages/sdk/src/assets.ts b/packages/sdk/src/assets.ts
index b4f202bd63..33668d8c7d 100644
--- a/packages/sdk/src/assets.ts
+++ b/packages/sdk/src/assets.ts
@@ -151,6 +151,22 @@ export const IMAGE_MIME_TYPES: readonly string[] = IMAGE_EXTENSIONS.map(
(ext) => ALLOWED_FILE_TYPES[ext as keyof typeof ALLOWED_FILE_TYPES]
);
+/**
+ * Subset of IMAGE_MIME_TYPES supported as input by the image resizing pipeline.
+ * Used in the Accept header when fetching external images to prevent services
+ * like Unsplash (with auto=format) from serving formats like AVIF that cause
+ * Cloudflare Image Resizing ERROR 9520 during transformation.
+ *
+ * See: https://developers.cloudflare.com/images/transform-images/#supported-input-formats
+ */
+export const RESIZABLE_IMAGE_MIME_TYPES: readonly string[] = [
+ "image/jpeg",
+ "image/png",
+ "image/gif",
+ "image/webp",
+ "image/svg+xml",
+];
+
/**
* All video file extensions
*/