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
Lab
- Lab: Exploiting DOM clobbering to enable XSS
- Lab: Clobbering DOM attributes to bypass HTML filters
- Lab: DOM clobbering test case protected by CSP
Exploit
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)//">
References
- Dom Clobbering - PortSwigger
- Dom Clobbering - HackTricks
- DOM Clobbering strikes back - @garethheyes - 06 February 2020
- Hijacking service workers via DOM Clobbering - @garethheyes - 29 November 2022
- Bypassing CSP via DOM clobbering - @garethheyes - 05 June 2023
Last update:
June 10, 2023