From eb05e8aa0e4d08e94245822c01a25dd2666f389a Mon Sep 17 00:00:00 2001 From: Aaro Varis Date: Sun, 29 Sep 2024 18:23:16 +0300 Subject: [PATCH] Set limit of 500mb for request body size and add API key validation --- index.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/index.js b/index.js index 545d09a..36420f3 100644 --- a/index.js +++ b/index.js @@ -7,6 +7,8 @@ app.use(express.json({ limit: '500mb' })); +const API_KEY = process.env.API_KEY || "silly!" + const RETRY_ERROR_CODES = [408, 500, 502, 503, 504, 522, 524, 599]; async function main() { @@ -95,6 +97,15 @@ async function main() { } app.post('/:instanceId', async (req, res) => { + + const apikey = req.headers['X-BatchHttp-Api-Key']; + if (apikey !== API_KEY) { + res.status(401).send({ + error: "Invalid API Key" + }); + return; + } + const instanceId = req.params.instanceId; //console.log(`Instance ID: ${instanceId}`); const body = req.body;