Compare commits

...

4 Commits

Author SHA1 Message Date
glay
0ec1ae6276 Enhance encryption security with additional safeguards. 2024-12-10 11:55:14 +08:00
glay
cb0422b8f2 Enhance processChunks by attempting to recover by processing the next chunk. 2024-12-10 11:53:49 +08:00
glay
e455840ab3 Update app/utils/aws.ts
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
2024-12-10 11:47:30 +08:00
glay
19437c7aa1 Enhance encryption security with additional safeguards. 2024-12-10 11:35:26 +08:00

View File

@@ -10,7 +10,7 @@ type ParsedEvent = Record<string, any>;
type EventResult = ParsedEvent[];
// Using a dot as separator since it's not used in Base64
const SEPARATOR = ".";
const SEPARATOR = "~";
// Unified crypto utilities for both frontend and backend
async function generateKey(
@@ -85,7 +85,7 @@ export async function encrypt(
return [saltBase64, ivBase64, encryptedBase64].join(SEPARATOR);
} catch (error) {
console.error("[Encryption Error]:", error);
// console.error("[Encryption Error]:", error);
throw new Error("Failed to encrypt AWS credentials");
}
}
@@ -121,7 +121,6 @@ export async function decrypt(
const dec = new TextDecoder();
return dec.decode(decrypted);
} catch (error) {
console.error("[Decryption Error]:", error);
throw new Error("Failed to decrypt AWS credentials");
}
}
@@ -610,9 +609,18 @@ export function processChunks(
chunks.shift();
}
} catch (e) {
console.error("[Chunk Process Error]:", e);
chunks.shift(); // Remove error chunk
pendingChunk = null; // Reset pending chunk on error
// console.error("[Chunk Process Error]:", e);
// chunks.shift(); // Remove error chunk
// pendingChunk = null; // Reset pending chunk on error
console.warn("Failed to process chunk, attempting recovery");
// Attempt to recover by processing the next chunk
if (chunks.length > 1) {
chunks.shift();
pendingChunk = null;
} else {
// If this is the last chunk, throw to prevent data loss
throw new Error("Failed to process final chunk");
}
}
}