Security operations

Session Hijacking Example: How Attackers Steal Your Login Session

Session hijacking lets an attacker use your logged-in session without your password or MFA code. These examples show how it happens — and how to stop it.

Cysoro Security TeamPublished · 9 min read
Session stolen cookie: abc123… hijacked SECURITY OPERATIONS Sessionhijacking One stolen cookie. Full access.
Quick answer

Session hijacking is an attack where a criminal steals or forges a valid session token, usually a cookie, and uses it to impersonate a logged-in user without needing their password or MFA code. Common examples include stealing cookies over public Wi-Fi, cross-site scripting that reads document.cookie, session fixation with a planted session ID, and adversary-in-the-middle phishing proxies such as Evilginx that relay the login and MFA code in real time.

Key takeaways

  • A stolen session cookie is as powerful as a password, because the server treats whoever holds it as the logged-in user.
  • Session hijacking bypasses MFA entirely, since the session is created after authentication has already happened.
  • HTTPS everywhere, Secure and HttpOnly cookies, short session timeouts and re-authentication for sensitive actions stop most attacks.

You log in to your bank, and the site gives your browser a small token that says "this person is authenticated". From then on, the site trusts the token, not your password. Session hijacking is the attack that steals that token — and with it, your entire logged-in session, no password or MFA code required.

What is session hijacking?

Session hijacking, sometimes called cookie hijacking or cookie side-jacking, occurs when an attacker takes over your internet session. The attacker fools the website into thinking they are you, and can then do anything you could do on the site: move money, read email, change settings or steal data.

It works because HTTP is stateless. Each request is independent, so web applications create a session after you log in and give your browser a session ID, usually stored in a temporary cookie. That ID is sent with every request, and the server uses it to know who you are.

OWASP puts it bluntly: once an authenticated session is established, the session ID is temporarily equivalent to the strongest authentication method used by the application — your password, one-time code, certificate or biometric. Whoever holds the token holds the account, as the OWASP Session Management Cheat Sheet explains.

How does session hijacking work?

Almost every session hijacking attack follows the same three steps. First, you log in normally and the site installs a session cookie in your browser. Second, the attacker obtains your valid session ID. Third, the attacker replays that ID from their own browser and the server lets them in.

The theft can happen in several ways: intercepting unencrypted traffic on shared Wi-Fi, injecting JavaScript that reads the cookie, malware that copies cookies from browser storage, or tricking you into logging in through a proxy that captures the session. If the token is generated with too little randomness, the attacker can even guess or predict it.

The payoff is immediate. The attacker can drain a bank account, buy goods with a saved card, read private messages, or set up mail-forwarding rules so they keep receiving your email even after you change your password. That last trick is why a hijacked email account is so dangerous.

Session hijacking in three steps1You log insite sets a sessioncookie in your browser2Attacker steals itWi-Fi sniffing, XSS,malware or a proxy3Attacker logs in as youserver sees a validtoken — no password neededThe token is the key. Protect it like a password.
The three steps of a session hijacking attack. Illustration by Cysoro.

Example 1: Wi-Fi session sniffing at a coffee shop

The classic example is also the simplest. A user sits in a coffee shop, logs in to a website over an unencrypted connection, and an attacker on the same network captures the session cookie as it travels through the air. The attacker pastes the cookie into their own browser and is suddenly logged in as the victim.

This is exactly what Firesheep demonstrated in 2010. Security researcher Eric Butler released a Firefox extension that automatically intercepted unencrypted session cookies on shared Wi-Fi networks, showing how trivially sessions could be hijacked at coffee shops, airports and hotels. It was a wake-up call, and it pushed the web toward HTTPS everywhere.

Today, most major sites use HTTPS, which encrypts the cookie in transit and stops this exact attack. But any site still served over plain HTTP, or any network where an attacker can strip the encryption, remains vulnerable. Our guide to securing your Wi-Fi network covers the settings that matter on shared networks.

Example 2: Cross-site scripting steals the cookie

In a cross-site scripting (XSS) attack, the criminal exploits a weakness in a web application to inject malicious JavaScript into a page other users will view. When a victim loads the page, the script runs in their browser, reads document.cookie, and sends the session token to the attacker's server, as described in Kaspersky's session hijacking guide.

A well-known case happened in 2013, when a cross-site scripting vulnerability in GitHub's Markdown rendering allowed attackers to inject JavaScript that could steal session cookies from developers viewing malicious repository content. The attack needed no password and no phishing email: visiting the wrong page was enough.

The defense on the server side is the HttpOnly cookie flag, which tells the browser not to expose the cookie to JavaScript at all. Combined with the Secure flag, which only sends the cookie over HTTPS, and the SameSite flag, which limits cross-site sending, it closes the easiest XSS path. Developers should also validate and encode all user input so the script never gets injected in the first place.

Example 3: Session fixation — the attacker picks your session ID

Session fixation reverses the usual flow. Instead of stealing your session, the attacker gives you one. They obtain a valid session ID from the server, then trick you into logging in with it — for example, through a crafted link that carries the session ID in the URL, or by setting the cookie through a vulnerability on a subdomain.

Once you authenticate, that session is now tied to your account, and the attacker already knows its ID. They simply open their browser, present the same ID, and walk into your account. The attack is silent: nothing looks wrong to the victim, because their own login worked normally.

The fix is to regenerate the session ID after login. OWASP recommends issuing a new, random session ID when authentication succeeds, and never accepting a session ID submitted through a URL parameter. If your application accepts IDs from URLs, it is vulnerable to fixation by design.

Example 4: Adversary-in-the-middle — the modern MFA bypass

The most dangerous current example is the adversary-in-the-middle attack, automated by tools such as Evilginx and Modlishka. The attacker sets up a transparent proxy and a phishing site that looks identical to a real login page, such as Microsoft 365, then sends the victim a phishing email with a link to the proxy.

When the victim clicks through and logs in, the proxy captures the username and password in real time and forwards them to the real site. The real site asks for an MFA code, the proxy shows that prompt to the victim, and the victim types the code in. The proxy forwards the code too — and keeps the session token the real site returns.

The attacker now holds a fully authenticated session, with MFA already satisfied. The victim sees a normal login and notices nothing. This is why security teams now treat stolen sessions as a bigger risk than stolen passwords: a session token bypasses every login control at once. Phishing-resistant MFA, such as passkeys and FIDO2 security keys, stops this attack because the credential is bound to the real website and cannot be relayed.

What are the main types of session hijacking?

Session hijacking takes several forms, and each needs a different defense. The table below compares the most common ones.

TypeHow it worksWhat it needsMain defense
Session sniffingCaptures cookies from network trafficShared Wi-Fi or unencrypted HTTPHTTPS everywhere, HSTS
Cross-site scriptingInjected script reads the cookieXSS flaw in the siteHttpOnly cookies, input validation
Session fixationAttacker plants a known session IDApp accepts IDs from URLsRegenerate ID after login
Session predictionGuesses a valid session IDWeak randomness, short IDs128+ bits of entropy, CSPRNG
Man-in-the-browserMalware copies cookies from storageMalware on the deviceAntivirus, device hygiene
Adversary-in-the-middleProxy relays login and MFA in real timePhishing link clickedPasskeys, FIDO2 security keys

Two technical details matter for anyone building or auditing a web application. OWASP requires session IDs to have at least 64 bits of entropy, generated with a cryptographically secure random number generator, and recommends 128 bits or more for the secret verifier. Short or predictable tokens can be brute-forced: OWASP estimates that a 64-bit token would take about 585 years to guess at 10,000 guesses per second against 100,000 active sessions.

How do you know if your session was hijacked?

Hijacking is designed to be silent, but it leaves traces. Check the signs below if anything feels off about an account.

  • You are logged out unexpectedly. Some attackers log you out after stealing the session, or the site invalidates the token when it is used from two places.
  • New devices or locations appear in your account's security or sessions page, especially in countries you have never visited.
  • Settings changed without you: a new recovery email, a new phone number, changed passwords or new mail-forwarding rules.
  • Activity you do not recognize: sent emails, purchases, messages or logins at times you were asleep.
  • Friends report strange messages from your account, or password-reset emails arrive that you did not request.

If you see any of these, act immediately: change the password from a trusted device, sign out of all sessions, and check for forwarding rules and unknown devices. The steps in our spear phishing guide also apply here, since the phishing email that delivers an adversary-in-the-middle attack looks like any other targeted scam.

How do users prevent session hijacking?

Most of the defenses are on the server side, but users can cut the risk sharply with a few habits. Never log in to important accounts on public Wi-Fi without a VPN, and never click login links in emails — type the address yourself or use a bookmark.

Log out when you finish, especially on shared or public computers, and do not stay signed in forever on accounts that hold money or email. Short session timeouts are a feature, not an annoyance: they shrink the window in which a stolen token is useful.

Use phishing-resistant MFA wherever it is offered. A passkey or a FIDO2 security key cannot be relayed by an adversary-in-the-middle proxy, because the credential is cryptographically bound to the real site. A one-time code from an app or text message can be relayed, so it is better than nothing but not enough against this attack.

Keep your browser and operating system updated, run reputable antivirus, and check whether your passwords have appeared in known breaches with our free pwned password checker. Malware that steals cookies usually arrives through the same channels as any other malware.

Server-side defenses that stop session hijackingHTTPS for the whole sessionNot just at login — every request, enforced with HSTSSecure + HttpOnly + SameSite cookiesHTTPS-only, hidden from JavaScript, limited cross-siteRegenerate the session ID after loginKills session fixation; never accept IDs from URLs128+ bits of entropy, CSPRNGRandom tokens that cannot be predicted or guessedShort timeouts + re-auth for sensitive actionsShrink the window a stolen token stays usefulBind sessions to device signalsFlag a token used from a new IP or deviceBased on the OWASP Session Management Cheat Sheet.
The six server-side controls that matter most against session hijacking. Illustration by Cysoro.

What should you do if your session was hijacked?

Act within minutes. Speed matters more than embarrassment, and attackers count on victims staying quiet while they use the session.

  1. Change the password from a trusted device, not the one you suspect is compromised. Use a strong, unique password.
  2. Sign out of all sessions using the account's security settings, which invalidates every stolen token at once.
  3. Check for mail-forwarding rules, new recovery emails and unknown devices, and remove anything you did not add.
  4. Turn on phishing-resistant MFA — a passkey or security key — and remove weaker methods if the account allows it.
  5. Check your bank and other accounts that share the same password, and change those too.
  6. Scan the device for malware and, if it was a work account, tell your IT or security team immediately.

If money moved, call your bank's fraud line at once and file a report at the FBI's Internet Crime Complaint Center. You can verify that the sites you use serve HTTPS correctly with our free SSL checker.

The bottom line

Session hijacking works because a session token is, for practical purposes, the same as being logged in. Whoever holds it is you, as far as the server is concerned — no password, no MFA code, no warning.

The examples all point the same way: use HTTPS everywhere, set Secure, HttpOnly and SameSite on every session cookie, regenerate the token after login, keep sessions short, and move to passkeys or security keys so there is nothing for a proxy to relay. Check your important accounts' session lists today, and log out anywhere you do not recognize.

Frequently asked questions

What is session hijacking in simple terms?

Session hijacking is when an attacker takes over your logged-in session on a website. After you log in, the site gives your browser a session token, usually a cookie. If an attacker steals that token, the site thinks the attacker is you.

Can session hijacking bypass MFA?

Yes. MFA protects the login step, but the session token is created after login succeeds. An attacker who steals the token skips the login entirely, so neither the password nor the MFA code is needed.

What is the difference between session hijacking and session fixation?

In hijacking, the attacker steals a session token that already belongs to the victim. In fixation, the attacker gives the victim a session ID first, then waits for the victim to log in with it, so the attacker already knows the valid token.

Is session hijacking illegal?

Yes. Taking over someone else's session to access their accounts is unauthorized access, which is a crime in most countries, including under the US Computer Fraud and Abuse Act and the UK Computer Misuse Act.

How do I know if my session was hijacked?

Warning signs include being logged out unexpectedly, new devices or locations in your account's session list, password or email changes you did not make, and activity you do not recognize. Check the security or sessions page of important accounts regularly.

Does HTTPS prevent session hijacking?

HTTPS prevents attackers on your network from reading session cookies in transit, which stops the classic Wi-Fi attack. It does not stop cross-site scripting, malware or adversary-in-the-middle phishing, so it is necessary but not sufficient on its own.

What should I do if my session was hijacked?

Change your password from a trusted device, sign out of all sessions, revoke unknown devices and app passwords, check for new mail-forwarding rules, and turn on phishing-resistant MFA such as a passkey or security key.

Sources

  1. OWASP — Session Management Cheat Sheet
  2. Kaspersky — Session Hijacking and Session Hijacking Attacks
  3. Norton — Session hijacking: What is it and how does it work?
  4. Huntress — What Is 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, Kaspersky and Norton session hijacking guides and Huntress session hijacking research.

How we write and fact-check →

See where your domain stands

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

Start free