From 8eb398c5cc05e6c9120106383b92753a733e8523 Mon Sep 17 00:00:00 2001 From: Reto Brunner Date: Sun, 21 Apr 2024 15:49:51 +0200 Subject: [PATCH] server: don't throw in async callback from index requests This was flagged as an issue by codeQL > Server crash [High] > The server of this route handler will terminate when an > uncaught exception from this location escapes an > asynchronous callback. --- server/server.ts | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/server/server.ts b/server/server.ts index 2df32aef..ab8d2419 100644 --- a/server/server.ts +++ b/server/server.ts @@ -406,22 +406,20 @@ function forceNoCacheRequest(_req: Request, res: Response, next: NextFunction) { function indexRequest(_req: Request, res: Response) { res.setHeader("Content-Type", "text/html"); - return fs.readFile( - Utils.getFileFromRelativeToRoot("client/index.html.tpl"), - "utf-8", - (err, file) => { - if (err) { - throw err; - } - - const config: IndexTemplateConfiguration = { - ...getServerConfiguration(), - ...{cacheBust: Helper.getVersionCacheBust()}, - }; - - res.send(_.template(file)(config)); + fs.readFile(Utils.getFileFromRelativeToRoot("client/index.html.tpl"), "utf-8", (err, file) => { + if (err) { + log.error(`failed to server index request: ${err.name}, ${err.message}`); + res.sendStatus(500); + return; } - ); + + const config: IndexTemplateConfiguration = { + ...getServerConfiguration(), + ...{cacheBust: Helper.getVersionCacheBust()}, + }; + + res.send(_.template(file)(config)); + }); } function initializeClient(