DOM Clobbering

Medium

DOM Clobbering

Definition

DOM Clobbering is a web attack technique where the attacker injects HTML elements that overwrite global properties of the JavaScript DOM. Using attributes such as id or name on HTML elements, global references are created that can replace variables, objects or functions the JavaScript code expects, altering its behavior.

Impact

Cross-Site Scripting (XSS) in contexts where HTML injection is allowed but scripts are notBypassing HTML sanitizers such as DOMPurifyAltering the JavaScript execution flowRedirection to malicious URLs

Examples

DOM Clobbering to overwrite a global variable

HTML elements with an id attribute create global properties on window. If the app's JavaScript uses a global variable that matches the injected id, the HTML element overwrites it, letting the attacker control its value.

<!-- The application's JavaScript code -->
<script>
  // The app expects 'config' to be an object defined in another script
  if (typeof config !== 'undefined') {
    fetch(config.apiUrl + '/data');
  }
</script>

<!-- The attacker injects (in a field that allows HTML but not <script>) -->
<a id="config" href="https://evil.com/"></a>

<!-- Now config.toString() returns "https://evil.com/"
     and the app fetches https://evil.com//data -->

External references

Practice DOM Clobbering with real labs

Apply what you've learned in safe environments based on real bug bounty reports.

See practice labs
2,482

hunters training

62

labs from real hacks

1,630

completions

$14,790

paid out for these bugs

11 flags captured this week·Real hacks from HackerOne · YesWeHack · Bugcrowd·No commitment·Free Academy
Free · no account

The checklist I run on every new target

47 checks ordered by cost: first what can get you in trouble, then the cheap stuff, and finally the expensive stuff — which is where the big bounties are. I'll send it to your inbox right now.

Unsubscribe in one click, from any email.

BBLabs · bug bounty training

Stop reading about bugs and start hunting them

Create your free account and practice on labs based on real hacks that paid out thousands of euros. The Academy is free forever.

No card · free Academy · cancel anytime