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:
1 parent
259c0c96ab
commit
818df3697b
3 files changed
+156
-39
No files matched your search
@@ -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", () => {
|
||||
|
||||
Reference in new issue
Block a user