Skip to content
XSS Write-up Intermediate

Cookie Shadowing and CSP bypass to read httpOnly cookie— Way to

The application had a CSP that allowed scripts from data: URLs, enabling XSS. An attacker could use XSS to set a shadow session cookie with a longer path, causing the server to disclose the real httpOnly session cookie in an error message.

kalawy Follow

Published on kalawy.medium.com

Welcome back, this time with my CONCTF finals challenge, created with zeyad zonkorany.

Kalawy, on kalawy.medium.com

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 CSP allowed data: URLs for scripts, and the authentication middleware disclosed all cookies in an error message when the session cookie was empty.

Impact

An attacker could steal the httpOnly session cookie, which in the CTF was the flag and in real-world scenarios would be the admin or user session.

What the attacker needed

Victim visits a page with the XSS payload; the application uses httpOnly session cookies; the server discloses cookies in an error message

The fix

The CSP should not allow data: URLs for scripts, and the authentication middleware should not disclose all cookies in error messages.

How it was found

  1. Set a new session cookie with an empty value and a path longer than the real one.
  2. Visit the path of the set cookie to ensure it is sent along with the real one.
  3. Trigger the error to disclose the session.
  4. Fetch the error page and forward the result to a webhook.

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.

A website had a security rule (CSP) that was meant to stop injected scripts, but it allowed scripts from a special kind of link (data: URL), so an attacker could run their own code. The attacker used that code to create a fake cookie with the same name as the real login cookie but a longer path, so the browser sent both cookies to the server. The server then showed an error that included all cookies, revealing the real login cookie that was supposed to be hidden from scripts.

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 kalawy

View all

2 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.