Password storage
An unsalted SHA-256 hash is the same for everyone who picks the same password, so attackers look it up in a precomputed list. Salted scrypt is different every time and slow to guess.
Fix: crypto.scrypt (or Argon2id) with a random salt per user, compared with timingSafeEqual.
Random tokens
Math.random() is built for speed, not secrecy. Its internal state can be recovered from a few outputs, after which every "random" reset link is predictable.
Fix: crypto.randomBytes(32) (or randomUUID, randomInt), and store only a hash of the token.
JWT verification
Edit a token and send it to two verifiers. The unsafe one lets the token pick its own algorithm ("none" means no signature check) and ignores expiry.
Fix: pin the algorithm on the server, compare signatures in constant time, and enforce exp.
Encryption
AES-CBC with a fixed IV encrypts the same message to the same bytes, and has no integrity check: editing the ciphertext silently edits the decrypted message.
Fix: AES-256-GCM with a fresh random IV per message. The auth tag makes any edit fail to decrypt.
Secrets & config
The value of JWT_SECRET the app starts with. The unsafe pattern falls back to a default and logs its config; the safe one refuses weak secrets and redacts logs.
Fix: load secrets from the environment, fail at startup if missing or short, and redact before logging.