Skip to content
XSS Write-up Beginner

From Alert(1) to Admin: Exploiting Stored XSS for Session Hijacki

A blog application stored user comments without sanitisation, allowing an attacker to inject JavaScript that executed in visitors' browsers. The attacker used this to steal an administrator's session cookie and hijack their session, gaining administrator access.

Iamdawoodayub Follow

Published on medium.com

In this lab, I exploited a Stored Cross-Site Scripting (XSS) vulnerability in a blog application’s comment functionality. The objective was to leverage the XSS vulnerability to obtain an administrator’s session cookie and gain access to the administrator account.

Iamdawoodayub, on 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

User-supplied comment content was rendered without proper sanitisation or output encoding, and the session cookie lacked the HttpOnly flag, making it readable by JavaScript.

Impact

Successful exploitation allowed execution of arbitrary JavaScript in victim browsers, theft of authenticated session cookies, and administrator account compromise.

What the attacker needed

Ability to post comments; administrator views the comment; session cookie lacks HttpOnly

The fix

The application should encode user-controlled data before rendering it in HTML, validate and sanitise all user-supplied content, mark session cookies with HttpOnly, Secure, and SameSite attributes, and implement a strong Content Security Policy.

How it was found

  1. Submit a basic XSS test payload in a comment and confirm it executes when the post is revisited.
  2. Inject JavaScript that waits for the page to load, reads the CSRF token and the session cookie, then posts a new comment containing the cookie value.
  3. Wait for an administrator to view the compromised blog post, causing the payload to execute and post the administrator's cookie as a comment.
  4. Retrieve the administrator's session cookie from the new comment.
  5. Intercept a request to the account page, replace the session cookie with the administrator's cookie, and forward the request to gain administrator access.

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 a website lets users post comments and then shows those comments to other people without cleaning them first, an attacker can include JavaScript code in a comment. That code runs in the browser of anyone who views the comment, including administrators. The attacker used this to read the administrator's session cookie (a small piece of data that proves who you are) and then used that cookie to log in as the administrator.

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 Iamdawoodayub

View all

1 more disclosed report, 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.