Skip to content
XSS Write-up Intermediate

“Day 28: The DOM Clobbering Coup — How I Turned a Simple Comment Box into a CSP Bypass”

A news site's comment section allowed limited HTML tags, and the site's JavaScript trusted a global variable called config without initialising it. By injecting anchor elements with id and name attributes, an attacker could clobber that variable so that the API key became a URL to the attacker's server, potentially sending API traffic to that domain.

Aman Sharma Follow

Published on infosecwriteups.com

Welcome to Day 28! Today’s vulnerability is one of my favorites because it feels like magic.

Aman Sharma, on infosecwriteups.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 checked for the existence of a global config object but did not initialise it, allowing user-injected HTML elements to define window.config and its properties.

Impact

The attacker could hijack the application's API traffic, potentially sending the real API key to their own server, though the text does not confirm actual data theft.

What the attacker needed

Comment section allows limited HTML; site uses global config variable; attacker can post a comment

The fix

The code should avoid global variables by using block-scoped declarations and should initialise variables locally rather than trusting window properties, and HTML sanitizers should strip id and name attributes from user content.

How it was found

  1. Find that the comment section allows limited HTML tags such as anchor, image, and div.
  2. Read the site's main JavaScript file and locate code that reads window.config without initialising it.
  3. Submit a comment containing anchor elements with id and name attributes to clobber window.config.
  4. Observe that the browser creates an HTMLCollection for window.config and properties for each name attribute.
  5. The application uses the clobbered values, causing the API key to become the attacker's URL and API calls to be sent to the attacker's domain.

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.

Web pages often store settings in global variables that any script can read. If a site lets users post HTML, an attacker can add elements with special id or name attributes that the browser automatically exposes as global variables, overwriting the real ones. Here, the site's code then used the attacker's fake value as an API key, which was actually a web address, so requests could go to the attacker.

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 Aman Sharma

View all

34 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.