Fix scrypt hash generation in plaintext fallback
- Adjusted `generateScryptHash` parameter in plaintext fallback logic in `lib/auth.ts` to use `storedPassword` instead of the intermediate hashed value. This prevents users from getting locked out when they adopt the recommended hash. - Enhanced plaintext fallback verification to hash `password` and `storedPassword` via keyed HMAC before executing `crypto.timingSafeEqual` to avoid potential timing attacks more securely. Co-authored-by: ralksta <16941050+ralksta@users.noreply.github.com>
This commit is contained in:
12
lib/auth.ts
12
lib/auth.ts
@@ -111,12 +111,18 @@ export function authenticate(
|
||||
} else {
|
||||
// Plaintext fallback (deprecated)
|
||||
// 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(storedPassword).digest();
|
||||
const attemptHash = crypto
|
||||
.createHmac('sha256', getConfig().authSecret)
|
||||
.update(password)
|
||||
.digest();
|
||||
const storedHash = crypto
|
||||
.createHmac('sha256', getConfig().authSecret)
|
||||
.update(storedPassword)
|
||||
.digest();
|
||||
isValid = crypto.timingSafeEqual(attemptHash, storedHash);
|
||||
|
||||
if (isValid) {
|
||||
const recommendedHash = generateScryptHash(storedHash.toString('hex'));
|
||||
const recommendedHash = generateScryptHash(storedPassword);
|
||||
console.warn(
|
||||
`\n⚠️ SECURITY WARNING: ${type === 'subpage' ? 'Subpage' : 'Album'} "${key}" is using a plaintext password in gallery.yaml.\n` +
|
||||
` Please replace it with this native secure hash:\n\n ${recommendedHash}\n`,
|
||||
|
||||
Reference in New Issue
Block a user