From abd4b411fa9fd96fd9177ff2dce64328a49756a9 Mon Sep 17 00:00:00 2001 From: ShubhamPalriwala Date: Mon, 10 Jun 2024 10:34:25 +0530 Subject: [PATCH] fix: add limit to character length in api as well --- .../secret-sharing/secret-sharing-service.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/backend/src/services/secret-sharing/secret-sharing-service.ts b/backend/src/services/secret-sharing/secret-sharing-service.ts index ac9dafe32..4748dbc3e 100644 --- a/backend/src/services/secret-sharing/secret-sharing-service.ts +++ b/backend/src/services/secret-sharing/secret-sharing-service.ts @@ -40,6 +40,20 @@ export const secretSharingServiceFactory = ({ if (new Date(expiresAt) < new Date()) { throw new BadRequestError({ message: "Expiration date cannot be in the past" }); } + + // Limit Expiry Time to 1 month + const expiryTime = new Date(expiresAt).getTime(); + const currentTime = new Date().getTime(); + const thirtyDays = 30 * 24 * 60 * 60 * 1000; + if (expiryTime - currentTime > thirtyDays) { + throw new BadRequestError({ message: "Expiration date cannot be more than 30 days currently." }); + } + + // Limit Input ciphertext length to 13000 (equivalent to 10,000 characters of Plaintext) + if (encryptedValue.length > 13000) { + throw new BadRequestError({ message: "Shared Secret Value too long" }); + } + const newSharedSecret = await secretSharingDAL.create({ encryptedValue, iv, @@ -67,6 +81,11 @@ export const secretSharingServiceFactory = ({ throw new BadRequestError({ message: "Expiration date cannot be more than 30 days currently." }); } + // Limit Input ciphertext length to 13000 (equivalent to 10,000 characters of Plaintext) + if (encryptedValue.length > 13000) { + throw new BadRequestError({ message: "Shared Secret Value too long" }); + } + const newSharedSecret = await secretSharingDAL.create({ encryptedValue, iv,