From 5df025e9cbfc20330574672ad253d9a30dc70dbc Mon Sep 17 00:00:00 2001 From: Jonathan Barrow Date: Sun, 2 Apr 2023 20:34:12 -0400 Subject: [PATCH] Added more checks to token middleware --- src/middleware/token.ts | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/middleware/token.ts b/src/middleware/token.ts index bfbe64b..bc0600f 100644 --- a/src/middleware/token.ts +++ b/src/middleware/token.ts @@ -2,8 +2,24 @@ import express from 'express'; import { decryptAndUnpackToken, jsonEncodeUTF16LE } from '@/util'; function tokenMiddleware(request: express.Request, response: express.Response, next: express.NextFunction): void { - // * RPG Maker appends a single F character to each service token, for some reason - request.token = decryptAndUnpackToken(request.args.token.substring(1)); + if (!request.token) { + response.send(jsonEncodeUTF16LE({ + EndCode: 102 + })); + + return; + } + + try { + // * RPG Maker appends a single F character to each service token, for some reason + request.token = decryptAndUnpackToken(request.args.token.substring(1)); + } catch (error) { + response.send(jsonEncodeUTF16LE({ + EndCode: 102 + })); + + return; + } const expireTime: number = Math.floor((Number(request.token.expire_time) / 1000));