W3C home > Mailing lists > Public > whatwg@whatwg.org > March 2006

[whatwg] The problem of duplicate ID as a security issue

From: Mikko Rantalainen <mikko.rantalainen@peda.net>
Date: Fri, 10 Mar 2006 12:33:19 +0200
Message-ID: <441155EF.1060107@peda.net>
Alexey Feldgendler wrote:
> The problem of duplicate ID isn't just another issue where it's nice to  
> have some well-defined error recovery just for uniformity. There are cases  
> when duplicate IDs should be viewed as a security concern.
> 
> [...]
> For example, imagine a script which finds a button by ID and attaches an  
> event listener to it. A possible markup looks like this:
> 
> <div>
>      ...blog entry body...
> </div>
> <button id="addtomemories">Add this entry to memories</button>
> <script>
> document.getElementById('addtomemories').addEventListener('click',  
> doSomeNiceAJAX);
> </script>
> 
> So, a malicious blog author can make the following entry:
> 
> I have found a <a href="#" id="addtomemories">cool website</a>.

I think the real problem is not adding the button though the script, 
too. This is bad for two reasons:

1) modified source may result to incorrect targeted element and
2) there shouldn't be any buttons if scripting isn't enabled.

If the script inserts the button, then it can store reference to it 
for later use so it doesn't need the id attribute in the first 
place. I'm fully aware that it's no always reasonable to expect the 
script author to insert all elements via script that need to be 
accessed but I think at least the actions that have security 
implications should go through this kind of procedure.

Security is hard just because *any little error* in the whole 
process can render every other "security feature" meaningless. 
Allowing random user input with possibility to use user supplied 
scripting is next to impossible to make secure.

-- 
Mikko
Received on Friday, 10 March 2006 02:33:19 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 16:58:45 UTC