Skip to content

Session Hijacking and Fixation

Session hijacking is taking over another user's authenticated session by stealing or guessing the session identifier. Session fixation is the reverse: the attacker plants a known identifier before the user logs in and reuses it afterwards.

DraftLast reviewed Oct 11, 20262 scriptsEdit this page on GitHub

This page is a draft: its scripts were tested in a lab, but its references still need an independent review.

On this page

After this lesson you can

  • Explain what Session Hijacking and Fixation is in your own words.
  • Describe how the attack or technique works.
  • Walk through a real-world example from start to finish.
  • Recognise it using the detection techniques in this lesson.
  • Apply the prevention methods described here.
  • Read and run the 2 Python scripts in a lab you control.
  • Relate the topic to T1539, CWE-384, CWE-613 in the standards.

Last reviewed: 2026-10-11 | Status: Draft (new topic; scripts tested against local lab targets, references not yet independently re-verified)

Standards mapping

FrameworkReference
OWASP Top 10:2025Authentication Failures (session management)
MITRE ATT&CK (v19)Credential Access / T1539 Steal Web Session Cookie
CWECWE-384 Session Fixation; CWE-613 Insufficient Session Expiration
CAPECCAPEC-593 Session Hijacking
Example CVEnot applicable

What it is

Session hijacking is taking over another user's authenticated session by stealing or guessing the session identifier. Session fixation is the reverse: the attacker plants a known identifier before the user logs in and reuses it afterwards.

How it works

After login the site gives the browser a session id and trusts it on every request. Anyone who obtains that id (from network sniffing on plain HTTP, XSS reading document.cookie, malware, a leaked log, or a guessable id) can present it and act as the user. With fixation, the site keeps the id it was given before login, so the attacker already knows the post-login id.

Real-world example

In October 2010 the Firesheep extension showed that anyone on shared Wi-Fi could hijack accounts on major sites that only encrypted the login page. The publicity pushed large sites to serve whole sessions over HTTPS.

Detection

  • Missing Secure, HttpOnly or SameSite cookie flags (session_security_checker.py)
  • Low-entropy, short, repeated or sequential session ids
  • The session id unchanged after login (fixation test)
  • The same session id used from two different browsers or networks at nearly the same time

Prevention

In order of strength. The first items fix the cause; the rest reduce risk.

  1. Serve the whole site over HTTPS and send HSTS
  2. Random 128-bit-plus ids from a CSPRNG; store only a hash server-side
  3. Issue a new id at login and on privilege change; destroy the old one
  4. Secure; HttpOnly; SameSite cookie attributes and the __Host- prefix
  5. Idle and absolute timeouts; real logout that destroys the server-side session
  6. Fix XSS: it is the most common way to read session cookies

Scripts in this topic

Common mistakes

  • Encrypting only the login page
  • Binding a session to an IP address that changes on mobile networks without a fallback
  • Using the user id or a timestamp as the session id
  • Logging out only on the client by deleting the cookie

Test it safely

Only test systems you own or have written permission to test. Practice against a deliberately vulnerable app such as OWASP Juice Shop or DVWA, or a local test server you write yourself.

Practical Python labs

Open a script to read its source and copy the run commands. Run security tools only on systems you own or have written permission to test.

Check what you have covered

These questions are generated from this lesson's category, standards mapping and scripts. They test where things live in the guide, not how well you understand the concepts. Nothing is saved or tracked.

1.Which category is "Session Hijacking and Fixation" part of?
2.Which MITRE ATT&CK identifier is listed in the standards mapping for "Session Hijacking and Fixation"?
3.Which of these scripts belongs to the "Session Hijacking and Fixation" lesson?
4.Is secure_session.py a detection script or a prevention script?