Security Playbook
by Federico Tejedor Llorente
Learn
Learning path
Concepts
Breaches
Practice
Labs
Playground
Quiz
Work with me
🔥 0
⚡ 0
Playbooks
Playbooks
System Design
Security
●
Algorithms
Portfolio
↗
en
English
✓
Español
← All code reviews
Find the bug · 06/10
Easy
Sign up with a salted hash
There's even a random salt per user. What's still wrong?
lib/users.ts
01 · Tap the vulnerable line
1
import { createHash, randomBytes } from "node:crypto";
2
3
export async function createUser(email: string, password: string) {
4
const salt = randomBytes(16).toString("hex");
5
const hash = createHash("sha256").update(salt + password).digest("hex");
6
return db.user.create({ data: { email, salt, hash } });
7
}
02 · What's the problem?
Weak password hashing
Secret exposed to the client
SQL injection
No rate limiting
03 · How do you fix it?
Use a slow password hash: argon2id (or bcrypt with cost ≥ 12)
Hash it twice with SHA-256
Use SHA-512 instead of SHA-256
Check answer