-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Include details of SVG-as-Image and Canvas origin-clean #10641
Comments
This doesn't seem to be true. As I already pointed out in the related chromium issue, Firefox does not taint same-origin SVG images at all. I share the test here too: https://cyclic-concise-litter.glitch.me/ (source)
How can it have not origin-clean images? From the specs that you mentioned after, and on which all UAs agree, in secure static mode no external request can be made from the image. i.e. all its resources (images, filters, fonts, stylesheets, etc.) have to be included in the file itself (be it as
No objection on my side to add more details in the specs, but I wonder why Chrome and WebKit had this restriction to begin with. IIUC the original reason was that this could expose privacy content like
I believe Firefox's behavior is the most sensible and corresponds to the current specs: if the resource is served as same-origin, it's origin-clean. cc @whatwg/canvas |
Mmm. I swear I ran your test case a couple of weeks back and Firefox tainted, but maybe I was testing a different SVG file with different properties or the file was local and hence not same origin.
Yes, there should not be cross origin content in the blob but the Chromium code, which is almost certainly still the same as the Webkit code, checks the images for anything other than data URIs.
I considered adding to the "updating the image data" but given it is very generic as to source I though here in the canvas location was more obvious. Though a note referencing the SVG spec about secure static context would probably be a good idea. I did test Chromium behavior around themes and links etc in foreign object and the only leakage of any privacy concern is OS level color contrast settings and the like, plus OS level scrollbar settings.
You are right about Webkit once tainting even data URI, but that was changed a few years ago to match Chromium. I'll have to check how Chromium tracks the origin of the SVG content itself when used in an image before I have a strong opinion on what security and privacy looks like.
|
It seems like a security bug if Without Now |
The OS theme information that is revealed is largely revealed in other ways already. Note I am not talking about browser theme information. High-contrast color settings or anything else that changes system colors already impacts things like the background color of a canvas, which can be read back. Scrollbar settings impact layout dimensions that can be queried. It's a fingerprinting privacy risk that has already been accepted by the community. You raise an interesting point about cross-origin iframes (etc.) creating and transmitting blob urls. I will look into that, because it would also apply to blob bitmap image sources. |
I don't think we have accepted the risk of reading back arbitrary drawn HTML as a community. Otherwise we'd have had APIs such as |
The added security layer here is that the HTML is "sandboxed" in the SVG document, itself sandboxed in the
You'll know better than me, but in that case wouldn't the |
From that first library you point to:
I'd love to know where other browsers decided that it was a good idea to allow readback of form control pixels, etc. That sounds very broken to me and does not match the security conversations we've had over the years. cc @whatwg/security There might indeed be a same-origin restriction on fetching |
Safari does not taint the canvas when a data URL is given as an image source, regardless of it's contents. So even there a path exists to get forms and scrollbars etc. The change was made several years ago. Firefox has supported the blob URL case "forever" even with blog posts explaining how to use it. Chrome supports the data URL case and I was planning to enable the blob case but that now depends on resolving some issues, plus getting approval to ship. Removing the data URL behavior would break the web at this point. The reports flew in when Chrome accidentally broke it once. |
I don't think |
Sorry for not being clear. When "WouldTaintCanvas" checks look at an There's a WPT for it: html/canvas/element/manual/drawing-images-to-the-canvas/drawimage_svg_image_with_foreign_object_does_not_taint.html |
No I understand all that. But |
The canvas cross-origin tainting behavior of SVG-as-image content varies across browsers, and is not specified in any way. The incompatibility arises from the treatment of SVG foreignObject elements in SVG content used as a source for HTML
or SVG
objects.
blob = await fetch("svg-with-foreign-object.svg").then(img.src = URL.createObjectURL(resp.blob()));
to be not origin-clean if it contains a foreignObject tag or has not origin-clean images. Gecko only checks the images. Chromium has in intent to match the Gecko behavior.The canvas spec currently does not specifically address SVG content as an image source, it just says a HTMLOrSVGImageElement is not origin-clean when the
"image's current request's image data is CORS-cross-origin"
Going over to the images portion of the spec we have the statement about CORS cross-origin being important to canvas, and we also have "The src attribute must be present, and must contain a valid non-empty URL ... referencing a non-interactive, optionally animated, image resource that is neither paged nor scripted." and note that explicitly calls out SVG and restricts HTML.
Finally we have the SVG spec saying
Browser behavior is in conformance with all this spec text thanks to limitations on scripting and external links in SVG foreignObject sub-trees and when SVG is used as an image source.
I would like to put up a PR to explicitly discuss the SVG-as-image case in the canvas image sources section on setting the cross-origin status of image content. Any objections?
Secondly, do we want to specify the origin-clean behavior as implemented by browsers for SVG with foreignObject content? That is, the dependency on how the image src is provided.
Finally, do we want to specify a common behavior for the blob case, or leave that up to browsers?
@domenic
Related issue for VideoSource: #10489
The text was updated successfully, but these errors were encountered: