Courses

Session Hijacking
OSWE · Chapter 6

Session Hijacking

Session hijacking is the theft or prediction of a valid session identifier, letting an attacker impersonate a logged-in user without ever knowing their password. It is usually the end-goal of an XSS or network sniffing attack, or the result of weak session ID generation.

Key concepts

  • Session IDs need at least 64 bits of entropy from a cryptographically secure random source — predictable or sequential IDs can be brute-forced or guessed.
  • Cookies carrying session IDs should always set `HttpOnly` (blocks JS access, mitigating XSS-based theft), `Secure` (HTTPS-only), and `SameSite` (CSRF defense in depth).
  • Regenerate the session ID on any privilege change (login, password change) to prevent session fixation attacks.
  • Bind sessions to additional signals (IP range, User-Agent) as a detection layer — not a hard security boundary, since these can be spoofed, but useful for anomaly alerts.

Try it yourself

Inspect the `Set-Cookie` header of any site you use, and check whether the session cookie sets `HttpOnly`, `Secure`, and `SameSite`. Note which protections are missing, if any.

@ Daniel Burlacu