Migrate from AES-256-CBC to AES-256-GCM for authenticated encryption

- Replace CBC+HMAC with GCM (built-in authentication via authTag)
- Remove createHmac and timingSafeEqual imports (no longer needed)
- Remove Snyk-ignore comments (no longer suppressible findings)
- Update test: tampered MAC test -> tampered auth tag test
- Add one-time migration script for existing CBC-encrypted 2FA secrets
This commit is contained in:
openhands committed 2026-07-10 23:51:56 +02:00
1 parent 259c0c96ab
commit 818df3697b
3 files changed
+156 -39

No files matched your search

+3 -3
View File
@@ -28,13 +28,13 @@ describe("LaravelEncrypter", () => {
expect(enc.decryptString(payload)).toBe("hello world");
});
it("fails closed when the MAC is tampered", () => {
it("fails closed when the auth tag is tampered", () => {
const enc = new LaravelEncrypter(APP_KEY);
const payload = enc.encrypt("x");
const json = JSON.parse(Buffer.from(payload, "base64").toString("utf8"));
json.mac = "00".repeat(32);
json.tag = Buffer.alloc(16).toString("base64"); // zeroed auth tag
const tampered = Buffer.from(JSON.stringify(json), "utf8").toString("base64");
expect(() => enc.decrypt(tampered)).toThrow(/MAC is invalid/);
expect(() => enc.decrypt(tampered)).toThrow();
});
it("decrypts a payload produced with a fresh instance of the same key", () => {