Cookie Theft and Session Hijacking
You'll learn how attackers steal session cookies through multiple attack vectors and what defenses protect against them.
Session cookies are like VIP backstage passes to your web application. If an attacker steals someone's session cookie, they can impersonate that user completely—no password needed. Understanding how these theft attacks work is essential for defending against them.
How Cookies Get Stolen
XSS (Cross-Site Scripting)
When attackers inject malicious JavaScript into a vulnerable page, they can read document.cookie and send it to their server. This is why the HttpOnly flag exists—it prevents JavaScript from accessing cookies, blocking this attack vector entirely.
Network Sniffing
On unencrypted HTTP connections or compromised networks (like public WiFi), attackers can intercept cookies traveling between browser and server. It's like someone reading postcards in transit. The Secure flag ensures cookies only travel over HTTPS, encrypting them in transit.
Malware and Browser Exploits
Malicious software on a user's device can directly access browser cookie storage. Unlike network-based attacks, this happens locally on the victim's machine—no interception needed.
Physical Access
An unlocked computer gives attackers direct access to browser developer tools and cookie storage. This is why session timeout matters.
Defense: Device Fingerprinting
Device fingerprinting tracks characteristics like browser version, screen resolution, operating system, and installed fonts. When a session cookie suddenly appears from a completely different device or location, the application can challenge or reject it. Think of it as noticing that your "backstage pass" is being used in Tokyo while you're in New York.
Key Takeaway: Cookie theft enables complete session hijacking; defend with HttpOnly (blocks XSS), Secure (blocks network sniffing), and device fingerprinting (detects suspicious session reuse).