From ac3bab3074233a34516f95f20439d329e4fe1039 Mon Sep 17 00:00:00 2001 From: = Date: Fri, 21 Feb 2025 14:38:34 +0530 Subject: [PATCH] feat: added min check for secret sharing --- .../services/secret-sharing/secret-sharing-service.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/backend/src/services/secret-sharing/secret-sharing-service.ts b/backend/src/services/secret-sharing/secret-sharing-service.ts index b0f66c3e3..f907649e7 100644 --- a/backend/src/services/secret-sharing/secret-sharing-service.ts +++ b/backend/src/services/secret-sharing/secret-sharing-service.ts @@ -62,6 +62,11 @@ export const secretSharingServiceFactory = ({ throw new BadRequestError({ message: "Expiration date cannot be more than 30 days" }); } + const fiveMins = 5 * 60 * 1000; + if (expiryTime - currentTime < fiveMins) { + throw new BadRequestError({ message: "Expiration time cannot be less than 5 mins" }); + } + if (secretValue.length > 10_000) { throw new BadRequestError({ message: "Shared secret value too long" }); } @@ -112,6 +117,11 @@ export const secretSharingServiceFactory = ({ throw new BadRequestError({ message: "Expiration date cannot exceed more than 30 days" }); } + const fiveMins = 5 * 60 * 1000; + if (expiryTime - currentTime < fiveMins) { + throw new BadRequestError({ message: "Expiration time cannot be less than 5 mins" }); + } + const encryptWithRoot = kmsService.encryptWithRootKey(); const encryptedSecret = encryptWithRoot(Buffer.from(secretValue));