fix: add validation for encrypted data format in decryptString function

This commit is contained in:
Viren070
2025-06-09 15:37:50 +01:00
parent edc310fe5f
commit 843b535d7c
+3
View File
@@ -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');