Skip to content
XSS Write-up Intermediate

DOM Clobbering XSS — vulnbydefault Write-Up

A reflected XSS challenge had a script that wrote query parameter keys and values into the page unsanitised whenever a global variable named CSHCTF25 was truthy. An attacker could inject a DOM element with that id to make the check pass, then inject an image with an error handler to run JavaScript and steal cookies or fetch the flag.

medium.com

Published on medium.com

The JavaScript checks each query parameter in the URL. If the key matches an element’s id, it sets its innerText.

Bader ALmutairi, 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

Likely the script trusted a global variable that can be created by DOM clobbering, and then wrote unsanitised query parameter data into the page with document.write.

Impact

The injected script could run in the bot's browser and exfiltrate cookies or fetch the flag page.

What the attacker needed

Victim (bot) visits crafted URL; attacker can submit URL to bot

How it was found

  1. Add a query parameter whose key is an element id that creates the global variable CSHCTF25.
  2. Add another query parameter containing an image tag with an onerror handler.
  3. URL-encode the whole URL so it survives parsing.
  4. Submit the encoded URL to the bot endpoint.

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.

The page took text from the web address and wrote it into the page without cleaning it. Normally a check blocked this, but the check looked for a variable that a browser creates automatically from an element's id. By adding an element with that id, the attacker made the check pass and got their own script to run in the victim's browser.

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.