fix(19): WR-03 make scrypt hashing async (threadpool) to avoid event-loop starvation DoS

This commit is contained in:
Lucas Berger
2026-06-17 20:30:28 -04:00
parent 322929aebe
commit 30ad25c026
8 changed files with 81 additions and 42 deletions
+6 -2
View File
@@ -141,6 +141,10 @@ adminRouter.post(
COLOR_PALETTE.find((c) => !usedColors.has(c)) ??
COLOR_PALETTE[usedColors.size % COLOR_PALETTE.length];
// WR-03: hash the initial password BEFORE opening the transaction so the (now async,
// threadpool) scrypt work does not hold the DB transaction open for its duration.
const initialPasswordHash = await hashPassword(initialPassword);
try {
let newUserId: number;
@@ -163,7 +167,7 @@ adminRouter.post(
await tx.insert(localCredentials).values({
userId: newUserId,
username,
passwordHash: hashPassword(initialPassword),
passwordHash: initialPasswordHash,
});
});
@@ -236,7 +240,7 @@ adminRouter.post(
try {
await db
.update(localCredentials)
.set({ passwordHash: hashPassword(newPassword) })
.set({ passwordHash: await hashPassword(newPassword) })
.where(eq(localCredentials.userId, targetId));
// CR-04: an admin password reset must immediately clear any rate-limit / lockout