From 3b153a6c9b57bced1d14e316d03c002325cbf258 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Sat, 27 Apr 2024 21:54:28 +0300 Subject: [PATCH] Check that path exists before serving --- src/users.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/users.js b/src/users.js index cf64c41f2..10bea3fd0 100644 --- a/src/users.js +++ b/src/users.js @@ -612,9 +612,13 @@ function createRouteHandler(directoryFn) { try { const directory = directoryFn(req); const filePath = decodeURIComponent(req.params[0]); + const exists = fs.existsSync(path.join(directory, filePath)); + if (!exists) { + return res.sendStatus(404); + } return res.sendFile(filePath, { root: directory }); } catch (error) { - return res.sendStatus(404); + return res.sendStatus(500); } }; }