fix(auth): secure plaintext password comparison against timing attacks (#68)

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
This commit is contained in:
Ralksta
2026-04-01 12:46:04 +02:00
committed by GitHub
parent b8833b4e60
commit 258c36899c
2 changed files with 10 additions and 2 deletions

View File

@@ -96,7 +96,11 @@ export function authenticate(slug: string, password: string): string | null {
isValid = verifyScrypt(password, sp.password);
} else {
// Plaintext fallback (deprecated)
isValid = password === sp.password;
// Hash both to a fixed length before constant-time comparison to prevent timing and length attacks
const attemptHash = crypto.createHash('sha256').update(password).digest();
const storedHash = crypto.createHash('sha256').update(sp.password).digest();
isValid = crypto.timingSafeEqual(attemptHash, storedHash);
if (isValid) {
const recommendedHash = generateScryptHash(sp.password);
console.warn(