From c7dcccd7a1899d400bc9ddd3cdfde5db37e12bc4 Mon Sep 17 00:00:00 2001 From: Madeline <46743919+MaddyUnderStars@users.noreply.github.com> Date: Mon, 24 Oct 2022 16:51:41 +1100 Subject: Handle fetch errors in cdn external endpoint --- src/cdn/routes/external.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/cdn/routes/external.ts b/src/cdn/routes/external.ts index 32979a59..08e6b164 100644 --- a/src/cdn/routes/external.ts +++ b/src/cdn/routes/external.ts @@ -74,11 +74,14 @@ router.get("/resize/:url", async (req: Request, res: Response) => { let buffer, response; try { response = await fetch(url, DEFAULT_FETCH_OPTIONS); + if (response.status !== 200) throw "e"; // lol super gross buffer = await response.buffer(); } catch (e) { throw new HTTPError("Couldn't fetch website"); } + if (buffer.length == 0) throw new HTTPError("Website response was empty."); + if (response.headers.get("content-type")?.indexOf("image") === -1) { throw new HTTPError("Content type is not image."); } -- cgit 1.4.1