Skip to content

A complete AI agency at your fingertips - From frontend wizards to Reddit community ninjas, from whimsy injectors to reality checkers. Each agent is a specialized expert with personality, processes, and proven deliverables.

Shell

Reject malformed stored password records without throwing

Rudy Celeklibaa773207b97
diff --git a/security/security-appsec-engineer.md b/security/security-appsec-engineer.md
index 441285a7..0c62f4df 100644
--- a/security/security-appsec-engineer.md
+++ b/security/security-appsec-engineer.md
@@ -140,10 +140,13 @@ function hashPassword(password: string): string {
}
function verifyPassword(password: string, storedHash: string): boolean {
- const [salt, hash] = storedHash.split(':');
+ // Match the format produced by hashPassword before decoding or deriving.
+ const match = /^([0-9a-f]{64}):([0-9a-f]{128})$/i.exec(storedHash);
+ if (!match) return false;
+ const [, salt, hash] = match;
const inputHash = scryptSync(password, salt, 64);
const storedBuffer = Buffer.from(hash, 'hex');
- // Constant-time comparison — same duration regardless of where mismatch occurs
+ // The validated hash has the same byte length, as timingSafeEqual requires.
return timingSafeEqual(inputHash, storedBuffer);
}