fix(auth): reject ill-formed local passwords
This commit is contained in:
@@ -1,6 +1,14 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import { resolve } from "node:path";
|
||||
import { describe, expect, test } from "vitest";
|
||||
import { describe, expect, test, vi } from "vitest";
|
||||
|
||||
const { argon2SyncSpy } = vi.hoisted(() => ({ argon2SyncSpy: vi.fn() }));
|
||||
vi.mock("node:crypto", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("node:crypto")>();
|
||||
argon2SyncSpy.mockImplementation(actual.argon2Sync);
|
||||
return { ...actual, argon2Sync: argon2SyncSpy };
|
||||
});
|
||||
|
||||
import { verifyPassword } from "../src/auth/password.js";
|
||||
|
||||
interface Argon2Vector {
|
||||
@@ -27,6 +35,15 @@ describe("local Argon2id password verification", () => {
|
||||
}
|
||||
});
|
||||
|
||||
test("rejects ill-formed Unicode instead of authenticating as U+FFFD", () => {
|
||||
const replacementPassword = "correct horse battery stap\uFFFD";
|
||||
const loneSurrogatePassword = "correct horse battery stap\uD800";
|
||||
const replacementPasswordHash = "$argon2id$v=19$m=65536,t=3,p=1$AAECAwQFBgcICQoLDA0ODw$+tAXzgaQVnNaonNvgevyG6UKlaKcwyRMi1mESNk0BvQ";
|
||||
|
||||
expect(verifyPassword(replacementPassword, replacementPasswordHash)).toBe(true);
|
||||
expect(verifyPassword(loneSurrogatePassword, replacementPasswordHash)).toBe(false);
|
||||
});
|
||||
|
||||
test("rejects malformed and oversized PHC parameters before Argon2 allocation", () => {
|
||||
const password = vectors[0].password;
|
||||
const digest = vectors[0].phc.split("$")[5];
|
||||
@@ -40,8 +57,9 @@ describe("local Argon2id password verification", () => {
|
||||
];
|
||||
|
||||
for (const phc of cases) {
|
||||
expect(() => verifyPassword(password, phc)).not.toThrow();
|
||||
argon2SyncSpy.mockClear();
|
||||
expect(verifyPassword(password, phc)).toBe(false);
|
||||
expect(argon2SyncSpy).not.toHaveBeenCalled();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user