Skip to content
XSS Write-up Beginner

Stored Cross-Site Scripting: HTML Context (Nothing Encoded)

The blog comment feature stored user input without encoding and rendered it directly into HTML, so a script tag in a comment executed for every visitor. An attacker could run arbitrary JavaScript in victims' browsers, potentially stealing cookies or performing actions as them.

medium.com

Published on medium.com

This PortSwigger lab contains a stored XSS vulnerability inside the blog’s comment functionality. Since nothing is encoded or sanitized, any JavaScript inside the comment body gets stored on the server and executed whenever any user views the blog post.

Aditya Bhatt, 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

The application stored user-supplied comment content and output it directly into HTML without any encoding or sanitisation.

Impact

An attacker could execute arbitrary JavaScript in the browser of any user who views the affected page, enabling session hijacking or account takeover.

What the attacker needed

Ability to post a comment; victim views the blog page

The fix

The application should encode output so that characters like < and > are displayed as text rather than interpreted as HTML, and optionally apply input validation and a Content Security Policy.

How it was found

  1. Open the lab and locate the comment form on a blog post.
  2. Enter a script payload in the comment field along with name, email and website, then submit.
  3. Navigate back to the blog page to view the stored comment.
  4. Observe the script executing as an alert when the page loads.

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 type a comment on a website, the site usually saves it and shows it to others. Here, the site saved the comment exactly as typed and put it into the page without turning special characters into harmless text. That meant if someone typed code that looks like a script, the browser would run it as a program for everyone who viewed the page.

What is XSS?

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

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.