Session hijacking is an attack in which someone steals or predicts a valid session ID — usually a cookie — and reuses it to impersonate a logged-in user without ever entering a password or passing MFA. It works because the server trusts any request carrying a valid session token. The main defenses are HTTPS everywhere, Secure, HttpOnly and SameSite cookie flags, session ID rotation at login, and short session timeouts.
Key takeaways
- Session hijacking steals the proof of login, not the password, so MFA alone cannot stop it.
- The most common theft routes are cross-site scripting, unencrypted Wi-Fi sniffing, session fixation and infostealer malware.
- Secure, HttpOnly and SameSite cookie flags plus ID rotation at login and short timeouts close most of the gaps.
You log in once, and the website remembers you. That memory is a session token — usually a cookie — and it is valuable. Anyone who copies it can browse, buy and change settings as you, without ever knowing your password.
What is session hijacking?
Session hijacking is an attack in which someone steals or predicts a valid session ID and reuses it to impersonate a user who is already logged in. The attacker never enters a password, so login controls and MFA are bypassed entirely.
HTTP has no memory between requests. After you log in, the server creates a random session ID, stores it next to your account, and sends it to your browser in a cookie. Your browser then sends that cookie with every request, and the server trusts it as proof of who you are.
That trust is the whole attack. The server cannot tell whether the cookie came from your browser or from an attacker's copy of it. Steal the token, and you steal the session. OWASP classifies the underlying problem under identification and authentication failures, and MITRE ATT&CK tracks cookie theft as technique T1539: Steal Web Session Cookie.
It is sometimes called cookie hijacking or cookie side-jacking, because the session cookie is the most common thing stolen. It is related to, but different from, a man-in-the-middle attack: that describes the attacker's network position, while session hijacking describes what they do with it.
How does session hijacking work?
A session hijack has three steps: get a copy of a valid session ID, replay it from the attacker's own browser or tool, and use the session before it expires or is revoked. The hard part is step one; steps two and three are trivial.
The token is most often a cookie, but the same idea applies to bearer tokens in Authorization headers and tokens stored in browser storage. Any credential that proves a session, and that can be copied, can be hijacked.
What are the main types of session hijacking?
Attackers get the token in five main ways. Each one has a different fix, which is why it helps to know them apart.
Cross-site scripting (XSS)
An attacker injects a script into a vulnerable web page. When a victim loads the page, the script runs in their browser and reads document.cookie, then sends the session ID to the attacker. The HttpOnly flag blocks exactly this read, because it tells the browser not to expose the cookie to JavaScript.
Network sniffing and side-jacking
On an unencrypted connection, anyone on the same network can watch traffic and copy session cookies as they pass. This was the classic coffee-shop Wi-Fi attack. HTTPS everywhere removes it, which is why every page — not just the login page — must use TLS.
Session fixation
The attacker plants a session ID they already know in the victim's browser, for example through a crafted link, before the victim logs in. If the site keeps the same ID after login, the attacker's copy is now a logged-in session. Regenerating the ID at login defeats fixation outright.
Infostealer malware
Malware on the victim's device reads the browser's cookie store directly and exfiltrates session cookies, often along with saved passwords. MITRE notes that web session cookies are a common target for credential-access malware. No cookie flag helps here, because the malware runs on the device itself.
Adversary-in-the-middle phishing
A phishing page acts as a proxy: the victim logs in through it, and it relays the credentials and the session cookie to the real site, then keeps a copy of the cookie. Microsoft has tracked such kits being used against more than 10,000 organizations since 2021 specifically to steal session cookies and bypass MFA. This is the technique behind the rise of "MFA bypass" phishing kits such as Evilginx2.
Session hijacking vs phishing vs credential stuffing
These attacks all end with someone else in your account, but they start in different places and need different defenses.
| Attack | What is stolen | Does MFA help? | Main defense |
|---|---|---|---|
| Session hijacking | A live session token | No — the session already passed MFA | Cookie flags, rotation, short timeouts |
| Phishing | Password, sometimes MFA code | Partly — phishing-resistant MFA helps | Passkeys, security keys, training |
| Credential stuffing | Reused passwords from breaches | Yes — MFA blocks the login | Unique passwords, MFA, rate limiting |
| Session fixation | Nothing — the ID is planted | No | Rotate session ID at login |
| Man-in-the-middle | Traffic in transit | Partly | HTTPS, HSTS, certificate pinning |
The key point is in the second column: MFA protects the login, not the session that follows it. Once a token is stolen, the attacker is already past the gate. Our guide to spear phishing covers the social engineering side that often delivers these attacks.
How do you know if your session was hijacked?
Session hijacking is quiet by design — the attacker wants to use your session, not announce themselves. Look for these signs instead.
- Unexpected logouts. You are signed out of a service you were using, or asked to log in again for no reason.
- Logins from unfamiliar places. Your account shows sessions from cities, countries or devices you do not recognize.
- Settings you did not change. A new forwarding rule in your email, a changed recovery address, or a new MFA device.
- Actions you did not take. Sent messages, changed passwords, purchases or permission grants you do not remember.
- Security alerts. Your provider warns about a new sign-in or an unusual session, even though you did not sign in.
Check the active sessions or security activity page in your email, cloud and banking accounts regularly. Most major services show every live session and let you revoke them one by one. If anything looks wrong, revoke all sessions, change the password, and check for new mail rules and unknown devices.
What should you do if your session is hijacked?
Act fast: a stolen session is useful only while it is alive, so your goal is to kill it and cut off the route the attacker used.
- Sign out of all sessions from the account's security settings, on a device you trust. This forces the server to invalidate the stolen token.
- Change the password from a clean device, and check for new mail-forwarding rules, changed recovery email or phone, and unknown MFA devices.
- Revoke app access for third-party apps and tokens you do not recognize, and re-check them a week later.
- Run a malware scan on every device you used, since infostealer malware is a common source of stolen cookies.
- Check your accounts and statements for actions taken during the hijack, and report fraud to the affected service and your bank.
- Turn on phishing-resistant MFA — passkeys or a security key — so the next phishing attempt cannot harvest a usable login.
How can users protect themselves from session hijacking?
Most of the protection is built into the website, but users control the parts attackers exploit most: the network, the device and the click.
- Always use HTTPS. Look for the padlock and never log in on a plain-HTTP page. Our free SSL checker shows whether a site's certificate and TLS setup are sound.
- Avoid public Wi-Fi for sensitive accounts, or use a VPN on it. A VPN encrypts traffic to the VPN server and stops local sniffing.
- Keep your browser and OS updated. Updates patch the flaws that let malware and malicious extensions read your cookie store.
- Do not install browser extensions you do not need. A malicious extension runs with access to your cookies on every site.
- Log out on shared devices, and use the "sign out of all sessions" option after using a public computer.
- Use passkeys where offered. They cannot be phished in the usual way, and they remove the password that AiTM kits harvest alongside the cookie.
On your home network, the same hygiene applies: keep your router firmware updated and your Wi-Fi secured, as our guide to securing your Wi-Fi explains.
How should developers prevent session hijacking?
For website builders, OWASP's Session Management Cheat Sheet is the baseline. These are the controls it treats as mandatory, not optional.
Set the cookie flags
OWASP's example session cookie is Set-Cookie: __Host-SessionID=<value>; Secure; HttpOnly; SameSite=Strict; Path=/. Each attribute closes a different theft route: Secure stops plain-HTTP sniffing, HttpOnly stops JavaScript from reading the cookie, SameSite=Strict keeps it off cross-site requests, and the __Host- prefix pins it to the exact host.
Never store session IDs, tokens or credentials in localStorage or sessionStorage. Any script on the page can read them, so one XSS bug discloses every token. An HttpOnly cookie is the safer place.
Generate and rotate session IDs properly
Session IDs must have at least 64 bits of entropy from a cryptographically secure random number generator, and must be meaningless to observers — no user IDs, timestamps or counters. Regenerate the ID at login and at every privilege change, and run session handling in strict mode so the server only accepts IDs it generated itself.
Set timeouts and invalidate on logout
OWASP suggests idle timeouts of 2 to 5 minutes for high-value applications and 15 to 30 minutes for low-risk ones, plus an absolute timeout so even an active session ends eventually. Invalidate the session on the server at logout — deleting the cookie in the browser is not enough.
Monitor for anomalous sessions
Log session creation and use, and flag sessions that change IP address, device fingerprint or geography mid-session. Token binding and continuous access evaluation, where the identity provider re-checks the session as conditions change, are the enterprise answers to stolen-but-valid tokens.
The bottom line
Session hijacking works because a session token is as good as a login — and unlike a password, it has already passed MFA. The attack is not exotic: it is XSS, sniffing, fixation, malware and phishing proxies, all aimed at the same small string.
For users, the habits are simple: HTTPS only, updated devices, few extensions, and log out everywhere when something feels wrong. For builders, the OWASP checklist is the floor, not the ceiling. Check your own site's headers and TLS with the free security headers checker, and treat every session token as if it were a password — because to an attacker, it is.
Frequently asked questions
What is session hijacking in simple terms?
Session hijacking is when an attacker steals the token that proves you are logged in to a website, usually a session cookie, and uses it to act as you. The website sees a valid session, so the attacker never needs your password or your two-factor code.
What is the difference between session hijacking and phishing?
Phishing tricks you into giving up your password, often on a fake login page. Session hijacking skips the login entirely by stealing a session token that is already authenticated. That is why it can bypass MFA: the attacker replays a session that already passed it.
Can session hijacking happen on HTTPS sites?
Yes, although HTTPS makes the most common route, network sniffing, much harder. Attackers can still steal session cookies through cross-site scripting, infostealer malware on your device, or adversary-in-the-middle phishing pages that relay the cookie in real time.
What is session fixation?
Session fixation is a variant where the attacker plants a session ID they already know in your browser before you log in. If the site keeps the same ID after login, the attacker's copy becomes a logged-in session. Rotating the session ID at login defeats it completely.
How can I tell if my session was hijacked?
Warning signs include being logged out unexpectedly, logins from unfamiliar locations or devices, changed account settings or passwords you did not change, and security alerts about new sessions. Check the active sessions page in your email, banking and cloud accounts and revoke anything unfamiliar.
Does logging out stop session hijacking?
Logging out helps only if the site invalidates the session on the server. If it only deletes the cookie in your browser, a stolen copy can still work. OWASP requires server-side invalidation at logout, which is one reason to sign out of all sessions after a suspected theft.
Do VPNs prevent session hijacking?
A VPN encrypts traffic between you and the VPN server, which stops Wi-Fi sniffing on public networks. It does not stop cross-site scripting, malware on your device, or phishing pages from stealing your session cookie, so it is only one layer of defense.
What should developers do to prevent session hijacking?
Use HTTPS everywhere with HSTS, set session cookies with Secure, HttpOnly and SameSite=Strict, use the __Host- prefix, generate IDs with at least 64 bits of entropy from a secure random generator, rotate the ID at login and privilege changes, and set idle and absolute timeouts.
Sources
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.
Checked against the OWASP Session Management Cheat Sheet, OWASP ASVS cookie requirements, MDN cookie documentation and MITRE ATT&CK T1539.
How we write and fact-check →