Why does this vector :
<svg><script>alert(/1/.source)</script>
works in http://jsfiddle.net/ZgPY4/2/ and this one
<script>alert(/1/.source)</script>
doesn't. How is <svg>
making it work?
Why does this vector :
<svg><script>alert(/1/.source)</script>
works in http://jsfiddle.net/ZgPY4/2/ and this one
<script>alert(/1/.source)</script>
doesn't. How is <svg>
making it work?
HTML <script>
has special powers other elements don't: it is a "CDATA element". That means that any <
or &
characters up to the end of the element are taken as literally meaning those characters. So what is passed to the JS interpreter is:
alert(/1/.source)
which is obviously not valid JS syntax.
The concept of a "CDATA element" comes from the SGML world from which HTML developed. But SVG comes from the XML world where things are simplified and there are no CDATA elements. Consequently the SVG <script>
element has no special powers: inside an SVG script, <
introduces a tag and &
introduces an entity or character reference.
Consequently the (
gets parsed to (
and the resulting string passed to the JS interpreter is:
alert(/1/.source)
In XML terms the <script>
element is in the HTML namespace and the <svg><script>
element is in the SVG namespace, so they are different elements. HTML5 makes this all less clear by hiding the namespace prefixes and applying a non-XML parser to the SVG (which is why (
works despite it being non-well-formed; should be (
).
<script>alert(/1/.source)</script>
. You would only need to consider the SVG workaround if you were dealing with an input filter that blocked use of (
and )
characters. There are many funny little workarounds for particular filters that arbitrarily block certain characters.
The #
(hash,sharp,pound) breaks your Javascript. Inside of an <svg>
tag pair (your closing tag is not provided) the entity number is being translated to it's proper character reference as it's rendered as html, then the engine executes the ECMA script (which it is allowed to do for drawing).
OWASP.org documents this as hex encoding without semicolons.
<svg>
used ASCII encoding is possible otherwise not, anyway here is xss js append payload when following characters are NOT allowed ? = ( ) ; : ----------- might someone find it usefull ;) http://jsfiddle.net/sh00pac/GrnqV/