What's in a tag name? JavaScript, apparently

10 points by freddyb


Gaelan

I feel like I need a bit more context for why any of this is useful. Is the idea that you could get XSS from a site that creates an element with untrusted input as the tag name?

cceckman

No mention of what browser(s) this applies to?

chrismorgan

I was genuinely disappointed to see “wondering what characters are allowed in a tag” followed by experimentation and even fuzzing rather than reference to the spec—I would have expected anyone from PortSwigger to know that HTML has a dependable spec, and that especially around parsing, all implementations match it exactly (barring new features, like how they just resurrected processing instructions). I know I reach to the HTML Standard quite frequently over subtle details; it’s typically faster and more reliable than experimenting.

The tag open state shows that the tag name has to start with ASCII alpha, and then the tag name state shows that anything goes other than ␉, ␊, ␌, ␠, /, > and ␀, with ASCII uppercase immediately lowercased. So <alert(1)> is considered legal syntax, no parse error or such (though a validator will probably still complain that there’s no such element).

Related fun stuff: at unspecified times and browsers in history (but long ago, and not consistent across browsers), <br/> would create an element with local name br/ (which was why <br /> became the XHTML/HTML-polyglot way of writing a line break, found in many CMSes; whereas XML would customarily skip the space), and <br /> would create an element with local name br and one attribute named / with value empty string (and I honestly think they should have left it that way rather than ignoring a trailing slash—now we’ve somehow ended up with a whole lot of developers that think the / does something or is in any way worthwhile).

freddyb

Fascinating how the end result looks so simple and clearly minimal. I like how Gareth describes how he started, which avenues he explored and how he arrived at this contrived but tiny XSS vector. Just neat.