Session Hijacking
Session hijacking allows attackers to impersonate users by stealing or forging session identifiers. If attackers can hijack sessions, they can access user accounts without knowing passwords.
Once a user logs in, a website recognizes them by the session ID in their cookie (see sessions). Whoever presents that ID is, as far as the website is concerned, that user. Attackers get hold of session IDs in several ways:
- Stealing them with JavaScript. A cross-site scripting flaw lets an attacker run code in the victim's browser that reads the cookie and sends it to the attacker.
- Sniffing them from the network. In 2010, a Firefox extension called Firesheep let anyone on café Wi-Fi hijack other people's Facebook and Twitter sessions with one click, because those sites sent session cookies over unencrypted HTTP.
- Guessing them. If session IDs are sequential or predictable, an attacker can simply calculate valid ones.
- Fixing them in advance. In session fixation, the attacker plants a session ID on the victim before they log in, then uses the same ID afterwards.
To protect your users, serve your whole site over HTTPS, and mark session cookies
Secure and HttpOnly. Generate long, random session IDs, issue a new one whenever a user logs in,
and expire sessions after a period of inactivity.