--- url: "https://portswigger.net/web-security/dom-based/dom-clobbering" titulek: "DOM clobbering | Web Security Academy" h1: "DOM clobbering" popis: "In this section, we will describe what DOM clobbering is, demonstrate how you can exploit DOM vulnerabilities using clobbering techniques, and suggest ways ..." jazyk: "" kanonicka: "https://portswigger.net/web-security/dom-based/dom-clobbering" drobecky: ["Web Security Academy", "DOM-based", "DOM clobbering"] zdroj: "live" wayback_snapshot: "" stazeno: "2026-09-13 21:26:13" znaku: 4404 slov: 703 kodovani: "utf-8" sha256: "2ce18c67edfc1caeb488a25dd6c4f1c8f34565f9de4751002dac450c56521ca9" --- # DOM clobbering In this section, we will describe what DOM clobbering is, demonstrate how you can exploit DOM vulnerabilities using clobbering techniques, and suggest ways you can reduce your exposure to DOM clobbering attacks. ## What is DOM clobbering? DOM clobbering is a technique in which you inject HTML into a page to manipulate the DOM and ultimately change the behavior of JavaScript on the page. DOM clobbering is particularly useful in cases where XSS is not possible, but you can control some HTML on a page where the attributes `id` or `name` are whitelisted by the HTML filter. The most common form of DOM clobbering uses an anchor element to overwrite a global variable, which is then used by the application in an unsafe way, such as generating a dynamic script URL. The term clobbering comes from the fact that you are "clobbering" a global variable or property of an object and overwriting it with a DOM node or HTML collection instead. For example, you can use DOM objects to overwrite other JavaScript objects and exploit unsafe names, such as `submit`, to interfere with a form's actual `submit()` function. ## How to exploit DOM-clobbering vulnerabilities A common pattern used by JavaScript developers is: `var someObject = window.someObject || {};` If you can control some of the HTML on the page, you can clobber the `someObject` reference with a DOM node, such as an anchor. Consider the following code: `` To exploit this vulnerable code, you could inject the following HTML to clobber the `someObject` reference with an anchor element: `` As the two anchors use the same ID, the DOM groups them together in a DOM collection. The DOM clobbering vector then overwrites the `someObject` reference with this DOM collection. A `name` attribute is used on the last anchor element in order to clobber the `url` property of the `someObject` object, which points to an external script. Another common technique is to use a `form` element along with an element such as `input` to clobber DOM properties. For example, clobbering the `attributes` property enables you to bypass client-side filters that use it in their logic. Although the filter will enumerate the `attributes` property, it will not actually remove any attributes because the property has been clobbered with a DOM node. As a result, you will be able to inject malicious attributes that would normally be filtered out. For example, consider the following injection: `
Click me` In this case, the client-side filter would traverse the DOM and encounter a whitelisted `form` element. Normally, the filter would loop through the `attributes` property of the `form` element and remove any blacklisted attributes. However, because the `attributes` property has been clobbered with the `input` element, the filter loops through the `input` element instead. As the `input` element has an undefined length, the conditions for the `for` loop of the filter (for example `i