DOM Clobbering Attacks
What you'll learn: How attackers exploit HTML id and name attributes to override JavaScript variables and hijack application logic without injecting script tags.
What is DOM Clobbering?
DOM Clobbering is a sneaky injection technique where attackers insert HTML elements with specially chosen id or name attributes to shadow or replace JavaScript global variables. Unlike traditional XSS that executes scripts, DOM clobbering manipulates the Document Object Model to trick existing JavaScript code into using attacker-controlled HTML elements instead of the expected variables.
Think of it like this: imagine your application has a variable named config that stores important settings. An attacker injects <a id="config" href="https://evil.com"></a> into the page. Now when your JavaScript tries to access window.config, it gets the anchor element instead of the real configuration object!
How It Works
Browsers automatically create global references for elements with id or name attributes. If your code references document.config or just config, and you've injected <input name="config">, the browser returns that HTML element instead.
Common exploitation patterns:
- Overriding object properties:
<form name="userData"><input name="isAdmin"></form>could clobber checks likeif(userData.isAdmin) - Hijacking URL references:
<a id="apiEndpoint" href="//attacker.com/api">redirects API calls - Breaking conditional logic: Clobbered variables may evaluate differently than expected (objects are truthy!)
Why This Bypasses Filters
Many XSS filters only block <script> tags and JavaScript event handlers. Plain HTML elements like <a>, <form>, and <input> often pass through unnoticed, yet can still manipulate DOM-based logic flows.
Key Takeaway: DOM Clobbering exploits how browsers create global references from HTML attributes, allowing attackers to poison JavaScript variables with HTML elements and redirect application logic—all without executing traditional scripts.