Skip to content
XSS Write-up Beginner

Stored DOM XSS

The blog comment functionality used a JavaScript escape function that replaced only the first occurrence of angle brackets, allowing an attacker to inject an image tag with an event handler that executed script in the victim's browser. An attacker could post a comment containing a crafted payload to trigger the alert() function, demonstrating stored DOM-based cross-site scripting.

marduk.i.am Follow

Published on medium.com

Lab description: This lab demonstrates a stored DOM vulnerability in the blog comment functionality. To solve this lab, exploit this vulnerability to call the ‘alert()’ function.

Marduk I Am, 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 escapeHTML function used String.replace() with a string pattern, which replaces only the first match, instead of replaceAll() or a global regex, so subsequent angle brackets were not escaped.

What the attacker needed

Ability to post a comment on a blog post; victim views the comment

The fix

The escapeHTML function should use replaceAll() or a global regular expression to replace every occurrence of angle brackets.

How it was found

  1. Open a blog post and scroll to the comment form.
  2. Fill in the form and post a comment containing a throwaway pair of angle brackets followed by an image tag with an onerror handler.
  3. Submit the comment and return to the blog post.
  4. Observe the alert pop-up and inspect the comment in the DOM to see the injected tag.

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 is a stored cross-site scripting (XSS) bug. When you post a comment, the website tries to make it safe by replacing the characters < and > with harmless codes, but it only replaces the first one it finds. By adding an extra <> at the start, the attacker can sneak in a real HTML tag that runs JavaScript, so anyone viewing the comment gets a pop-up.

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 marduk.i.am

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.