-
-
Notifications
You must be signed in to change notification settings - Fork 59
Allow data URIs as image sources #164
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
Conversation
a) the only sources here are about svg, not about other |
Hello! SVG is indeed the only image format supported in img tags that supports scripting, so I thought it was important to clarify that svg scripts are not executed. Non-image formats are just ignored, and other supported image formats cannot include scripts. About allowing all protocols on images: I don't see any legitimate use case for javascript: or other protocols in image sources, but this is indeed not a security issue. We could add it, but I'm not sure that would be useful. Advising users to completely disable the built-in protocol validation to allow the perfectly safe data URLs is not a great security posture. About GitHub: as I showed, the markdown parsing and rendering library they use does allow data URLs. They indeed have a filter removing data URLs further in their pipeline, but that's still something that could be implemented with this library too. This is a product decision, not a security decision that should be enforced at the markdown renderer level. The point is, there is absolutely no security reason to disable data URLs, or to put them behind the same flag that for instance disables JavaScript: URLs in links. |
I believe that the HTML spec does not specify a particular list of image formats. Your argumentation also begs the question: Is currently maintained browsers the target of this project? Only popular ones? Are browsers the only target or are there other user agents? I can at least confirm that Opera from 2012 had scripting in
I understand your argumentation to stretch against all allow-lists for
I am not advising that. I am advising an allow list of Similar argumentation to
Comrak is as far as I am aware still not used by GH. GH uses
Though, I do believe they run this in dangerous mode, and then filter later with a tool similar but different to the HTML pipeline. See also kivikakk/comrak#169. It looks like comrak is also doing things differently than what you propose. |
You are right, the HTML spec does not specify a particular list of image formats, and it allows PDFs !
This is indeed a good question, and is related to my argument. But let's try to keep focused on the issue at hand.
I would be perfectly fine with that ! I can remove the protocol restrictions on image sources completely if that's what you think is best. Let me know if you want me to update the PR in that direction.
I think github uses https://github.com/gjtorikian/commonmarker , which is a wrapper around comrak.
I think this is a weaker security posture than allowing all safe protocols and forbidding unsafe ones by default. This encourages people who just need safe data URIs to switch on Anyways, let's try to be productive here. I understand that you are not willing to allow |
Very nice.
😅 When GH adds things, they do it in
The latter is I believe what this project does. What is safe and unsafe, at what time, seems to be the debate. There are indeed several discussions going on here. I think solutions need to match real problems. Be good to use and be hard to abuse. Would other users allow particular protocols on images? Does it make sense for people to allow If users want that, would they not also want to change the protocols of If users want all this, is that not what plugins are for? Should we not advance plugins? Or, can we figure out that indeed in modern user agents |
Hi ! I think we now both understand each other's arguments here. Let's not dive deeper into the topic of whether embedded images can execute scripts, since it is not related to allowing
Just let me know what you think is best; I'll write the code. |
Another consideration is what standard implementations do.
I'd be more open to that approach |
I opened a separate pull request adding a crate feature: #165 |
This feature was released in |
Data URIs allow embedding image data directly within HTML documents using the
src
attribute of<img>
tags. This practice is generally safe and does not lead to arbitrary code execution.I understand this is a scary pull request to merge when one is not familiar with the topic, so here is a detailed explanation:
<img>
tag, browsers interpret and render the content strictly as an image. They do not execute any embedded scripts or code within this context.<img>
tags have scripting disabled, preventing any embedded JavaScript from executing.Using Data URIs within
<img>
tags is a secure method for embedding images directly into HTML documents. Browsers handle these URIs in a way that prevents code execution.Other markdown rendering libraries, including the one used by github (comrak), do not consider image data URLs as unsafe.
Example:
Results in
fixes #163