DOM Clobbering
DOM Clobbering is a technique where global variables can be overwritten or "clobbered" by naming HTML elements with certain IDs or names. This can cause unexpected behavior in scripts and potentially lead to security vulnerabilities.
Summary
Methodology
Exploitation requires any kind of HTML injection
in the page.
-
Clobbering
x.y.value
-
Clobbering
x.y
using ID and name attributes together to form a DOM collection -
Clobbering
x.y.z
- 3 levels deep -
Clobbering
a.b.c.d
- more than 3 levels -
Clobbering
forEach
(Chrome only) -
Clobbering
document.getElementById()
using<html>
or<body>
tag with the sameid
attribute -
Clobbering
x.username
-
Clobbering (Firefox only)
-
Clobbering (Chrome only)
Tricks
- DomPurify allows the protocol
cid:
, which doesn't encode double quote ("
):<a id=defaultAvatar><a id=defaultAvatar name=avatar href="cid:"onerror=alert(1)//">
Lab
- PortSwigger - Exploiting DOM clobbering to enable XSS
- PortSwigger - Clobbering DOM attributes to bypass HTML filters
- PortSwigger - DOM clobbering test case protected by CSP
References
- Bypassing CSP via DOM clobbering - Gareth Heyes - 05 June 2023
- DOM Clobbering - HackTricks - January 27, 2023
- DOM Clobbering - PortSwigger - September 25, 2020
- DOM Clobbering strikes back - Gareth Heyes - 06 February 2020
- Hijacking service workers via DOM Clobbering - Gareth Heyes - 29 November 2022