From ce3936e2f6d05bdc3eba1d3536f5c0ea7ded7585 Mon Sep 17 00:00:00 2001 From: Yadd Date: Fri, 22 Mar 2024 15:10:36 +0400 Subject: [PATCH] Fix: db response may be empty --- packages/matrix-identity-server/src/utils.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/matrix-identity-server/src/utils.ts b/packages/matrix-identity-server/src/utils.ts index 1653c7a0..1c64f4bd 100644 --- a/packages/matrix-identity-server/src/utils.ts +++ b/packages/matrix-identity-server/src/utils.ts @@ -60,7 +60,17 @@ export const Authenticate = ( if (token != null) { db.get('accessTokens', ['data'], { id: token }) .then((rows) => { - callback(JSON.parse(rows[0].data as string), token) + // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions + if (!rows || rows.length === 0) { + logger.error( + `${req.socket.remoteAddress as string} sent an inexistent token ${ + token as string + }` + ) + send(res, 401, errMsg('unAuthorized')) + } else { + callback(JSON.parse(rows[0].data as string), token) + } }) .catch((e) => { logger.error(