fix: improve authentication and container reliability
- Update admin login logic to include email validation and optional fallback - Make Docker builds flexible for missing lockfiles - Standardize on 'node' user in web Dockerfile - Improve Nginx header forwarding for proxies - Add volume persistence and health dependency to compose file
This commit is contained in:
1 parent
1a1c19d7bb
commit
fa4516b078
5 files changed
+52
-25
No files matched your search
+22
-10
@@ -443,18 +443,30 @@ export async function verifyAdminCredentials(email: string, password: string) {
|
||||
const result = await pool.query(
|
||||
`SELECT email, password_salt, password_hash
|
||||
FROM admin_users
|
||||
WHERE email = $1`,
|
||||
[cleanEmail],
|
||||
WHERE id = 1`,
|
||||
);
|
||||
if (result.rowCount && result.rowCount > 0) {
|
||||
const admin = result.rows[0] as
|
||||
| { email: string; password_salt: Buffer; password_hash: Buffer }
|
||||
| undefined;
|
||||
const salt = admin?.password_salt ?? Buffer.alloc(PASSWORD_SALT_BYTES);
|
||||
const expectedHash =
|
||||
admin?.password_hash ?? Buffer.alloc(PASSWORD_HASH_BYTES);
|
||||
const actualHash = await derivePasswordHash(password, salt);
|
||||
return Boolean(admin && timingSafeEqual(actualHash, expectedHash));
|
||||
const admin = result.rows[0] as {
|
||||
email: string;
|
||||
password_salt: Buffer;
|
||||
password_hash: Buffer;
|
||||
};
|
||||
const emailMatches = matchesSecret(
|
||||
cleanEmail,
|
||||
admin.email.trim().toLowerCase(),
|
||||
);
|
||||
const actualHash = await derivePasswordHash(
|
||||
password,
|
||||
admin.password_salt,
|
||||
);
|
||||
const passwordMatches = timingSafeEqual(
|
||||
actualHash,
|
||||
admin.password_hash,
|
||||
);
|
||||
return emailMatches && passwordMatches;
|
||||
}
|
||||
if (!process.env.DATASTACK_ADMIN_PASSWORD) {
|
||||
return false;
|
||||
}
|
||||
} catch {
|
||||
// Database connection error, fall back to in-memory admin
|
||||
|
||||
Reference in new issue
Block a user