Security operations

HTTP Session Hijacking: How It Works and How to Stop It

Session hijacking skips the login entirely. Here is how attackers steal session cookies, how to spot a hijacked session, and the controls that stop it.

Cysoro Security TeamPublished · 8 min read
Session cookieStolen in secondsAttacker replays it — no password SECURITY OPERATIONS Sessionhijacking Logged in — without logging in.
Quick answer

HTTP session hijacking is an attack in which someone steals or reuses a valid session token, usually a cookie, to take over a user's already-authenticated web session. Because the session is already trusted, the attacker skips the password and MFA and looks like the real user. The main defenses are HTTPS everywhere, Secure and HttpOnly cookies with SameSite, short session lifetimes, session rotation, and token binding or continuous access evaluation where supported.

Key takeaways

  • Session hijacking happens after login, so MFA alone does not stop it.
  • Infostealer malware, adversary-in-the-middle phishing, and cross-site scripting are the main ways session tokens are stolen.
  • Revoke sessions and refresh tokens first, then reset credentials and check the device for malware.

You log in, pass MFA, and get on with your work. An attacker who steals the session cookie issued at that moment does not need your password or your MFA code. They simply replay the cookie and become you.

What is HTTP session hijacking?

HTTP session hijacking is an attack in which someone steals or reuses a valid session token, usually a cookie, to take over a user's already-authenticated web session. The server trusts the token, so it treats the attacker as the real user.

HTTP is stateless, so a website needs a way to remember that you are logged in. After you sign in, it gives your browser a session ID, normally stored as a cookie and sent with every request. That ID is, in OWASP's words, temporarily equivalent to the strongest authentication method used by the application, which is why stealing it is so powerful.

The attack has particular relevance to web developers, because the HTTP cookies used to maintain a session on many websites can be stolen by an attacker with access to network traffic or to saved cookies on the victim's computer. Once the attacker has the cookie, they inject it into their own browser and use the account.

Session hijacking is sometimes called cookie hijacking, and MITRE ATT&CK tracks the related techniques as Steal Web Session Cookie and Use Alternate Authentication Material: Web Session Cookie, under adversary-in-the-middle and credential access techniques.

How does HTTP session hijacking work?

Session hijacking happens in three phases. First, a legitimate user logs in and the server issues a session token. Second, the attacker steals that token. Third, the attacker replays it from their own browser or tool and gains the same access as the victim.

The server cannot tell the difference, because the token is the proof of login. It does not ask for the password again, and it does not ask for MFA again, unless the application is set up to re-check during the session. That is the core weakness: the session is trusted, not the person holding it.

Modern browsers and HTTPS have made the oldest method, sniffing cookies on public Wi-Fi, much less common. The main methods now are malware, phishing proxies, and web flaws, which work even when the site uses HTTPS correctly.

Attackers often act quickly once they have a token. They change the email or password, add a new MFA device, set up mail-forwarding rules, or move money, before the victim notices anything is wrong.

How session hijacking works1. User logs inServer issues asession cookie2. Attacker steals itMalware, phishingproxy, or XSS3. Attacker replays itNo password,no MFA neededThe server trusts the cookie, not the person holding it.
Session hijacking in three phases. Illustration by Cysoro.

What are the main types of session hijacking?

The main types are session sidejacking, session fixation, cross-site scripting theft, and malware theft, plus adversary-in-the-middle phishing. Each steals the token in a different way, but the result is the same.

TypeHow the token is stolenMain defense
Session sidejackingSniffing network traffic for unencrypted cookiesHTTPS everywhere, Secure cookies, HSTS
Session fixationAttacker sets the victim's session ID before loginRotate session ID on login
Cross-site scripting (XSS)Malicious script reads the cookie from the browserHttpOnly cookies, XSS fixes, CSP
Infostealer malwareMalware copies cookies from the browser storeEndpoint protection, short sessions
Adversary-in-the-middlePhishing proxy relays login and captures tokenToken binding, continuous evaluation
Session predictionAttacker guesses a weak or sequential session IDRandom IDs with at least 64 bits of entropy

Session fixation deserves a closer look. The attacker sends the victim a link containing a session ID the attacker already knows. When the victim logs in, the server keeps that same ID, so the attacker can now use it. Rotating the session ID at login stops this attack outright.

Session prediction is rarer now, because modern frameworks generate random IDs. OWASP recommends session IDs with at least 64 bits of entropy, generated by a cryptographically secure random number generator, and at least 128 bits when creating your own IDs. A predictable or sequential ID is a serious flaw.

How does adversary-in-the-middle phishing steal sessions?

Adversary-in-the-middle, or AiTM, phishing is now the most important session hijacking method for business accounts. A proxy site sits between the victim and the real login page, relaying the real page so the victim sees a genuine flow, including the MFA prompt.

MITRE ATT&CK documents this as technique T1557, Adversary-in-the-Middle, under Credential Access. Attackers abuse common network protocols to force a device to communicate through an attacker-controlled system, then collect credentials, access tokens, and session cookies.

The victim types real credentials into a real-looking flow and completes MFA. The proxy relays the live session and captures the authentication cookie issued after MFA succeeds. The attacker imports that cookie into their own browser and walks straight into the account, with no password and no second factor needed.

That is why MFA can work exactly as designed and still be bypassed. The attacker does not defeat the MFA factor; they exploit the trusted session created after it succeeds. The fix is to bind the session to the device or to re-check access continuously, not just at login.

How do you detect a hijacked session?

Detect session hijacking by watching how a session behaves, not just how it started. A token used from a new IP, network, or device with no matching new sign-in is the clearest signal.

  • New location or device. A session appears in a country the user has never visited, or on a device they do not own.
  • Impossible travel. The same account signs in from two distant places within minutes.
  • Changes you did not make. A new email, password, MFA device, or mail-forwarding rule appears.
  • Session survives sign-out. The account stays active after the user signed out everywhere.
  • Unusual actions. Bulk downloads, new payees, or admin changes at odd hours.

For security teams, the key log to watch is session use without a matching authentication event. If a token is used from a new network and there is no sign-in record for that use, treat it as a hijack until proven otherwise.

Users should also check the active sessions page in important accounts, such as email, banking, and cloud services. If a session lists a device or location you do not recognize, revoke it immediately and change the password from a clean device.

What should you do if a session was hijacked?

Act in the right order: revoke sessions first, then reset credentials, then check the device. Resetting the password before revoking sessions leaves the stolen token working.

  1. Revoke all active sessions and refresh tokens for the affected account, so the stolen token stops working.
  2. Change the password from a trusted, clean device, and sign out of all sessions again.
  3. Check for changes the attacker made: new MFA devices, forwarding rules, recovery email, and payees.
  4. Check the device for infostealer malware, because a reset will not help if the endpoint keeps leaking new cookies.
  5. Review what the attacker accessed and tell your IT or security team, even if nothing seems missing.
  6. If money moved, call your bank immediately and report the incident to the FBI's IC3 in the US.

Do not reuse the old password anywhere else. If it was used on other sites, change it there too, and test whether it appears in known breaches with the free pwned password checker.

For the wider incident pattern, see our spear phishing guide, since AiTM phishing often starts with a targeted email.

How can users prevent session hijacking?

Users cannot fix a website's session handling, but they can reduce the ways a token can be stolen. The most important habits are avoiding phishing, keeping devices clean, and using trusted networks.

  • Do not click login links in emails. Go to the site from a bookmark instead, so a phishing proxy never sees your login.
  • Keep software and browsers updated, and run endpoint protection that can catch infostealer malware.
  • Avoid public Wi-Fi for sensitive accounts, or use a trusted VPN on untrusted networks.
  • Sign out when you finish on shared or public devices, and do not save logins on them.
  • Check active sessions regularly in email, banking, and cloud accounts, and revoke anything unfamiliar.

Passkeys help against ordinary phishing, but they do not stop a session that is stolen after login. That is why session hygiene matters even for users with the strongest login method available.

A secure session cookieSet-Cookie: __Host-SessionID=value;Secure; HttpOnly; SameSite=Strict; Path=/Secure — only sent over HTTPSHttpOnly — JavaScript cannot read itSameSite=Strict — not sent on cross-site requests__Host- prefix — pinned to the exact host that set it
OWASP's recommended session cookie format. Illustration by Cysoro.

How should developers prevent session hijacking?

Developers should treat session management as a security feature, not as a default framework setting. The OWASP Session Management Cheat Sheet is the reference to follow, and its recommendations are specific and testable.

Use HTTPS for the entire session, not just for login, and enforce it with HSTS. Set the Secure flag so the cookie is only sent over HTTPS, HttpOnly so JavaScript cannot read it, and SameSite=Strict so it is not sent on cross-site requests. OWASP recommends a cookie of the form Set-Cookie: __Host-SessionID=value; Secure; HttpOnly; SameSite=Strict; Path=/.

Generate session IDs with a cryptographically secure random number generator, with at least 64 bits of entropy, and rotate the session ID on login and on privilege changes. Destroy the session fully on logout, and expire idle and absolute sessions after a short time for sensitive apps.

Bind sessions to the device or network where possible, using token binding or token protection where the identity provider supports it, and turn on continuous access evaluation so access is re-checked during a session, not just at sign-in. Log session creation, use, and revocation, and alert on anomalous reuse.

Test your own site with the free security headers checker to confirm HTTPS and HSTS are actually enforced.

Use the free SSL checker to confirm the certificate and TLS setup are correct.

Session hijacking vs other attacks: what is the difference?

Session hijacking is often confused with credential theft, but the difference matters for defense. Credential theft steals the password; session hijacking steals the trusted session that follows a successful login.

AttackWhat is stolenWhen it happensMFA helps?
Session hijackingSession cookie or tokenAfter loginNo, session is already trusted
Credential phishingUsername and passwordAt loginYes, if MFA is enforced
Man-in-the-middleTraffic in transitDuring usePartly, if traffic is encrypted
Cross-site scriptingCookie or actions in browserDuring browsingNo, script runs as the user

That is why a defense that only strengthens login is incomplete. A complete defense also protects the session itself: short lifetimes, rotation, binding, and monitoring for reuse from a new context.

The bottom line

Session hijacking succeeds because a stolen cookie is as good as a login. MFA protects the front door, but the session is the house, and it needs its own locks.

For users, that means avoiding phishing links, keeping devices clean, and checking active sessions. For developers, it means HTTPS everywhere, secure cookie flags, rotation, and short sessions. You can check whether your own site enforces HTTPS and HSTS with the free SSL checker.

Frequently asked questions

What is HTTP session hijacking in simple terms?

It is stealing someone's logged-in session so you can use their account without their password. After you log in, the website gives your browser a session cookie. If an attacker copies that cookie, the website treats them as you.

Can session hijacking bypass MFA?

Yes. MFA checks you at login, but session hijacking happens after login, when the session is already trusted. That is why passkeys and MFA alone do not stop it, and why session controls matter.

What is the difference between session hijacking and session fixation?

In session hijacking, the attacker steals a session that already exists. In session fixation, the attacker sets the victim's session ID to a value the attacker already knows, then waits for the victim to log in with that ID.

How do attackers steal session cookies?

The main ways are infostealer malware that copies cookies from the browser, adversary-in-the-middle phishing pages that relay a real login and capture the token, cross-site scripting flaws that read cookies, and sniffing on unencrypted networks.

How can I tell if my session was hijacked?

Look for logins from a new device, location, or IP address with no matching sign-in, password or email changes you did not make, and sessions that stay active after you signed out. Security teams should watch for a token used from a new network without a new login.

What should I do if my session was hijacked?

Revoke all active sessions and refresh tokens first, then change your password from a clean device, sign out everywhere, and check the device for malware. If money moved, contact your bank and report the incident.

Does HTTPS stop session hijacking?

HTTPS stops attackers from sniffing session cookies on the network, but it does not stop malware, phishing proxies, or cross-site scripting from stealing them. Use HTTPS everywhere, plus Secure and HttpOnly cookies, short sessions, and monitoring.

Sources

  1. OWASP — Session Management Cheat Sheet
  2. Expel — What is session hijacking? Detection and prevention
  3. MITRE ATT&CK — Adversary-in-the-Middle, Technique T1557
  4. Gcore — What is Session Hijacking? Types and Prevention Methods
  5. CodePath — Session Hijacking
Written & fact-checked byCysoro Security Team

The engineers and analysts who build Cysoro's domain scanner, email-authentication checks and free security tools. We test what we write about every day — SPF, DKIM, DMARC, certificates, look-alike domains and phishing — and check each guide against the relevant standards, government guidance and vendor documentation.

  • Email authentication
  • Phishing & BEC
  • Domain & DNS security
  • Small-business security

Checked against the OWASP Session Management Cheat Sheet, MITRE ATT&CK T1557, and current session hijacking guidance.

How we write and fact-check →

See where your domain stands

Free for up to 3 domains. No card, no installs.

Start free