Hijacking A Web Application Cookie Session
A stored cross-site scripting flaw in a guestbook let injected JavaScript read the session cookie because the HttpOnly flag was not set. An attacker could capture a victim's session identifier and reuse it to log in as that user without a password.
Published on systemweakness.com
Cookie session hijacking, also known as session hijacking or session side jacking, is an attack where unauthorized individual intercepts and steals a user’s session identifier or session cookie. This allows the attacker to impersonate the victim and gain unauthorized access to their account or session on a website or…
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the session cookie lacked the HttpOnly flag and the guestbook stored unsanitised input, so injected script could read and exfiltrate the session identifier.
Impact
An attacker could impersonate the victim's running session and act as that user without credentials, though this relied on the cookie being readable by script and on the victim loading the injected comment.
What the attacker needed
A guestbook that stores unsanitised input; session cookie without HttpOnly flag; victim loads the injected comment; attacker can receive outbound traffic
The fix
Session cookies should be set with the HttpOnly and Secure flags, and stored input such as guestbook comments should be sanitised or encoded to prevent script injection.
How it was found
- Confirm the session cookie is readable from JavaScript in the browser console.
- Start a listener on the attacker machine to receive the cookie.
- Submit a guestbook comment containing a script that sends the cookie to the listener.
- Raise the message field length limit in the inspector so the payload fits.
- Read the captured session identifier from the listener.
- Open a private window, replace the session cookie value, and reload to be logged in as the victim.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
When you log in, the site gives your browser a small token called a session cookie so it remembers who you are. If a page lets an attacker run their own JavaScript, that script can read the token and send it elsewhere. The attacker then puts the stolen token in their own browser and is treated as the logged-in user.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.