*Clobbering DOM Attributes to Bypass HTML Filters and Trigger DOM-Based XSS*
The application's client-side HTML sanitizer relied on the DOM 'attributes' property to filter dangerous attributes, but an attacker could clobber that property by injecting an element with a matching id, disabling the validation. This allowed event handlers to be smuggled in, and a crafted form with an onfocus handler could execute arbitrary JavaScript when focused via a URL fragment.
Published on meetcyber.net
This lab demonstrates a subtle but powerful form of DOM-based XSS that arises from unsafe assumptions about DOM properties rather than from classic script injection. The application allows users to post comments containing a restricted subset of “safe” HTML.
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 sanitizer trusted the DOM 'attributes' property to enumerate attributes, but DOM clobbering allowed an attacker to override that property with a named element, bypassing the check.
Impact
An attacker could execute arbitrary JavaScript in the context of other users' sessions, potentially affecting any application that relies on DOM properties without guarding against name collisions.
What the attacker needed
Victim visits a malicious page; victim uses Chrome
The fix
The sanitizer should be fixed to avoid relying on mutable DOM properties like 'attributes' for validation, or to guard against name collisions.
How it was found
- Open the lab and select any article to access the comment form.
- Submit a payload that uses DOM clobbering with id, tabindex, and onfocus attributes to trigger print().
- Use the exploit server to embed the vulnerable page in an iframe with a script that appends #dom to the URL after a delay.
- Click View exploit to test that print() executes automatically.
- Deliver the exploit to the victim to complete the lab.
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 website tried to clean up user comments by checking which attributes each HTML element had, using a built-in browser property called 'attributes'. But an attacker could add an element with an id that matched that property name, which confused the cleaning code and let dangerous attributes like onfocus slip through. Then, by making the browser focus that element, the malicious code ran.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.