Open to everyone Reading, lesson 56 of 100, 2 min read
Sign-in and session flaws
Getting sign-in right
Sign-in and sessions are where attackers aim first. Common mistakes, and their fixes:
| Mistake | Fix |
|---|---|
| No limit on guesses | Rate limiting and temporary lockouts per account and per address |
| Different messages for "no such user" and "wrong password" | One generic message, so attackers cannot list valid accounts |
| Weak passwords allowed | Minimum length (at least 12 is common), block known breached and common passwords |
| Passwords stored badly | Salted, slow hashes (Argon2, bcrypt) |
| No MFA option | Offer it to everyone; require it for admins |
| Session ID in the URL | Keep it in a secure cookie only |
| Session not renewed at sign-in | Issue a new session ID when the user signs in (prevents session fixation) |
| Sessions never expire | Idle and absolute time-outs |
| Sign-out does nothing on the server | Destroy the session on the server, not just the cookie |
| Password reset links that never expire or can be guessed | Long random single-use tokens, valid for a short time, stored hashed |
Password reset is a sign-in door too
Attackers love weak reset flows. A good one:
- Always says "if that email has an account, we sent a link", whether or not it exists.
- Sends a single-use link that expires in under an hour.
- Ends all other sessions after the password changes.
- Notifies the user that the password was changed.
Changing important details
When a user changes their email, password or bank details, ask for the current password (or MFA) again, and notify the old email address. This stops a stolen session from quietly taking over an account.
APIs
Mobile apps and other systems use APIs. They need the same care: authentication on every call, authorisation for each object, rate limits, and API keys treated as passwords (shown once, stored hashed, revocable).
Tip
As a user, the "sign out of all other sessions" button is worth knowing. Use it after signing in on a shared computer.