# Session Hijacking

> Stealing someone's login so you can act as them. No password is needed.

**Field:** Software Development  
**Category:** Security  
**Also known as:** Session Hijack, Cookie Hijacking, Session Theft

## Think of it like

Think of it like a wristband at a fair. Whoever has it gets in as you.

## Definition

Session hijacking is stealing someone's logged-in session to act as them. After you log in, the site gives your browser a session ID, often in a cookie. Whoever holds that ID looks like you to the site. Attackers steal it through XSS, unsafe Wi-Fi or a leaked link. Safe cookie settings, HTTPS and short sessions make it much harder.

## Example

A script on a forum page reads Lucy's session cookie and sends it away. The attacker pastes it in and is logged in as Lucy.

## Example code

```http
Set-Cookie: session=7f3a9c; HttpOnly; Secure; SameSite=Lax
```

HttpOnly hides the cookie from page scripts, and Secure sends it only over HTTPS.

## Why it matters

A stolen session skips the password and even the second step. The site sees a normal user.

## Common mistake

Leaving the session cookie open to scripts. The HttpOnly flag stops page scripts from reading it.

## Three principles

- **The ID is the key.** Whoever holds it is you.
- **Many ways to steal.** XSS, open Wi-Fi and leaked links.
- **Lock the cookie.** HttpOnly, Secure and short lives.

## Related terms

- [Session (Web)](https://learn.benibix.com/term/development/session)
- [HTTP Cookie](https://learn.benibix.com/term/development/cookie)
- [Cross-Site Scripting (XSS)](https://learn.benibix.com/term/development/cross-site-scripting)
- [HyperText Transfer Protocol Secure (HTTPS)](https://learn.benibix.com/term/infrastructure/https)
- [Authentication](https://learn.benibix.com/term/development/authentication)

![Three panels. Brute force: guesses like 123456, password and qwerty are tried on one account until one works; stop it by limiting tries. Credential stuffing: a pair leaked from a games site, jack@example.com and sunset77, is tried on his shop account and works because he used it twice; stop it with a second factor. Session hijacking: Lucy logs in and gets a session cookie, a script steals it and the site sees Lucy with no password needed; stop it with HttpOnly cookies.](https://learn.benibix.com/diagrams/dev2-login-attacks.svg)

---

Source: https://learn.benibix.com/term/development/session-hijacking
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
