Allow SVG image tag with inline data
Currently there is no way to load image data into an SVG element. SVG <amp-img> than <img>.
One path is to allow <image> tags with xlink:href='data:..', which should cover all common use case a limit potential malicious uses
Potential problems
- File size will increase due to embedding of images. Should we limit the size?
- Could be exploited to get around delayed loading of
<amp-img> - Optimization of images of this type in the cache might be limited or more complex
Generally this option makes sense to me since we allow <img> element in SVG already.
/cc @Gregable
Generally this option makes sense to me since we allow
<img>element in SVG already.
Not currently, unless you mean an <img> inside an SVG subresource (ie: <amp-img src="foo.svg"></amp-img> and foo.svg includes an <img> element). The only context in an AMP page where an <img> element is allowed is inside a <noscript> element. We don't allow <image> in any context.
My concern would be the 2nd bullet point, which is that this subverts the AMP runtime's ability to control when an image is loaded. However, we already allow <amp-img> to have data: urls.
It seems like a parallel test would be:
- Should we allow
<img>anywhere in the document as long as thesrcattr is adata:url?
@Gregable No, not the <img> tag in HTML, but SVG's <image> element - https://developer.mozilla.org/en-US/docs/Web/SVG/Element/image
Do we currently allow these?
@dvoytenko , no we do not currently allow <image> tags anywhere.
I believe we should enable SVG <image> tag provided that its xlink:href attribute contains a data URI.
/to @Gregable
sgtm
@powdercloud thought of one more potential issue with this that I wanted to run by you, specifically that I could data encode an .svg image into the <image> URL, for example:
<svg ...>
<image xlink:href="data:image/svg+xml;base64,BLAHBLAH"/>
</svg>
That base64 encoded SVG could in turn have any SVG syntax at all, including something like:
<svg ...>
<image xlink:href="http://example.com/foo.png"/>
</svg>
This would effectively be a workaround to inject a remote image into the document not managed by amp runtime and not rewritten by the amp cache.
A similar thing can be done with <amp-img src="data:image/svg+xml;base64,BLAHBLAH", but that's at least managed by the amp runtime, though not rewritten by the cache.
Do we need to also constrain the file types in data: URLs? There is no mechanism for this currently, but it could be added.
@dvoytenko
Sure, this is very specific to raster images, so let's make sure the image type is NOT svg+xml.
Two follow ups:
Are there other types you know of that we should constrain besides svg+xml?
There are a few other places we allow data: urls. Do you feel we should add this constraint to
<amp-img src=,<amp-anim src=<img src=<video src=<audio src=- Images in the custom CSS block
No. It's enough for us to control the loading on top level for these elements. We only care about SVG since (a) we can control when it renders or not; (b) SVG is more of a composite element.
This is fixed and live everywhere.