← All lessons Stage 3 · Lesson 5
25 min

Broken authentication & session flaws

Stage 3 · Lesson 5 · 25 minutes · Requires Stage 1 Lesson 5


The one-line answer

Broken authentication means the way an application proves "you are who you say you are" — the login, the password reset, the session that keeps you logged in — has a gap that lets someone else become you.

The boundary: never test logins on real sites — not even "a few passwords on my friend's account." Trying credentials against accounts you don't own is unauthorised access. Labs and your own local apps only.


Why you should care

Every other protection depends on this one. If an attacker can log in as you, the server's access-control checks (Lesson 4) work perfectly — for the attacker.

You already tested two of these flaws in Stage 1 Lesson 5 (cookies & sessions). This lesson puts names on them and adds the rest of the family.


How it actually works

Authentication has two halves:

  1. Logging in — proving identity once (password, OTP, etc.).
  2. Staying logged in — the session: a token (usually a cookie) that says "this browser already proved who it is" (Stage 1 Lesson 5).

Flaws can be in either half.

Login flaws

Weak password rules. If 123456 or password is allowed, attackers will try them first. Huge lists of common and leaked passwords are public.

Credential stuffing. People reuse passwords. When one site is breached, attackers take the leaked email/password pairs and try them on other sites, automatically. No bug on your site is needed — only reused passwords and no defences against automated logins.

Brute force. Trying many passwords against one account. Works when there's no rate limit or lockout (recall Stage 2 Lesson 2 and its defensive angle).

Username enumeration. The login form gives different responses for "wrong username" and "wrong password":

You tryResponse
nosuchuser / anything"Invalid username"
carlos / wrong password"Incorrect password"

Now an attacker knows carlos exists, and only has to guess the password. The difference isn't always words — it can be a different status code, response length, or response time (Stage 2 Lesson 2 again: read all three).

Weak password reset. Reset links that never expire, reset tokens that are guessable, or reset flows that let you choose which email the link is sent to. Password reset is a second login door — often less carefully built.

Weak or missing MFA. Multi-factor authentication (an OTP or app code on top of the password) stops most credential attacks — unless it can be skipped (e.g. the app checks the code on one page but lets you jump straight to the dashboard).

Session flaws

Predictable session IDs. If tokens are like session=1001, 1002, 1003, the next user's session is easy to guess. Tokens must be long and random.

Session fixation. The session ID doesn't change when you log in. An attacker gives a victim a session ID they already know (for example via a crafted link), waits for the victim to log in with it, then uses the same ID — now authenticated.

Broken logout. Clicking "Log out" only deletes the cookie in the browser, but the server still accepts the old session token. Anyone who copied it (from a shared computer, a log, an XSS bug) stays logged in. You tested this in Stage 1 Lesson 5.

Sessions that never expire. A session from months ago still works.

Insecure cookie flags. Missing Secure (sent over plain HTTP), HttpOnly (readable by scripts — Lesson 3), or SameSite (sent on cross-site requests — Lesson 7).


See it yourself

Only on PortSwigger labs (they provide the wordlists and accounts):

  1. Read the Authentication topic introduction (link below).
  2. Do the apprentice lab on username enumeration via different responses. In Repeater, compare the response for a fake user and a real one — status, length, message.
  3. Do the apprentice lab on 2FA simple bypass. Note which page the server forgot to protect.
  4. Revisit your Stage 1 Lesson 5 notes on logout and session behaviour. Which of this lesson's flaws did you already test?

How attackers abuse this

  • Credential stuffing at scale with leaked password lists — the most common way consumer accounts get taken over.
  • Enumeration, then targeted guessing of real usernames.
  • Session theft (via XSS, malware, shared devices) followed by reuse because logout or expiry is broken.
  • Abusing password reset to take over accounts without knowing the password at all.

The defensive fix:

  • Rate-limit and protect login: limit attempts per account and per IP, add delays or CAPTCHA after failures, and alert on spikes (Stage 5).
  • Same response for every login failure: "Invalid username or password" — same message, same status, similar timing.
  • MFA, enforced on the server for every protected page.
  • Check passwords against known-breached lists and block the most common ones; allow long passphrases.
  • Strong session management:
  • long, random session IDs from the framework (never home-made),
  • issue a new session ID at login (stops fixation) and on privilege changes,
  • invalidate the session on the server at logout, not just in the browser,
  • idle and absolute expiry times,
  • cookies with Secure, HttpOnly and SameSite.
  • Secure password reset: single-use, short-lived, random tokens sent only to the account's registered email; same response whether or not the email exists.
  • Store passwords properly: slow, salted hashing (e.g. bcrypt or Argon2) — recall Stage 0 Lesson 6.

Common mistakes

  • Different error messages for bad username vs bad password — "to be helpful".
  • Deleting the cookie at logout but not ending the session on the server.
  • Keeping the same session ID before and after login.
  • MFA on the login page only, not enforced on the pages after it.
  • Treating password reset as minor. It's another way in, and needs the same care as login.
  • Practising on real accounts. Labs only.

Check yourself

  1. A login says "Incorrect password" for real users and "No such user" for fake ones. What's the flaw and the fix?
  2. What is session fixation, and what single change prevents it?
  3. A user clicks "Log out", but their old session cookie still works when replayed in Repeater. What's wrong?
Answers
  1. Username enumeration — attackers can discover valid usernames. Fix: return the same generic message, status code and similar timing for every failed login.
  2. The attacker gets the victim to log in using a session ID the attacker already knows, then reuses it. Issuing a new session ID at login prevents it.
  3. Logout only cleared the cookie in the browser; the server never invalidated the session. Logout must end the session server-side.

Your lab

  • PortSwigger Authentication vulnerabilities: https://portswigger.net/web-security/authentication

Writeup: the flaw, the exact response difference or missing check, and the specific fix.


Summary in your language

தமிழில் சுருக்கம்

Broken authentication என்பது login, password reset, session ஆகியவற்றில் உள்ள இடைவெளி — வேறு ஒருவர் நீங்களாக மாற அனுமதிக்கும். பலவீனமான கடவுச்சொற்கள், credential stuffing, brute force, username enumeration, பலவீனமான reset, MFA bypass ஆகியவை login பிழைகள். ஊகிக்கக்கூடிய session ID, session fixation, உடைந்த logout, காலாவதியாகாத session ஆகியவை session பிழைகள். தீர்வு: rate limiting, ஒரே மாதிரியான error செய்தி, MFA, login-இல் புதிய session ID, logout-இல் server-இல் session முடித்தல், Secure/HttpOnly/SameSite cookies.

हिंदी में सारांश

Broken authentication का मतलब है login, password reset या session में कमी — जिससे कोई और आप बन सकता है। कमज़ोर passwords, credential stuffing, brute force, username enumeration, कमज़ोर reset और MFA bypass — ये login की गलतियाँ हैं। अनुमान लगाने लायक session ID, session fixation, टूटा logout और कभी expire न होने वाले sessions — ये session की गलतियाँ हैं। इलाज: rate limiting, एक जैसा error message, MFA, login पर नया session ID, logout पर server-side session ख़त्म करना, और Secure/HttpOnly/SameSite cookies।

Want this summary in Malayalam, Telugu, Kannada or another language? Tell us — the most requested languages get added next.


What's next

From identity to files — escaping the folder you were meant to stay in: Path traversal and file upload flaws