Session hijacking explained in plain terms means understanding how an attacker can take over your account without ever knowing your password. The central question is how a login can be stolen after it has happened, and the answer is that the website does not check your password on every click; it checks a session token instead, and whoever holds that token is treated as you.
When you log in, the server creates a session, a record that this browser belongs to this user, and gives your browser a session identifier, usually stored in a cookie, to present with each request. That identifier is a temporary key, and while you present it, the website trusts you without asking for your password again.
Session hijacking is the attack in which someone else gets hold of that identifier and uses it to impersonate you. The attacker need not break your password; they simply present your session token as if it were their own, and the website lets them in. This article explains what session hijacking is, how it works, and how it is stopped.
Key takeaways
- Session hijacking is taking over a logged-in session by stealing its identifier.
- The identifier is usually a session cookie sent with every request.
- Attackers steal it through sniffing, cross-site scripting, malware, or guessing.
- HTTPS, HttpOnly and Secure cookie flags, and session rotation all help to prevent it.
- If a session is stolen, logging out and changing the password should end it.
What session hijacking is
A session is the website’s memory of your login. Because the web is stateless, meaning each request arrives on its own with no memory of the one before it, websites give each logged-in visitor a session identifier, a long random string that is hard to guess. Your browser stores it, usually in a cookie, and sends it back with every page you load and every action you take, so the server can recognise you each time.
Session hijacking is the theft or misuse of that identifier. Once an attacker has a valid session identifier for your account, they can paste it into their own browser, and the website will treat their requests as yours. They can read your messages, change your settings, make purchases, or transfer money, depending on what the account allows, all without triggering a password check.
The attack works because the session identifier is, in practice, as good as the password for as long as it lasts. The server cannot tell the real user from an attacker presenting the same token, unless extra checks are in place. Our guide to cookies explains how browsers store and send these small pieces of data, and our guide to CSRF explains a related attack that tricks your browser into making requests you never intended.
How session hijacking works
The simplest method is session sniffing, in which the attacker watches network traffic and reads the session identifier as it passes by. On an unencrypted connection, cookies travel in plain text, so anyone on the same public Wi-Fi network, or anywhere along the route, can capture them. This is a main reason websites now use HTTPS, which encrypts the whole connection and hides the cookie from anyone listening in.
A second method is cross-site scripting, usually shortened to XSS, in which an attacker gets a website to run malicious code in the victim’s browser. If the site allows an attacker to inject a script into a page, that script can read the session cookie and send it to the attacker. The HttpOnly flag defends against exactly this, by telling the browser not to let scripts read the cookie at all, though the browser will still send it with requests.
A third method is session fixation, in which the attacker sets the session identifier before the victim logs in, rather than stealing it afterwards. The attacker creates a session, notes its identifier, and tricks the victim into using that same identifier, perhaps through a crafted link. When the victim logs in, the session the attacker already knows becomes a logged-in session, and the attacker can use it straight away.
A fourth method is guessing, in which the attacker tries many possible session identifiers until one works. This succeeds only when identifiers are short, predictable, or drawn from a weak random source, such as a counter or a timestamp. Modern websites defend against it with long identifiers from a strong random generator, so guessing one is practically impossible, and by limiting how many guesses an attacker can make.
Malware on the victim’s own device is a fifth route. If malicious software is running on a computer or phone, it can read the browser’s stored cookies directly and send the session identifier to the attacker. No website defence can fully protect a session once the device itself is compromised, which is why keeping devices free of malware matters as much as any server setting.

Comparing session hijacking with other web attacks
Session hijacking is one of several attacks aimed at logged-in users, each working in a different way. Cross-site request forgery tricks the browser into acting, cross-site scripting runs code inside the browser, and phishing tricks the user into handing over credentials, but all end with an attacker acting with the victim’s authority.
The table below sets out the main contrasts between the leading attacks.
| Aspect | Session hijacking | CSRF | Phishing |
|---|---|---|---|
| What is stolen | The session identifier | Nothing, the browser is tricked | The password itself |
| Needs the password | No | No | Yes, the user gives it away |
| Needs a flaw in the site | Often, or an open network | Yes, missing token checks | No, targets the person |
| Main defence | HTTPS, secure cookies | Anti-CSRF tokens | Checking the address, wariness |
| Victim notices | Often not, until too late | Often not | May notice the fake page |
The practical result is that session hijacking is the quietest of the three, because the attacker simply reuses a genuine login, while CSRF abuses a genuine browser and phishing depends on deceiving the user into giving up the password.
Where session hijacking is used
Public Wi-Fi is the classic setting. In a cafe, airport, or hotel, many strangers share the same network, and if a website does not use HTTPS, an attacker there can watch the traffic and pick out session cookies as they pass. The attack needs no skill beyond running a packet sniffer, which is why advice stresses avoiding sensitive logins on open networks.
Online banking and shopping accounts are the most valuable targets, because a hijacked session there can move or spend money directly. An attacker in a banking session can change account details, add a payee, or transfer funds, while one in a shopping account can order goods to a new address. That is why banks add extra checks, such as a code from a phone before a payment is confirmed.
Social media and email accounts are attacked for a different reason: access and leverage. A hijacked email account can reset the passwords of other accounts, since reset links are sent by email, and a hijacked social media account can spread scams to contacts who trust messages that appear to come from a friend.
Corporate networks face it too, often through a compromised device or a malicious insider. An attacker who hijacks an employee’s session on an internal system can read company data, approve expenses, or change records, all under the employee’s name, which makes it hard to trace and undo. That is why companies set short session lifetimes and require fresh logins for sensitive actions.
Gaming and streaming accounts are frequent targets too, because they hold payment details and virtual items that can be sold. An attacker who takes over a gaming account can strip it of valuable items, change the linked email address, and lock the real owner out, and the owner may not notice until the damage is done.
Strengths and limits
The strength of session hijacking, from the attacker’s point of view, is that it bypasses the password entirely. Two-factor authentication, strong passwords, and password managers all protect the login step, but none helps once the session is established, because the session token is checked instead of the password. That makes a stolen session a powerful prize, and protecting the token matters as much as protecting the password.
It is also a strength that the attack is silent. A hijacked session looks exactly like a normal session, because it is one, only used from a different browser. Unless the website checks extra signals, such as device or location, both may remain unaware until the attacker does something visible, such as changing the password.
The limits are real, and growing. HTTPS is now standard on almost every website, closing the easiest sniffing route, and HttpOnly and Secure cookie flags, session rotation, and short lifetimes have made the attack much harder than it once was. A token also expires, so a stolen one is useful only for a limited time, and logging out or changing the password should end it at once.
Session hijacking checklist
- Use HTTPS on every page, not only on the login page.
- Mark session cookies HttpOnly so scripts cannot read them.
- Mark session cookies Secure so they are sent only over HTTPS.
- Use the SameSite flag to limit when cookies are sent with other sites’ requests.
- Give every session a new identifier at login.
- Set short lifetimes and expire idle sessions.
- Ask for the password again before sensitive actions, such as payments.
- End all sessions when the user changes password.
- Watch for sessions used from a new device or location.
Frequently asked questions
What is session hijacking in simple terms?
It is taking over someone’s logged-in session by stealing the session identifier, usually a cookie, that proves they are logged in. The attacker uses it to act as the victim, without the password.
How is a session identifier stolen?
Most often by watching unencrypted network traffic, by running malicious code in the victim’s browser through cross-site scripting, by fixing the session identifier before login, by guessing a weak identifier, or by malware reading stored cookies.
Does two-factor authentication stop session hijacking?
Not on its own. Two-factor authentication protects the login step, but once the session is created, the session token is what is checked. If that token is stolen afterwards, the attacker can use it without passing the second factor again, unless the site asks for it for sensitive actions.
What is session fixation?
It is a form of session hijacking in which the attacker sets the session identifier before the victim logs in, often through a crafted link. When the victim logs in with it, the attacker already knows it and can use the logged-in session immediately.
How can I tell if my session has been hijacked?
Look for logins from places you have never been, settings or passwords changed without your knowledge, messages you did not send, or orders you did not place. Many websites show recent login activity, worth checking if something feels wrong.
What should I do if I think my session was stolen?
Log out on all devices, change your password, and turn on two-factor authentication if available. Then check for changes, such as a new email address or payment method, and contact support if anything looks wrong.
The bottom line
Session hijacking explained in one line is this: the login is not the password, it is the session token, and whoever holds it is treated as the account owner until the session ends.
Protecting that token, with encryption, careful cookie settings, fresh identifiers at login, and short lifetimes, keeps a login safe after the password has done its job.
This article is general information about how session hijacking works, not advice about securing a particular website or account.







