Skip to main content
All Terms Glossary

Session Hijacking

Definition

Session hijacking occurs when an attacker steals or impersonates a user's valid session identifier to gain unauthorized access to web applications. This can happen through various means including XSS, network sniffing, or predictable session tokens. Prevention involves secure session management, using HTTPS, and implementing proper session timeout policies.

What session hijacking is

After a user logs in, the server issues a session identifier, usually stored in a cookie or token, that stands in for the login on every subsequent request. Session hijacking is any technique that lets an attacker obtain or reproduce that identifier and use it to act as the user, without ever learning the password. Theft can happen several ways: cross-site scripting or a malicious third-party script reading the cookie, network sniffing of unencrypted traffic, malware on the device, or guessing weak, predictable tokens. Once the attacker replays a valid session ID, the application treats their requests as the genuine user's until the session expires or is revoked.

Why session hijacking is serious

A stolen session grants immediate authenticated access, so it sidesteps the login entirely, including multi-factor authentication that was only checked at sign-in. This is the essence of a pass-the-cookie attack: with a valid session cookie, the attacker often needs no password and no second factor. Depending on the account, they can read private data, make purchases, move funds, or change settings to lock the real user out. Because the requests carry a legitimate session, they look normal to the server, so detection often depends on subtler signals like a sudden change in device or location rather than an obvious failure.

Defending against session hijacking

Send session cookies only over HTTPS, mark them HttpOnly so client-side JavaScript cannot read them, and set the SameSite attribute to limit cross-site sending. Use long, random tokens, rotate them on privilege changes, and enforce sensible timeouts and server-side revocation. Because a common theft route is a malicious or compromised third-party script reading cookies or tokens in the browser, controlling client-side code matters: cside routes third-party scripts through a Script method, analyses the payload, and can block in real time a script that tries to exfiltrate session data, keeping a forensic record. Detecting a device mismatch on a reused session can also flag a hijacked token.

Definition

What is a pass-the-cookie attack?

It is session hijacking that uses a stolen session cookie. Because the cookie already represents an authenticated session, an attacker who obtains it can import it into their own browser and gain access without the password or a second factor. It is a favored way to bypass multi-factor authentication after the fact.

Definition

Do HttpOnly cookies fully prevent session hijacking?

No. HttpOnly stops client-side JavaScript, including XSS payloads, from reading a cookie, which closes one major theft route. But sessions can still be hijacked through network sniffing, device malware, or predictable tokens. It is an important layer, best combined with HTTPS, SameSite, strong token generation, and timeouts.

Got more questions

Talk to a security expert

We answer client-side security questions every day. Bring yours.

Book a demo

Want to walk through this with an engineer?

Thirty minutes, on your own site. Not a slide deck.

We'll show you:

Which third-party scripts are running on your site right now
Where you stand on PCI DSS 6.4.3 and 11.6.1
How much of your traffic is bots and AI agents

Rather just send a question?

Finding open slots…

Real humans only. We'd know.

Having trouble booking? Open scheduler in a new tab

What are you trying to solve?

Tell us in a line and we'll come back with something useful, not a generic pitch.

We usually help with:

Seeing which third-party scripts run on your site
PCI DSS 6.4.3 and 11.6.1 evidence
Bots, AI agents and account takeover

Prefer to just book a time? Pick a slot instead