“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.
Published on infosecwriteups.com
Welcome to Day 28! Today’s vulnerability is one of my favorites because it feels like magic.
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
- Find that the comment section allows limited HTML tags such as anchor, image, and div.
- Read the site's main JavaScript file and locate code that reads window.config without initialising it.
- Submit a comment containing anchor elements with id and name attributes to clobber window.config.
- Observe that the browser creates an HTMLCollection for window.config and properties for each name attribute.
- 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.