Skip to content
XSS Write-up Advanced

Exploiting a “Useless” Cookie-Based XSS and Making it Useful

A cookie-based XSS on a subdomain was initially unexploitable because cookies cannot be set for other users, but the author found a way to inject cookies via a CSRF and use cookie parsing quirks to reflect the victim's HttpOnly session cookie into the page, then steal it with JavaScript.

Daniel Thatcher Follow

Published on blog.long.lat

This is the writeup of the exploitation of a cookie-based XSS I found on a bug bounty program last summer which initially appeared to be:

Daniel Thatcher, on blog.long.lat

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

The web server unsafely reflects the value of the csrf cookie into a JavaScript context without escaping, and it also parses cookies in a non-standard way that allows an attacker to inject a csrf cookie via a CSRF attack and to wrap other cookies inside the csrf value using double quotes.

Impact

An attacker could steal session cookies, including those marked HttpOnly, from the main customer-facing web application, potentially leading to account takeover.

What the attacker needed

Victim visits attacker's page; victim logged into main app; cookies set with domain xss.long.lat

The fix

The text does not state a fix; the issue was resolved by the program removing the website.

How it was found

  1. Inject a csrf cookie with a value containing a single quote and JavaScript via a CSRF request to the language change endpoint, exploiting the server's acceptance of commas as cookie delimiters.
  2. Set a second lang cookie with a value starting with a double quote and a path of /index.php to control cookie ordering.
  3. Set a third lang cookie with a value ending with a double quote to close the quoted string.
  4. Victim visits the vulnerable page, causing the server to parse the Cookie header as a single csrf cookie containing all other cookies, which are then reflected into the page.
  5. The injected JavaScript executes and can access the reflected cookie value, including the HttpOnly session cookie.

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.

This report describes a cross-site scripting (XSS) bug where a value from a cookie is inserted into a web page without proper cleaning. Normally, an attacker cannot set cookies for another user, so this seemed harmless. But the author found a way to make the victim's browser send a crafted cookie that causes the victim's own session cookie to be included in the page, allowing the attacker to steal it.

What is XSS?

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.

More by Daniel Thatcher

View all

5 more disclosed reports, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

Cross-site scripting (XSS)

The lesson behind this report.

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.