Sanitizing SVG
For, perhaps obvious, reasons, I’ve been thinking again about sanitizing SVG. My most recent changes to the HTML5lib Sanitizer was to ensure that in constructions like
<rect width='0' height='0' fill='url(...)'/>
the referenced URL is a same-document reference, rather than one that pulls in an external resource from Lord-Knows-Where.
The white-list of elements and attributes in the HTML5lib Sanitizer is the union of a list for MathML that I came up with, and a list for SVG from Sam Ruby. I didn’t really put much thought into Sam’s list. But, once one starts thinking about things, one does start to wonder.
Is
<image xlink:href='http://bad.com/evil.svg'/>
really safe1?
Update:
Of course it’s not safe, as my little example for Anne (viewable only in Opera 9.5beta, but the same problem exists, mutatis mutandis, for<svg:image>
) demonstrates. I’ve updated Instiki and the HTML5lib Sanitizer, accordingly.SVG is a gargantuan Specification. Even thinking about the security implications of Sam’s limited subset makes my head hurt.
1 On similar grounds, while I consider the standard <img src='http://bad.com/ugly.jpg'/>
element fairly safe, I have to wonder at the wisdom of the decision in Opera 9.5beta to allow SVG in (X)HTML <img>
elements.
SVG in <img>
SVG in <img> has no extra options over PNG or JPEG. Scripting is disabled, for one.