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.
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.
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
- Open a blog post and scroll to the comment form.
- Fill in the form and post a comment containing a throwaway pair of angle brackets followed by an image tag with an onerror handler.
- Submit the comment and return to the blog post.
- 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.