Skip to content

Commit fa469f9

Browse files
committed
Block redirects explicitly in fetch-url API route
1 parent ce84efe commit fa469f9

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/routes/api/fetch-url/+server.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,17 @@ export async function GET({ url, fetch }) {
4848

4949
const response = await fetch(targetUrl, {
5050
signal: controller.signal,
51-
redirect: "error", // Block all redirects
51+
redirect: "manual",
5252
headers: {
5353
"User-Agent": "HuggingChat-Attachment-Fetcher/1.0",
5454
},
5555
}).finally(() => clearTimeout(timeoutId));
5656

57+
// Explicitly block redirects
58+
if (response.status >= 300 && response.status < 400) {
59+
throw error(400, "Redirects are not allowed");
60+
}
61+
5762
if (!response.ok) {
5863
throw error(response.status, `Failed to fetch: ${response.statusText}`);
5964
}

0 commit comments

Comments
 (0)