From 8c30c3fb108cf2ced9ea99017c4773583175ced9 Mon Sep 17 00:00:00 2001 From: Apoorv Mishra Date: Tue, 5 Sep 2023 13:43:48 +0530 Subject: [PATCH] fix: jwt.verify handles expiration --- server/storage/files/LocalStorage.ts | 8 ++++---- server/utils/jwt.ts | 7 ------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/server/storage/files/LocalStorage.ts b/server/storage/files/LocalStorage.ts index b04120da15..5b78b9c1cf 100644 --- a/server/storage/files/LocalStorage.ts +++ b/server/storage/files/LocalStorage.ts @@ -85,12 +85,12 @@ export default class LocalStorage extends BaseStorage { const sig = JWT.sign( { key, - expiresAt: expiresIn - ? new Date(Date.now() + expiresIn * 1000) - : undefined, type: "attachment", }, - env.SECRET_KEY + env.SECRET_KEY, + { + expiresIn, + } ); return Promise.resolve(`/api/files.get?sig=${sig}`); }; diff --git a/server/utils/jwt.ts b/server/utils/jwt.ts index 4a9146364e..5f87db9579 100644 --- a/server/utils/jwt.ts +++ b/server/utils/jwt.ts @@ -105,13 +105,6 @@ export async function getAttachmentForJWT(token: string): Promise { throw AuthenticationError("Invalid token"); } - // check the token is within it's expiration time - if (payload.expiresAt) { - if (new Date(payload.expiresAt) < new Date()) { - throw AuthenticationError("Expired token"); - } - } - const attachmentId = payload.key.split("/")[2]; const attachment = await Attachment.findByPk(attachmentId, { rejectOnEmpty: true,