Course contentsShow
← Security
Lesson 654 of 3,05214. Web Security - XSS and Content InjectionFree lesson

DOM Clobbering and Prototype Manipulation

Exploiting DOM properties and JavaScript prototype pollution to bypass client-side filters and security controls.

DOM Clobbering and Prototype Manipulation

You'll learn how attackers exploit the structure of JavaScript and the DOM to pollute global variables and bypass security filters.


What Is DOM Clobbering?

DOM clobbering takes advantage of how browsers automatically create global JavaScript variables for certain HTML elements with id or name attributes. If a security filter checks for the existence of a variable before using it, an attacker can "clobber" (overwrite) that variable by injecting HTML elements.

Example: If code checks if (window.config) before loading a legitimate config object, you could inject <div id="config"></div> to make window.config exist as a DOM element instead, potentially bypassing the security check or causing unexpected behavior.

Prototype Manipulation

JavaScript's prototype chain is like a family tree of objects. When you access a property that doesn't exist on an object, JavaScript climbs up the chain to find it. Prototype pollution happens when an attacker modifies Object.prototype or other base prototypes, affecting all objects in the application.

Think of it like poisoning a well that everyone drinks from—every object inherits the contaminated properties.

Attack scenario: If you can inject code that sets Object.prototype.isAdmin = true, suddenly every object in the app might report isAdmin as true, potentially bypassing authorization checks.

Why This Matters for XSS Defense

Security filters might check if certain properties or objects exist before allowing content through. By clobbering DOM references or polluting prototypes, attackers can:

  • Make security checks pass when they shouldn't
  • Override sanitization logic
  • Inject malicious values that propagate throughout the application

Key Takeaway: DOM clobbering and prototype pollution exploit the fundamental mechanics of JavaScript and browser behavior to contaminate the global namespace and object inheritance, turning client-side security controls against themselves.