From 6587c3f86563966e376319d7fee914e78068ab0a Mon Sep 17 00:00:00 2001 From: Niklas Date: Sat, 5 Sep 2026 12:45:26 +0200 Subject: [PATCH] fix(upload): send browser-like headers in from-url fetch (CDN 403s) --- backend/routes/upload.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/backend/routes/upload.js b/backend/routes/upload.js index c3c865c..b0ce87e 100644 --- a/backend/routes/upload.js +++ b/backend/routes/upload.js @@ -286,7 +286,14 @@ function downloadImage(imageUrl, maxRedirects = 5) { const parsed = new URL(imageUrl); const client = parsed.protocol === 'https:' ? https : http; - client.get(imageUrl, { timeout: 30000 }, (response) => { + // Browser-like headers: many CDNs (film.ai, frameset, etc.) reject + // requests without UA/Referer with 403. + const requestHeaders = { + "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0 Safari/537.36", + "Accept": "image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8", + "Referer": parsed.origin + "/", + }; + client.get(imageUrl, { timeout: 30000, headers: requestHeaders }, (response) => { // Follow redirects up to maxRedirects times if ([301, 302, 303, 307, 308].includes(response.statusCode) && response.headers.location) { if (maxRedirects <= 0) {