From 725c7a1d24e3656743f5112dd29db088bfcd589e Mon Sep 17 00:00:00 2001 From: Ayane Satomi Date: Mon, 23 Oct 2023 13:32:04 +0000 Subject: [PATCH] feat: Add user agent check Add code to check if useragent is a browser --- routes/index.tsx | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/routes/index.tsx b/routes/index.tsx index 6320d00..29a86fb 100644 --- a/routes/index.tsx +++ b/routes/index.tsx @@ -74,6 +74,17 @@ export const handler: Handlers = { }, POST: async (req, ctx) => { const body = await req.json(); + const headers = req.headers; + + // check if useragent is a browser + // we can use the Sec-Ch-Ua header but it's not supported by all browsers + if (!headers.get("sec-ch-ua")) { + return new Response("", { + status: 403, + statusText: "Forbidden", + }); + } + await setGlobalStatistics(body.data); const updatedCount = await getGlobalStatistics();