DOM Clobbering
Definition
DOM Clobbering is a vulnerability that originates from a naming collision between JavaScript variables and named HTML markups, where browsers replace pre-existing content of an undefined variable with an HTML element when the variable name and the element’s name
(or id
) attribute match.
Attributes
Attribute id
Example with a random tag with a id
attribute:
Attribute name
Example with a form
tag with a name
attribute:
List of tags which supports the name attribute:
embed
,form
,iframe
,image
,img
,object
Caution
document.fm (name=fm) is defined but NOT document.hd (id=hd).
Element name fuzzing - Proof of Concept
Other attributes
Unfortunately, you can only use id
or name
.
Fuzzing other attributes - Proof of Concept
Values
One level deep
Use an anchor with the href
attribute:
You can retrieve some attributes like href
and lang
but not class
. You can list all the attributes you can retrieve on a specific element by doing fuzzing.
Attribute enumeration - Proof of Concept
Two levels deep
You can clobber two depths variable using HTMLCollection
:
Caution
HTMLCollection only works on Chromium based browser (not Firefox).
You can also create an array of values:
Three levels deep
Infinite levels deep
Caution
iframe allows you to clobber as many levels as you want. However, iframes are often blocked by HTML filters.
This simple example does not work because the iframe takes some time to render:
To make things works, you can add some delay by adding a CSS import:
References
- PortSwigger - DOM clobbering
- JavaScript for hackers - Gareth Heyes (book)
- OWASP CS - DOM Clobbering
- DOM Clobbering - Frederik Braun
- WHATWG - Named access on the Window object
- It’s (DOM) Clobbering Time: Attack Techniques, Prevalence, and Defenses