From 843b535d7ca47c362e254669d0a3f149abe9ffc2 Mon Sep 17 00:00:00 2001 From: Viren070 Date: Mon, 9 Jun 2025 15:37:50 +0100 Subject: [PATCH] fix: add validation for encrypted data format in decryptString function --- packages/core/src/utils/crypto.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/core/src/utils/crypto.ts b/packages/core/src/utils/crypto.ts index b02b00f1..507ac5f3 100644 --- a/packages/core/src/utils/crypto.ts +++ b/packages/core/src/utils/crypto.ts @@ -114,6 +114,9 @@ export function decryptString(data: string, secretKey?: Buffer): Response { secretKey = Buffer.from(Env.SECRET_KEY, 'hex'); } try { + if (!isEncrypted(data)) { + throw new Error('The data was not in an expected encrypted format'); + } const [_, ivHex, encryptedHex] = decodeURIComponent(data).split(':'); const iv = Buffer.from(ivHex, 'base64'); const encrypted = Buffer.from(encryptedHex, 'base64');