What's in a tag name? JavaScript, apparently
The browser allows unusual characters in HTML tag names and exposes the lowercased tag name via the localName property. An attacker can craft a tag whose name is JavaScript and use event handlers to execute it, bypassing WAFs and blocklists.
portswigger.net
Published on portswigger.net
I was on my laptop, as I often am when there's rubbish on telly, and found myself wondering what characters are allowed in a tag. I knew they had to begin with "a-zA-Z", but what about after that?
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the browser's lenient parsing of tag names combined with the localName property exposing the tag name as a string that can be executed via event handlers.
Impact
An attacker could execute arbitrary JavaScript in a victim's browser, potentially bypassing WAFs and blocklists.
What the attacker needed
Victim visits a crafted page; browser allows unusual tag names
How it was found
- Create an HTML element with a tag name that contains JavaScript code.
- Add an onfocus event handler that reads the localName property and executes it.
- Make the element focusable using tabindex or contenteditable and autofocus.
- Load the page so the element receives focus and the handler runs.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
HTML tags normally have simple names like 'div' or 'img', but browsers actually accept many more characters. The browser also stores a lowercase version of the tag name in a property called localName. By putting JavaScript code inside the tag name and using an event like onfocus to read localName and run it, an attacker can execute code in the victim's browser.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.